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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
#pragma once
#include "indexer/feature_data.hpp"
#include "base/base.hpp"
#include "base/stl_helpers.hpp"
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <initializer_list>
#include <set>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include <boost/optional.hpp>
namespace feature { class TypesHolder; }
class FeatureType;
#define DECLARE_CHECKER_INSTANCE(CheckerType) static CheckerType const & Instance() { \
static CheckerType const inst; return inst; }
namespace ftypes
{
class BaseChecker
{
size_t const m_level;
protected:
std::vector<uint32_t> m_types;
BaseChecker(size_t level = 2) : m_level(level) {}
virtual ~BaseChecker() = default;
public:
virtual bool IsMatched(uint32_t type) const;
bool operator()(feature::TypesHolder const & types) const;
bool operator()(FeatureType & ft) const;
bool operator()(std::vector<uint32_t> const & types) const;
bool operator()(uint32_t type) const { return IsMatched(type); }
static uint32_t PrepareToMatch(uint32_t type, uint8_t level);
template <typename TFn>
void ForEachType(TFn && fn) const
{
std::for_each(m_types.cbegin(), m_types.cend(), std::forward<TFn>(fn));
}
};
class IsPeakChecker : public BaseChecker
{
IsPeakChecker();
public:
DECLARE_CHECKER_INSTANCE(IsPeakChecker);
};
class IsATMChecker : public BaseChecker
{
IsATMChecker();
public:
DECLARE_CHECKER_INSTANCE(IsATMChecker);
};
class IsSpeedCamChecker : public BaseChecker
{
IsSpeedCamChecker();
public:
DECLARE_CHECKER_INSTANCE(IsSpeedCamChecker);
};
class IsFuelStationChecker : public BaseChecker
{
IsFuelStationChecker();
public:
DECLARE_CHECKER_INSTANCE(IsFuelStationChecker);
};
class IsRailwayStationChecker : public BaseChecker
{
IsRailwayStationChecker();
public:
DECLARE_CHECKER_INSTANCE(IsRailwayStationChecker);
};
class IsSubwayStationChecker : public BaseChecker
{
IsSubwayStationChecker();
public:
DECLARE_CHECKER_INSTANCE(IsSubwayStationChecker);
};
class IsAirportChecker : public BaseChecker
{
IsAirportChecker();
public:
DECLARE_CHECKER_INSTANCE(IsAirportChecker);
};
class IsSquareChecker : public BaseChecker
{
IsSquareChecker();
friend class IsStreetOrSuburbChecker;
public:
DECLARE_CHECKER_INSTANCE(IsSquareChecker);
};
class IsSuburbChecker : public BaseChecker
{
IsSuburbChecker();
friend class IsStreetOrSuburbChecker;
public:
DECLARE_CHECKER_INSTANCE(IsSuburbChecker);
};
class IsWayChecker : public BaseChecker
{
IsWayChecker();
friend class IsStreetOrSuburbChecker;
public:
DECLARE_CHECKER_INSTANCE(IsWayChecker);
};
class IsStreetOrSuburbChecker : public BaseChecker
{
IsStreetOrSuburbChecker();
public:
DECLARE_CHECKER_INSTANCE(IsStreetOrSuburbChecker);
};
class IsAddressObjectChecker : public BaseChecker
{
IsAddressObjectChecker();
public:
DECLARE_CHECKER_INSTANCE(IsAddressObjectChecker);
};
class IsVillageChecker : public BaseChecker
{
IsVillageChecker();
public:
DECLARE_CHECKER_INSTANCE(IsVillageChecker);
};
class IsOneWayChecker : public BaseChecker
{
IsOneWayChecker();
public:
DECLARE_CHECKER_INSTANCE(IsOneWayChecker);
};
class IsRoundAboutChecker : public BaseChecker
{
IsRoundAboutChecker();
public:
DECLARE_CHECKER_INSTANCE(IsRoundAboutChecker);
};
class IsLinkChecker : public BaseChecker
{
IsLinkChecker();
public:
DECLARE_CHECKER_INSTANCE(IsLinkChecker);
};
class IsBuildingChecker : public BaseChecker
{
IsBuildingChecker();
public:
uint32_t GetMainType() const { return m_types[0]; }
DECLARE_CHECKER_INSTANCE(IsBuildingChecker);
};
class IsPoiChecker : public BaseChecker
{
IsPoiChecker();
public:
static std::set<std::string> const kPoiTypes;
DECLARE_CHECKER_INSTANCE(IsPoiChecker);
};
class WikiChecker : public BaseChecker
{
WikiChecker();
public:
static std::set<std::pair<std::string, std::string>> const kTypesForWiki;
DECLARE_CHECKER_INSTANCE(WikiChecker);
template <typename Ft>
bool NeedFeature(Ft & feature) const
{
bool need = true;
feature.ForEachType([&](uint32_t type) {
if (need && !IsMatched(type))
need = false;
});
return need;
}
};
class IsPlaceChecker : public BaseChecker
{
IsPlaceChecker();
public:
DECLARE_CHECKER_INSTANCE(IsPlaceChecker);
};
class IsBridgeChecker : public BaseChecker
{
virtual bool IsMatched(uint32_t type) const override;
IsBridgeChecker();
public:
DECLARE_CHECKER_INSTANCE(IsBridgeChecker);
};
class IsTunnelChecker : public BaseChecker
{
virtual bool IsMatched(uint32_t type) const override;
IsTunnelChecker();
public:
DECLARE_CHECKER_INSTANCE(IsTunnelChecker);
};
class IsPopularityPlaceChecker : public BaseChecker
{
IsPopularityPlaceChecker();
public:
DECLARE_CHECKER_INSTANCE(IsPopularityPlaceChecker);
};
class IsHotelChecker : public BaseChecker
{
public:
enum class Type
{
Hotel,
Apartment,
CampSite,
Chalet,
GuestHouse,
Hostel,
Motel,
Resort,
Count
};
using UnderlyingType = std::underlying_type_t<Type>;
static_assert(base::Key(Type::Count) <= CHAR_BIT * sizeof(unsigned),
"Too many types of hotels");
static char const * GetHotelTypeTag(Type type);
unsigned GetHotelTypesMask(FeatureType & ft) const;
boost::optional<Type> GetHotelType(FeatureType & ft) const;
DECLARE_CHECKER_INSTANCE(IsHotelChecker);
private:
IsHotelChecker();
std::array<std::pair<uint32_t, Type>, base::Key(Type::Count)> m_sortedTypes;
};
// WiFi is a type in classificator.txt,
// it should be checked for filling metadata in MapObject.
class IsWifiChecker : public BaseChecker
{
IsWifiChecker();
public:
DECLARE_CHECKER_INSTANCE(IsWifiChecker);
};
class IsEatChecker : public BaseChecker
{
public:
enum class Type
{
Cafe,
Bakery,
FastFood,
Restaurant,
Bar,
Pub,
Biergarten,
Count
};
DECLARE_CHECKER_INSTANCE(IsEatChecker);
std::vector<uint32_t> const & GetTypes() const { return m_types; }
Type GetType(uint32_t t) const;
private:
IsEatChecker();
std::array<std::pair<uint32_t, Type>, base::Key(Type::Count)> m_sortedTypes;
};
class IsCuisineChecker : public BaseChecker
{
IsCuisineChecker();
public:
DECLARE_CHECKER_INSTANCE(IsCuisineChecker);
};
class IsCityChecker : public BaseChecker
{
IsCityChecker();
public:
DECLARE_CHECKER_INSTANCE(IsCityChecker);
};
class IsPublicTransportStopChecker : public BaseChecker
{
IsPublicTransportStopChecker();
public:
DECLARE_CHECKER_INSTANCE(IsPublicTransportStopChecker);
};
/// Type of locality (do not change values and order - they have detalization order)
/// COUNTRY < STATE < CITY < ...
enum Type { NONE = -1, COUNTRY = 0, STATE, CITY, TOWN, VILLAGE, LOCALITY_COUNT };
class IsLocalityChecker : public BaseChecker
{
IsLocalityChecker();
public:
Type GetType(uint32_t t) const;
Type GetType(feature::TypesHolder const & types) const;
Type GetType(FeatureType & f) const;
DECLARE_CHECKER_INSTANCE(IsLocalityChecker);
};
template <typename Types>
bool IsCityTownOrVillage(Types const & types)
{
feature::TypesHolder h;
for (auto const t : types)
h.Add(t);
auto const type = IsLocalityChecker::Instance().GetType(h);
return type == CITY || type == TOWN || type == VILLAGE;
}
/// @name Get city radius and population.
/// @param r Radius in meters.
//@{
uint64_t GetPopulation(FeatureType & ft);
double GetRadiusByPopulation(uint64_t p);
uint64_t GetPopulationByRadius(double r);
//@}
/// Check if type conforms the path. Strings in the path can be
/// feature types like "highway", "living_street", "bridge" and so on
/// or *. * means any class.
/// The root name ("world") is ignored
bool IsTypeConformed(uint32_t type, base::StringIL const & path);
// Highway class. The order is important.
// The enum values follow from the biggest roads (Trunk) to the smallest ones (Service).
enum class HighwayClass
{
Undefined = 0, // There has not been any attempt of calculating HighwayClass.
Error, // There was an attempt of calculating HighwayClass but it was not successful.
Trunk,
Primary,
Secondary,
Tertiary,
LivingStreet,
Service,
Pedestrian,
Transported, // Vehicles are transported by train or ferry.
Count // This value is used for internals only.
};
std::string DebugPrint(HighwayClass const cls);
HighwayClass GetHighwayClass(feature::TypesHolder const & types);
} // namespace ftypes
namespace std
{
template<>
struct hash<ftypes::IsHotelChecker::Type>
{
size_t operator()(ftypes::IsHotelChecker::Type type) const
{
using UnderlyingType = ftypes::IsHotelChecker::UnderlyingType;
return hash<UnderlyingType>()(static_cast<UnderlyingType>(type));
}
};
} // namespace std
|