Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ftypes_matcher.hpp « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 400ef14499547cac8c32db00d540fc7c0d9e5412 (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
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
#pragma once

#include "base/base.hpp"

#include "std/algorithm.hpp"
#include "std/initializer_list.hpp"
#include "std/string.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"

namespace feature { class TypesHolder; }
class FeatureType;

namespace ftypes
{

class BaseChecker
{
  size_t const m_level;

protected:
  vector<uint32_t> m_types;

  virtual bool IsMatched(uint32_t type) const;

  BaseChecker(size_t level = 2) : m_level(level) {}
  virtual ~BaseChecker() = default;

public:
  bool operator() (feature::TypesHolder const & types) const;
  bool operator() (FeatureType const & ft) const;
  bool operator() (vector<uint32_t> const & types) const;
  // Simple type equality comparison. No magic like in IsMatched.
  bool HasTypeValue(uint32_t const type) const;

  static uint32_t PrepareToMatch(uint32_t type, uint8_t level);
};

class IsPeakChecker : public BaseChecker
{
  IsPeakChecker();
public:
  static IsPeakChecker const & Instance();
};

class IsATMChecker : public BaseChecker
{
  IsATMChecker();
public:
  static IsATMChecker const & Instance();
};

class IsSpeedCamChecker : public BaseChecker
{
  IsSpeedCamChecker();
public:
  static IsSpeedCamChecker const & Instance();
};

class IsFuelStationChecker : public BaseChecker
{
  IsFuelStationChecker();
public:
  static IsFuelStationChecker const & Instance();
};

class IsRailwayStationChecker : public BaseChecker
{
  IsRailwayStationChecker();
public:
  static IsRailwayStationChecker const & Instance();
};

class IsStreetChecker : public BaseChecker
{
  IsStreetChecker();
public:
  template <typename TFn>
  void ForEachType(TFn && fn) const
  {
    for_each(m_types.cbegin(), m_types.cend(), forward<TFn>(fn));
  }

  static IsStreetChecker const & Instance();
};

class IsVillageChecker : public BaseChecker
{
public:
  IsVillageChecker();

  template <typename TFn>
  void ForEachType(TFn && fn) const
  {
    for_each(m_types.cbegin(), m_types.cend(), forward<TFn>(fn));
  }

  static IsVillageChecker const & Instance();
};

class IsOneWayChecker : public BaseChecker
{
  IsOneWayChecker();
public:
  static IsOneWayChecker const & Instance();
};

class IsRoundAboutChecker : public BaseChecker
{
  IsRoundAboutChecker();
public:
  static IsRoundAboutChecker const & Instance();
};

class IsLinkChecker : public BaseChecker
{
  IsLinkChecker();
public:
  static IsLinkChecker const & Instance();
};

class IsBuildingChecker : public BaseChecker
{
  IsBuildingChecker();
public:
  static IsBuildingChecker const & Instance();
  uint32_t GetMainType() const { return m_types[0]; }
};

class IsBuildingPartChecker : public BaseChecker
{
  IsBuildingPartChecker();
public:
  static IsBuildingPartChecker const & Instance();
};

class IsBridgeChecker : public BaseChecker
{
  virtual bool IsMatched(uint32_t type) const override;

  IsBridgeChecker();
public:
  static IsBridgeChecker const & Instance();
};

class IsTunnelChecker : public BaseChecker
{
  virtual bool IsMatched(uint32_t type) const override;

  IsTunnelChecker();
public:
  static IsTunnelChecker const & Instance();
};

/// 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(feature::TypesHolder const & types) const;
  Type GetType(FeatureType const & f) const;

  static IsLocalityChecker const & Instance();
};

/// @name Get city radius and population.
/// @param r Radius in meters.
//@{
uint32_t GetPopulation(FeatureType const & ft);
double GetRadiusByPopulation(uint32_t p);
uint32_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, 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,
  Count           // This value is used for internals only.
};

string DebugPrint(HighwayClass const cls);

HighwayClass GetHighwayClass(feature::TypesHolder const & types);
HighwayClass GetHighwayClass(FeatureType const & ft);

}  // namespace ftypes