libosmscout  1.1.1
TypeFeature.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_TYPEFEATURE_H
2 #define OSMSCOUT_TYPEFEATURE_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2018 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 <memory>
24 #include <string>
25 #include <unordered_map>
26 #include <vector>
27 
29 
32 #include <osmscout/util/Locale.h>
33 
35 
36 #include <osmscout/system/Assert.h>
37 
38 namespace osmscout {
39 
41  {
42  public:
43  FeatureValue() = default;
44  FeatureValue(const FeatureValue& featureValue) = default;
45 
46  virtual ~FeatureValue() = default;
47 
48  virtual FeatureValue& operator=(const FeatureValue& other); // NOLINT
49 
50  virtual std::string GetLabel(const Locale &/*locale*/, size_t /*labelIndex*/) const
51  {
52  return "";
53  }
54 
55  virtual bool IsFlagSet(size_t /*flagIndex*/) const
56  {
57  assert(false);
58 
59  return false;
60  }
61 
67  virtual void Read(FileScanner& scanner) = 0;
68 
74  virtual void Write(FileWriter& writer) = 0;
75 
76  virtual bool operator==(const FeatureValue& other) const = 0;
77 
78  virtual bool operator!=(const FeatureValue& other) const
79  {
80  return !(*this==other);
81  }
82  };
83 
84  // Forward declaration of classes because
85  // of circular dependency between them and Feature
86  class FeatureValueBuffer;
87  class FeatureInstance;
88 
99  {
100  private:
101  std::unordered_map<std::string,size_t> labels;
102  std::unordered_map<std::string,size_t> flags;
103  std::unordered_map<std::string,std::string> descriptions;
104 
105  protected:
106  void RegisterLabel(size_t index,
107  const std::string& labelName);
108 
109  void RegisterFlag(size_t index,
110  const std::string& flagName);
111 
112  public:
113  Feature() = default;
114 
115  virtual ~Feature() = default;
116 
121  virtual void Initialize(TagRegistry& tagRegistry) = 0;
122 
123  void AddDescription(const std::string& languageCode,
124  const std::string& description);
125 
129  virtual std::string GetName() const = 0;
130 
135  virtual size_t GetValueAlignment() const
136  {
137  return 0;
138  }
139 
144  virtual size_t GetValueSize() const
145  {
146  return 0;
147  }
148 
157  virtual size_t GetFeatureBitCount() const
158  {
159  return 0;
160  }
161 
165  virtual bool HasValue() const
166  {
167  return GetValueSize()>0;
168  }
169 
173  virtual bool HasLabel() const
174  {
175  return !labels.empty();
176  }
177 
181  virtual bool HasFlags() const
182  {
183  return !flags.empty();
184  }
185 
191  bool GetLabelIndex(const std::string& labelName,
192  size_t& index) const;
193 
199  bool GetFlagIndex(const std::string& flagName,
200  size_t& index) const;
201 
202  std::string GetDescription(const std::string& languageCode) const;
203 
204  const std::unordered_map<std::string,std::string>& GetDescriptions() const
205  {
206  return descriptions;
207  };
208 
209  virtual FeatureValue* AllocateValue(void* buffer);
210 
211  virtual void Parse(TagErrorReporter& reporter,
212  const TagRegistry& tagRegistry,
213  const FeatureInstance& feature,
214  const ObjectOSMRef& object,
215  const TagMap& tags,
216  FeatureValueBuffer& buffer) const = 0;
217  };
218 
219  using FeatureRef = std::shared_ptr<Feature>;
220 
221  // Forward declaration of TypeInfo
222  class TypeInfo;
223 
227  class OSMSCOUT_API FeatureInstance CLASS_FINAL
228  {
229  private:
230  FeatureRef feature;
231  const TypeInfo* type;
232  size_t featureBit;
233  size_t index;
234  size_t offset;
235 
236  public:
237  FeatureInstance();
238 
239  FeatureInstance(const FeatureRef& feature,
240  const TypeInfo* type,
241  size_t featureBit,
242  size_t index,
243  size_t offset);
244 
249  {
250  return feature;
251  }
252 
256  const TypeInfo* GetType() const
257  {
258  return type;
259  }
260 
264  size_t GetFeatureBit() const
265  {
266  return featureBit;
267  }
268 
272  size_t GetIndex() const
273  {
274  return index;
275  }
276 
280  size_t GetOffset() const
281  {
282  return offset;
283  }
284  };
285 }
286 
287 #endif
virtual size_t GetValueSize() const
Definition: TypeFeature.h:144
virtual std::string GetLabel(const Locale &, size_t) const
Definition: TypeFeature.h:50
const std::unordered_map< std::string, std::string > & GetDescriptions() const
Definition: TypeFeature.h:204
Definition: Area.h:86
const TypeInfo * GetType() const
Definition: TypeFeature.h:256
size_t GetFeatureBit() const
Definition: TypeFeature.h:264
virtual bool HasValue() const
Definition: TypeFeature.h:165
Definition: Area.h:38
Definition: TypeFeature.h:98
Definition: TypeFeature.h:40
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
size_t GetOffset() const
Definition: TypeFeature.h:280
size_t GetIndex() const
Definition: TypeFeature.h:272
Setup internal state of renderer for executing next steps with current projection and parameters...
Definition: MapPainter.h:57
std::shared_ptr< Feature > FeatureRef
Definition: TypeFeature.h:219
Definition: TagErrorReporter.h:32
virtual bool HasFlags() const
Definition: TypeFeature.h:181
virtual bool HasLabel() const
Definition: TypeFeature.h:173
bool operator==(const MapView &a, const MapView &b)
Definition: InputHandler.h:222
virtual bool IsFlagSet(size_t) const
Definition: TypeFeature.h:55
virtual bool operator!=(const FeatureValue &other) const
Definition: TypeFeature.h:78
virtual size_t GetFeatureBitCount() const
Definition: TypeFeature.h:157
std::unordered_map< TagId, std::string > TagMap
Definition: Tag.h:41
virtual size_t GetValueAlignment() const
Definition: TypeFeature.h:135
FeatureRef GetFeature() const
Definition: TypeFeature.h:248