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
72
73
74
75
76
77
78
79
80
81
|
#pragma once
#include "feature.hpp"
#include "data_header_reader.hpp"
#include "../defines.hpp"
#include "../coding/var_record_reader.hpp"
#include "../base/logging.hpp"
struct FeatureReaders
{
FilesContainerR m_cont;
FileReader m_datR;
FeatureReaders(FilesContainerR const & cont)
: m_cont(cont), m_datR(cont.GetReader(DATA_FILE_TAG))
{
uint64_t const offset = feature::GetSkipHeaderSize(m_datR);
m_datR = m_datR.SubReader(offset, m_datR.Size() - offset);
}
};
class FeaturesVector
{
public:
FeaturesVector(FeatureReaders const & dataR)
: m_RecordReader(dataR.m_datR, 256), m_source(dataR.m_cont)
{
FileReader r = dataR.m_cont.GetReader(HEADER_FILE_TAG);
m_source.m_base = ReadPrimitiveFromPos<int64_t>(r, 0);
LOG(LINFO, ("OFFSET = ", m_source.m_base));
}
void Get(uint64_t pos, FeatureType & feature) const
{
m_RecordReader.ReadRecord(pos, m_source.m_data, m_source.m_offset);
feature.Deserialize(m_source);
}
template <class ToDo> void ForEachOffset(ToDo toDo) const
{
m_RecordReader.ForEachRecord(feature_getter<ToDo>(toDo, m_source));
}
//template <class TDo> void ForEach(TDo const & toDo) const
//{
// FeatureType f;
// m_RecordReader.ForEachRecord(
// bind<void>(toDo, bind(&FeaturesVector<ReaderT>::DeserializeFeature, this, _2, _3, &f)));
//}
bool IsMyData(string const & fName) const
{
return m_RecordReader.IsEqual(fName);
}
private:
template <class ToDo> class feature_getter
{
ToDo & m_toDo;
FeatureType::read_source_t & m_source;
public:
feature_getter(ToDo & toDo, FeatureType::read_source_t & src)
: m_toDo(toDo), m_source(src)
{
}
void operator() (uint32_t pos, char const * data, uint32_t size) const
{
FeatureType f;
m_source.assign(data, size);
f.Deserialize(m_source);
m_toDo(f, pos);
}
};
VarRecordReader<FileReader, &VarRecordSizeReaderVarint> m_RecordReader;
mutable FeatureType::read_source_t m_source;
};
|