| 217 | } |
| 218 | |
| 219 | void GpsTrackStorage::ForEach(std::function<bool(TItem const & item)> const & fn) |
| 220 | { |
| 221 | ASSERT(m_stream.is_open(), ()); |
| 222 | |
| 223 | size_t i = 0; |
| 224 | |
| 225 | // Set read position to the first item |
| 226 | m_stream.seekg(GetItemOffset(i), ios::beg); |
| 227 | if (!m_stream.good()) |
| 228 | MYTHROW(ReadException, ("File:", m_filePath)); |
| 229 | |
| 230 | vector<char> buff(min(kItemBlockSize, m_itemCount) * kPointSize); |
| 231 | for (; i < m_itemCount;) |
| 232 | { |
| 233 | size_t const n = min(m_itemCount - i, kItemBlockSize); |
| 234 | |
| 235 | m_stream.read(&buff[0], n * kPointSize); |
| 236 | if (!m_stream.good()) |
| 237 | MYTHROW(ReadException, ("File:", m_filePath)); |
| 238 | |
| 239 | for (size_t j = 0; j < n; ++j) |
| 240 | { |
| 241 | TItem item; |
| 242 | Unpack(&buff[0] + j * kPointSize, item); |
| 243 | if (!fn(item)) |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | i += n; |
| 248 | } |
| 249 | } |