blob: 75836ad019c0479fe76c6edbff8d6dac76ffaac8 (
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#pragma once
#include "platform/platform.hpp"
#include "base/assert.hpp"
#include "base/logging.hpp"
#include <atomic>
#include <fstream>
#include <memory>
#include <string>
struct OsmElement;
class RelationElement;
namespace feature
{
class FeatureBuilder;
} // namespace feature
namespace base
{
class GeoObjectId;
} // namespace base
namespace feature
{
class MetalinesBuilder;
} // namespace feature
namespace routing
{
class CameraCollector;
class RestrictionWriter;
class RoadAccessWriter;
} // namespace routing
namespace generator
{
class CollectorAddresses;
class CollectorCollection;
class CollectorTag;
class MaxspeedsCollector;
class CityAreaCollector;
namespace cache
{
class IntermediateDataReader;
} // namespace cache
namespace regions
{
class CollectorRegionInfo;
} // namespace regions
// Implementing this interface allows an object to collect data from RelationElement,
// OsmElement and FeatureBuilder elements.
class CollectorInterface
{
public:
CollectorInterface(std::string const & filename = {}) : m_id(CreateId()), m_filename(filename) {}
virtual ~CollectorInterface() { CHECK(Platform::RemoveFileIfExists(GetTmpFilename()), ()); }
virtual std::shared_ptr<CollectorInterface>
Clone(std::shared_ptr<cache::IntermediateDataReader> const & = {}) const = 0;
virtual void Collect(OsmElement const &) {}
virtual void CollectRelation(RelationElement const &) {}
virtual void CollectFeature(feature::FeatureBuilder const &, OsmElement const &) {}
virtual void Finish() {}
virtual void Save() = 0;
virtual void Merge(CollectorInterface const &) = 0;
virtual void MergeInto(CityAreaCollector &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(routing::CameraCollector &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(routing::RestrictionWriter &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(routing::RoadAccessWriter &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(CollectorAddresses &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(CollectorTag &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(MaxspeedsCollector &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(feature::MetalinesBuilder &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(regions::CollectorRegionInfo &) const { FailIfMethodUnsupported(); }
virtual void MergeInto(CollectorCollection &) const { FailIfMethodUnsupported(); }
std::string GetTmpFilename() const { return m_filename + "." + std::to_string(m_id); }
std::string const & GetFilename() const { return m_filename; }
private:
void FailIfMethodUnsupported() const { CHECK(false, ("This method is unsupported.")); }
int CreateId()
{
static std::atomic_int id{0};
return id++;
}
int m_id;
std::string m_filename;
};
} // namespace generator
|