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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
#pragma once
#include "generator/booking_dataset.hpp"
#include "generator/feature_generator.hpp"
#include "generator/opentable_dataset.hpp"
#include "generator/polygonizer.hpp"
#include "generator/promo_catalog_cities.hpp"
#include "generator/world_map_generator.hpp"
#include <memory>
#include <sstream>
#include <string>
class CoastlineFeaturesGenerator;
namespace feature
{
class FeatureBuilder;
struct GenerateInfo;
} // namespace feature
namespace generator
{
class CityBoundaryProcessor;
class CountryMapper;
class WorldMapper;
// Responsibility of the class Log Buffer - encapsulation of the buffer for internal logs.
class LogBuffer
{
public:
template <class T, class... Ts>
void AppendLine(T const & value, Ts... rest)
{
AppendImpl(value, rest...);
// The last "\t" is overwritten here
m_buffer.seekp(-1, std::ios_base::end);
m_buffer << "\n";
}
std::string GetAsString() const;
private:
template <class T, class... Ts>
void AppendImpl(T const & value, Ts... rest)
{
m_buffer << value << "\t";
AppendImpl(rest...);
}
void AppendImpl() {}
std::ostringstream m_buffer;
};
// This is the base layer class. Inheriting from it allows you to create a chain of layers.
class LayerBase : public std::enable_shared_from_this<LayerBase>
{
public:
LayerBase() = default;
virtual ~LayerBase() = default;
// The function works in linear time from the number of layers that exist after that.
virtual void Handle(feature::FeatureBuilder & feature);
void SetNext(std::shared_ptr<LayerBase> next);
std::shared_ptr<LayerBase> Add(std::shared_ptr<LayerBase> next);
template <class T, class... Ts>
constexpr void AppendLine(T const & value, Ts... rest)
{
m_logBuffer.AppendLine(value, rest...);
}
std::string GetAsString() const;
std::string GetAsStringRecursive() const;
private:
LogBuffer m_logBuffer;
std::shared_ptr<LayerBase> m_next;
};
// Responsibility of class RepresentationLayer is converting features from one form to another for countries.
// Here we can use the knowledge of the rules for drawing objects.
// The class transfers control to the CityBoundaryProcessor if for the feature it is a city, town or village.
// Osm object can be represented as feature of following geometry types: point, line, area depending on
// its types and geometry. Sometimes one osm object can be represented as two features e.g. object with
// closed geometry with types "leisure=playground" and "barrier=fence" splits into two objects: area object
// with type "leisure=playground" and line object with type "barrier=fence".
class RepresentationLayer : public LayerBase
{
public:
explicit RepresentationLayer(std::shared_ptr<CityBoundaryProcessor> processor);
// LayerBase overrides:
void Handle(feature::FeatureBuilder & feature) override;
private:
static bool CanBeArea(FeatureParams const & params);
static bool CanBePoint(FeatureParams const & params);
static bool CanBeLine(FeatureParams const & params);
void HandleArea(feature::FeatureBuilder & feature, FeatureParams const & params);
std::shared_ptr<CityBoundaryProcessor> m_processor;
};
// Responsibility of class PrepareFeatureLayer is the removal of unused types and names,
// as well as the preparation of features for further processing for countries.
class PrepareFeatureLayer : public LayerBase
{
public:
// LayerBase overrides:
void Handle(feature::FeatureBuilder & feature) override;
};
// Responsibility of class CityBoundaryLayer - transfering control to the CityBoundaryProcessor
// if the feature is a place.
class CityBoundaryLayer : public LayerBase
{
public:
explicit CityBoundaryLayer(std::shared_ptr<CityBoundaryProcessor> processor);
// LayerBase overrides:
void Handle(feature::FeatureBuilder & feature) override;
private:
std::shared_ptr<CityBoundaryProcessor> m_processor;
};
// Responsibility of class BookingLayer - mixing information from booking. If there is a
// coincidence of the hotel and feature, the processing of the feature is performed.
class BookingLayer : public LayerBase
{
public:
explicit BookingLayer(std::string const & filename, std::shared_ptr<CountryMapper> countryMapper);
// LayerBase overrides:
~BookingLayer() override;
void Handle(feature::FeatureBuilder & feature) override;
private:
BookingDataset m_dataset;
std::shared_ptr<CountryMapper> m_countryMapper;
};
// Responsibility of class OpentableLayer - mixing information from opentable. If there is a
// coincidence of the restaurant and feature, the processing of the feature is performed.
class OpentableLayer : public LayerBase
{
public:
explicit OpentableLayer(std::string const & filename, std::shared_ptr<CountryMapper> countryMapper);
// LayerBase overrides:
void Handle(feature::FeatureBuilder & feature) override;
private:
OpentableDataset m_dataset;
std::shared_ptr<CountryMapper> m_countryMapper;
};
class PromoCatalogLayer : public LayerBase
{
public:
explicit PromoCatalogLayer(std::string const & citiesFinename);
// LayerBase overrides:
void Handle(feature::FeatureBuilder & feature) override;
private:
promo::Cities m_cities;
};
// Responsibility of class CountryMapperLayer - mapping of features to countries.
class CountryMapperLayer : public LayerBase
{
public:
explicit CountryMapperLayer(std::shared_ptr<CountryMapper> countryMapper);
// LayerBase overrides:
void Handle(feature::FeatureBuilder & feature) override;
private:
std::shared_ptr<CountryMapper> m_countryMapper;
};
// Responsibility of class EmitCoastsLayer is adding coastlines to countries.
class EmitCoastsLayer : public LayerBase
{
public:
explicit EmitCoastsLayer(std::string const & worldCoastsFilename, std::string const & geometryFilename,
std::shared_ptr<CountryMapper> countryMapper);
// LayerBase overrides:
~EmitCoastsLayer() override;
void Handle(feature::FeatureBuilder & feature) override;
private:
std::shared_ptr<feature::FeaturesCollector> m_collector;
std::shared_ptr<CountryMapper> m_countryMapper;
std::string m_geometryFilename;
};
// Responsibility of class RepresentationCoastlineLayer is converting features from one form to
// another for coastlines. Here we can use the knowledge of the rules for drawing objects.
class RepresentationCoastlineLayer : public LayerBase
{
public:
// LayerBase overrides:
void Handle(feature::FeatureBuilder & feature) override;
};
// Responsibility of class PrepareCoastlineFeatureLayer is the removal of unused types and names,
// as well as the preparation of features for further processing for coastlines.
class PrepareCoastlineFeatureLayer : public LayerBase
{
public:
// LayerBase overrides:
void Handle(feature::FeatureBuilder & feature) override;
};
// Responsibility of class CoastlineMapperLayer - mapping of features on coastline.
class CoastlineMapperLayer : public LayerBase
{
public:
explicit CoastlineMapperLayer(std::shared_ptr<CoastlineFeaturesGenerator> coastlineMapper);
// LayerBase overrides:
void Handle(feature::FeatureBuilder & feature) override;
private:
std::shared_ptr<CoastlineFeaturesGenerator> m_coastlineGenerator;
};
// Responsibility of class CountryMapperLayer - mapping of features on the world.
class WorldAreaLayer : public LayerBase
{
public:
using WorldGenerator = WorldMapGenerator<feature::FeaturesCollector>;
explicit WorldAreaLayer(std::shared_ptr<WorldMapper> mapper);
// LayerBase overrides:
~WorldAreaLayer() override;
void Handle(feature::FeatureBuilder & feature) override;
private:
std::shared_ptr<WorldMapper> m_mapper;
};
// This is the class-wrapper over CountriesGenerator class.
class CountryMapper
{
public:
using Polygonizer = feature::Polygonizer<feature::FeaturesCollector>;
using CountriesGenerator = CountryMapGenerator<Polygonizer>;
explicit CountryMapper(feature::GenerateInfo const & info);
void Map(feature::FeatureBuilder & feature);
void RemoveInvalidTypesAndMap(feature::FeatureBuilder & feature);
Polygonizer & Parent();
std::vector<std::string> const & GetNames() const;
private:
std::unique_ptr<CountriesGenerator> m_countries;
};
// This is the class-wrapper over WorldGenerator class.
class WorldMapper
{
public:
using WorldGenerator = WorldMapGenerator<feature::FeaturesCollector>;
explicit WorldMapper(std::string const & worldFilename, std::string const & rawGeometryFilename,
std::string const & popularPlacesFilename);
void Map(feature::FeatureBuilder & feature);
void RemoveInvalidTypesAndMap(feature::FeatureBuilder & feature);
void Merge();
private:
std::unique_ptr<WorldGenerator> m_world;
};
} // namespace generator
|