libosmscout  1.1.1
Tag.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_TAG_H
2 #define OSMSCOUT_TAG_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2009 Tim Teulings
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
23 #include <list>
24 #include <memory>
25 #include <string>
26 #include <unordered_map>
27 #include <unordered_set>
28 #include <vector>
29 
31 
32 #include <osmscout/util/Parsing.h>
33 
36 
37 namespace osmscout {
38 
39  using TagId = uint16_t;
40 
41  using TagMap = std::unordered_map<TagId, std::string>;
42 
48  static const TagId tagIgnore = 0;
49 
56  {
57  public:
58  virtual ~TagCondition() = default;
59 
60  virtual bool Evaluate(const TagMap& tagMap) const = 0;
61  };
62 
68  using TagConditionRef = std::shared_ptr<TagCondition>;
69 
76  {
77  private:
78  TagConditionRef condition;
79 
80  public:
81  explicit TagNotCondition(const TagConditionRef& condition);
82 
83  inline bool Evaluate(const TagMap& tagMap) const override
84  {
85  return !condition->Evaluate(tagMap);
86  }
87  };
88 
96  {
97  public:
98  enum Type {
100  boolOr
101  };
102 
103  private:
104  std::list<TagConditionRef> conditions;
105  Type type;
106 
107  public:
108  explicit TagBoolCondition(Type type);
109 
110  void AddCondition(const TagConditionRef& condition);
111 
112  bool Evaluate(const TagMap& tagMap) const override;
113  };
114 
120  using TagBoolConditionRef = std::shared_ptr<TagBoolCondition>;
121 
128  {
129  private:
130  TagId tag;
131 
132  public:
133  explicit TagExistsCondition(TagId tag);
134 
135  inline bool Evaluate(const TagMap& tagMap) const override
136  {
137  return tagMap.find(tag)!=tagMap.end();
138  }
139  };
140 
148  {
149  private:
150  enum ValueType {
151  string,
152  sizet
153  };
154 
155  private:
156  TagId tag;
157  BinaryOperator binaryOperator;
158  ValueType valueType;
159  std::string tagStringValue;
160  size_t tagSizeValue;
161 
162  public:
164  BinaryOperator binaryOperator,
165  const std::string& tagValue);
167  BinaryOperator binaryOperator,
168  const size_t& tagValue);
169 
170  bool Evaluate(const TagMap& tagMap) const override;
171  };
172 
180  {
181  private:
182  TagId tag;
183  std::unordered_set<std::string> tagValues;
184 
185  public:
186  explicit TagIsInCondition(TagId tag);
187 
188  void AddTagValue(const std::string& tagValue);
189 
190  bool Evaluate(const TagMap& tagMap) const override;
191  };
192 
198  using TagIsInConditionRef = std::shared_ptr<TagIsInCondition>;
199 
206  {
207  private:
208  TagId id;
209  std::string name;
210 
211  public:
212  TagInfo(TagId id,
213  const std::string& name);
214 
215  inline std::string GetName() const
216  {
217  return name;
218  }
219 
223  inline TagId GetId() const
224  {
225  return id;
226  }
227  };
228 
229  class OSMSCOUT_API TagRegistry CLASS_FINAL
230  {
231  private:
232  // Tags
233 
234  std::vector<TagInfo> tags;
235 
236  TagId nextTagId;
237 
238  std::unordered_map<std::string,TagId> stringToTagMap;
239  std::unordered_map<TagId,uint32_t> nameTagIdToPrioMap;
240  std::unordered_map<TagId,uint32_t> nameAltTagIdToPrioMap;
241  std::unordered_map<std::string,uint8_t> nameToMaxSpeedMap;
242 
243  std::unordered_map<std::string,size_t> surfaceToGradeMap;
244 
245  public:
246  TagRegistry();
247  ~TagRegistry();
248 
249  TagId RegisterTag(const std::string& tagName);
250 
251  TagId RegisterNameTag(const std::string& tagName,
252  uint32_t priority);
253  TagId RegisterNameAltTag(const std::string& tagName,
254  uint32_t priority);
255 
256  TagId GetTagId(const char* name) const;
257  TagId GetTagId(const std::string& name) const;
258 
259  bool IsNameTag(TagId tag,
260  uint32_t& priority) const;
261  bool IsNameAltTag(TagId tag,
262  uint32_t& priority) const;
263 
268  void RegisterSurfaceToGradeMapping(const std::string& surface,
269  size_t grade);
274  bool GetGradeForSurface(const std::string& surfaceValue,
275  size_t& grade) const;
277 
282  void RegisterMaxSpeedAlias(const std::string& alias,
283  uint8_t maxSpeed);
284  bool GetMaxSpeedFromAlias(const std::string& alias,
285  uint8_t& maxSpeed) const;
287  };
288 }
289 
290 #endif
Definition: Tag.h:147
uint16_t TagId
Definition: Tag.h:39
std::string GetName() const
Definition: Tag.h:215
std::shared_ptr< TagIsInCondition > TagIsInConditionRef
Definition: Tag.h:198
static const TagId tagIgnore
Definition: Tag.h:48
TagId GetId() const
Definition: Tag.h:223
Definition: Area.h:38
Definition: Tag.h:127
bool Evaluate(const TagMap &tagMap) const override
Definition: Tag.h:83
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
Definition: Tag.h:205
Definition: Tag.h:95
Definition: Tag.h:179
Type
Definition: Tag.h:98
std::shared_ptr< TagBoolCondition > TagBoolConditionRef
Definition: Tag.h:120
Definition: Tag.h:75
std::unordered_map< TagId, std::string > TagMap
Definition: Tag.h:41
std::shared_ptr< TagCondition > TagConditionRef
Definition: Tag.h:68
Definition: Tag.h:55
bool Evaluate(const TagMap &tagMap) const override
Definition: Tag.h:135
BinaryOperator
Definition: Parsing.h:32