forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeatures_vector.hpp
71 lines (57 loc) · 2.04 KB
/
features_vector.hpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include "feature.hpp"
#include "feature_loader_base.hpp"
#include "coding/var_record_reader.hpp"
namespace feature { class FeaturesOffsetsTable; }
/// Note! This class is NOT Thread-Safe.
/// You should have separate instance of Vector for every thread.
class FeaturesVector
{
DISALLOW_COPY(FeaturesVector);
public:
FeaturesVector(FilesContainerR const & cont, feature::DataHeader const & header,
feature::FeaturesOffsetsTable const * table)
: m_LoadInfo(cont, header), m_RecordReader(m_LoadInfo.GetDataReader(), 256), m_table(table)
{
}
void GetByIndex(uint32_t index, FeatureType & ft) const;
template <class ToDo> void ForEach(ToDo && toDo) const
{
uint32_t index = 0;
m_RecordReader.ForEachRecord([&] (uint32_t pos, char const * data, uint32_t /*size*/)
{
FeatureType ft;
ft.Deserialize(m_LoadInfo.GetLoader(), data);
toDo(ft, m_table ? index++ : pos);
});
}
template <class ToDo> static void ForEachOffset(ModelReaderPtr reader, ToDo && toDo)
{
VarRecordReader<ModelReaderPtr, &VarRecordSizeReaderVarint> recordReader(reader, 256);
recordReader.ForEachRecord([&] (uint32_t pos, char const * /*data*/, uint32_t /*size*/)
{
toDo(pos);
});
}
private:
friend class FeaturesVectorTest;
feature::SharedLoadInfo m_LoadInfo;
VarRecordReader<FilesContainerR::ReaderT, &VarRecordSizeReaderVarint> m_RecordReader;
mutable vector<char> m_buffer;
feature::FeaturesOffsetsTable const * m_table;
};
/// Test features vector (reader) that combines all the needed data for stand-alone work.
/// Used in generator_tool and unit tests.
class FeaturesVectorTest
{
DISALLOW_COPY(FeaturesVectorTest);
FilesContainerR m_cont;
feature::DataHeader m_header;
FeaturesVector m_vector;
public:
explicit FeaturesVectorTest(string const & filePath);
explicit FeaturesVectorTest(FilesContainerR const & cont);
~FeaturesVectorTest();
feature::DataHeader const & GetHeader() const { return m_header; }
FeaturesVector const & GetVector() const { return m_vector; }
};