1 #ifndef OSMSCOUT_FEATURE_READER_H 2 #define OSMSCOUT_FEATURE_READER_H 43 std::vector<size_t> lookupTable;
58 bool GetIndex(
const FeatureValueBuffer& buffer,
68 bool IsSet(
const FeatureValueBuffer& buffer)
const;
74 FeatureRef feature=typeConfig.GetFeature(F::NAME);
76 lookupTable.resize(typeConfig.GetTypeCount(),
77 std::numeric_limits<size_t>::max());
79 for (
const auto &type : typeConfig.GetTypes()) {
82 if (type->GetFeature(F::NAME,
84 lookupTable[type->GetIndex()]=index;
93 index=lookupTable[buffer.GetType()->GetIndex()];
95 return index!=std::numeric_limits<size_t>::max();
101 size_t index=lookupTable[buffer.GetType()->GetIndex()];
103 if (index!=std::numeric_limits<size_t>::max()) {
104 return buffer.HasFeature(index);
124 std::string featureName;
125 std::vector<size_t> lookupTable;
128 DynamicFeatureReader(
const TypeConfig& typeConfig,
136 bool IsSet(
const FeatureValueBuffer& buffer)
const;
138 FeatureValue* GetValue(
const FeatureValueBuffer& buffer)
const;
148 template<
class F,
class V>
152 std::vector<size_t> lookupTable;
154 static_assert(std::is_base_of<Feature, F>::value,
"F have to be subtype of Feature");
155 static_assert(std::is_base_of<FeatureValue, V>::value,
"V have to be subtype of FeatureValue");
170 bool GetIndex(
const FeatureValueBuffer& buffer,
171 size_t& index)
const;
181 V*
GetValue(
const FeatureValueBuffer& buffer)
const;
190 V
GetValue(
const FeatureValueBuffer& buffer,
const V& defaultValue)
const;
193 template<
class F,
class V>
196 FeatureRef feature=typeConfig.GetFeature(F::NAME);
198 assert(feature->HasValue());
200 lookupTable.resize(typeConfig.GetTypeCount(),
201 std::numeric_limits<size_t>::max());
203 for (
const auto &type : typeConfig.GetTypes()) {
206 if (type->GetFeature(F::NAME,
208 lookupTable[type->GetIndex()]=index;
213 template<
class F,
class V>
217 assert(buffer.GetType()->GetIndex() < lookupTable.size());
218 index=lookupTable[buffer.GetType()->GetIndex()];
220 return index!=std::numeric_limits<size_t>::max();
223 template<
class F,
class V>
226 assert(buffer.GetType()->GetIndex()<lookupTable.size());
227 size_t index=lookupTable[buffer.GetType()->GetIndex()];
229 if (index!=std::numeric_limits<size_t>::max() &&
230 buffer.HasFeature(index)) {
234 assert(val==
nullptr || dynamic_cast<V*>(val)!=
nullptr);
235 return static_cast<V*
>(val);
241 template<
class F,
class V>
244 assert(buffer.GetType()->GetIndex() < lookupTable.size());
245 size_t index=lookupTable[buffer.GetType()->GetIndex()];
247 if (index!=std::numeric_limits<size_t>::max() &&
248 buffer.HasFeature(index)) {
252 assert(val ==
nullptr || dynamic_cast<V*>(val) !=
nullptr);
253 return *
static_cast<V*
>(val);
283 template <
class F,
class V>
287 std::vector<size_t> lookupTable;
299 std::string
GetLabel(
const FeatureValueBuffer& buffer)
const;
302 template<
class F,
class V>
305 FeatureRef feature=typeConfig.GetFeature(F::NAME);
307 assert(feature->HasLabel());
309 lookupTable.resize(typeConfig.GetTypeCount(),
310 std::numeric_limits<size_t>::max());
312 for (
const auto &type : typeConfig.GetTypes()) {
315 if (type->GetFeature(F::NAME,
317 lookupTable[type->GetIndex()]=index;
322 template<
class F,
class V>
325 size_t index=lookupTable[buffer.GetType()->GetIndex()];
327 if (index!=std::numeric_limits<size_t>::max() &&
328 buffer.HasFeature(index)) {
329 auto* value=
dynamic_cast<V*
>(buffer.GetValue(index));
331 if (value!=
nullptr) {
332 return value->GetLabel(Locale(), 0);
FeatureLabelReader(const TypeConfig &typeConfig)
Definition: FeatureReader.h:303
Definition: FeatureReader.h:149
V * GetValue(const FeatureValueBuffer &buffer) const
Definition: FeatureReader.h:224
Definition: FeatureReader.h:284
std::string GetLabel(const FeatureValueBuffer &buffer) const
Definition: FeatureReader.h:323
FeatureValueReader(const TypeConfig &typeConfig)
Definition: FeatureReader.h:194
Definition: TypeFeature.h:98
Definition: TypeFeature.h:40
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
bool GetIndex(const FeatureValueBuffer &buffer, size_t &index) const
Definition: FeatureReader.h:214
std::string GetFeatureName() const
Definition: FeatureReader.h:131
std::shared_ptr< Feature > FeatureRef
Definition: TypeFeature.h:219
Definition: FeatureReader.h:40
bool GetIndex(const FeatureValueBuffer &buffer, size_t &index) const
Definition: FeatureReader.h:90
FeatureReader(const TypeConfig &typeConfig)
Definition: FeatureReader.h:72
bool IsSet(const FeatureValueBuffer &buffer) const
Definition: FeatureReader.h:99