Welcome to mirror list, hosted at ThFree Co, Russian Federation.

feature_processor.hpp « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b71e56f4b75cbac0e45cebd5714a705b7f704c16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

#include "features_vector.hpp"

#include "../coding/file_container.hpp"

#include "../std/bind.hpp"


namespace feature
{
  template <class ToDo>
  void ForEachFromDat(string const & fName, ToDo & toDo)
  {
    FilesContainerR container(fName);
    FeaturesVector<FileReader> featureSource(container);
    featureSource.ForEachOffset(bind<void>(ref(toDo), _1, _2));
  }

   /// Read feature from feature source.
  template <class TSource>
  void ReadFromSource(TSource & src, FeatureGeom & f, typename FeatureGeom::read_source_t & buffer)
  {
    uint32_t const sz = ReadVarUint<uint32_t>(src);
    buffer.m_data.resize(sz);
    src.Read(&buffer.m_data[0], sz);
    f.Deserialize(buffer);
  }

  /// Process features in .dat file.
  template <class ToDo>
  void ForEachFromDatRawFormat(string const & fName, ToDo & toDo)
  {
    typedef ReaderSource<FileReader> source_t;

    FileReader reader(fName);
    source_t src(reader);
    typename FeatureGeom::read_source_t buffer(fName);

    // skip header
    uint64_t currPos = feature::GetSkipHeaderSize(reader);
    src.Skip(currPos);

    uint64_t const fSize = reader.Size();
    // read features one by one
    while (currPos < fSize)
    {
      FeatureGeom f;
      ReadFromSource(src, f, buffer);
      toDo(f, currPos);
      currPos = src.Pos();
    }
  }
}