blob: a0e1af6b1d2834f6ebab829ff62915b9e0ec3065 (
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
55
56
57
58
59
60
61
62
63
64
65
|
#pragma once
#include "geometry/rect2d.hpp"
#include "coding/file_writer.hpp"
#include <limits>
#include <string>
#include <vector>
class FeatureBuilder1;
namespace feature
{
// Writes features to dat file.
class FeaturesCollector
{
char m_writeBuffer[48000];
size_t m_writePosition = 0;
uint32_t m_featureID = 0;
protected:
static uint32_t constexpr kInvalidFeatureId = std::numeric_limits<uint32_t>::max();
FileWriter m_datFile;
m2::RectD m_bounds;
private:
void Write(char const * src, size_t size);
void FlushBuffer();
protected:
static uint32_t GetFileSize(FileWriter const & f);
/// @return feature offset in the file, which is used as an ID later
uint32_t WriteFeatureBase(std::vector<char> const & bytes, FeatureBuilder1 const & fb);
void Flush();
public:
FeaturesCollector(std::string const & fName);
virtual ~FeaturesCollector();
std::string const & GetFilePath() const { return m_datFile.GetName(); }
/// \brief Serializes |f|.
/// \returns feature id of serialized feature if |f| is serialized after the call
/// and |kInvalidFeatureId| if not.
/// \note See implementation operator() in derived class for cases when |f| cannot be
/// serialized.
virtual uint32_t operator()(FeatureBuilder1 const & f);
};
class FeaturesAndRawGeometryCollector : public FeaturesCollector
{
FileWriter m_rawGeometryFileStream;
size_t m_rawGeometryCounter = 0;
public:
FeaturesAndRawGeometryCollector(std::string const & featuresFileName,
std::string const & rawGeometryFileName);
~FeaturesAndRawGeometryCollector();
uint32_t operator()(FeatureBuilder1 const & f) override;
};
}
|