1#ifndef OSMSCOUT_TYPECONFIG_H
2#define OSMSCOUT_TYPECONFIG_H
26#include <unordered_map>
27#include <unordered_set>
110 std::list<TypeCondition> conditions;
111 std::unordered_map<std::string,size_t> nameToFeatureMap;
112 std::vector<FeatureInstance> features;
113 size_t featureMaskBytes=0;
114 size_t specialFeatureMaskBytes=0;
115 size_t valueBufferSize=0;
117 bool canBeNode=
false;
119 bool canBeArea=
false;
120 bool canBeRelation=
false;
122 bool canRouteFoot=
false;
123 bool canRouteBicycle=
false;
124 bool canRouteCar=
false;
125 bool indexAsAddress=
false;
126 bool indexAsLocation=
false;
127 bool indexAsRegion=
false;
128 bool indexAsPOI=
false;
129 bool optimizeLowZoom=
false;
132 bool mergeAreas=
false;
133 bool ignoreSeaLand=
false;
136 uint8_t onewayLanes=1;
138 std::unordered_set<std::string> groups;
139 std::unordered_map<std::string,std::string> descriptions;
203 const std::string& description);
207 return !features.empty();
220 size_t& index)
const;
227 return features[idx];
243 return features.size();
251 return featureMaskBytes;
260 return specialFeatureMaskBytes;
268 return valueBufferSize;
336 return !conditions.empty();
352 this->canBeNode=canBeNode;
367 this->canBeWay=canBeWay;
382 this->canBeArea=canBeArea;
397 this->canBeRelation=canBeRelation;
404 return canBeRelation;
427 this->canRouteFoot=canBeRoute;
434 this->canRouteBicycle=canBeRoute;
444 this->canRouteCar=canBeRoute;
451 return canRouteFoot || canRouteBicycle || canRouteCar;
464 return canRouteBicycle;
479 return canRouteBicycle;
494 this->indexAsAddress=indexAsAddress;
501 return indexAsAddress;
509 this->indexAsLocation=indexAsLocation;
516 return indexAsLocation;
524 this->indexAsRegion=indexAsRegion;
531 return indexAsRegion;
539 this->indexAsPOI=indexAsPOI;
554 this->optimizeLowZoom=optimize;
561 return optimizeLowZoom;
565 this->specialType=specialType;
637 this->mergeAreas=mergeAreas;
652 this->ignoreSeaLand=ignoreSeaLand;
659 return ignoreSeaLand;
692 this->onewayLanes=lanes;
705 const std::unordered_set<std::string>&
GetGroups()
const
712 return groups.find(groupName)!=groups.end();
733 uint8_t *featureBits=
nullptr;
734 char *featureValueBuffer=
nullptr;
739 void AllocateValueBufferLazy();
747 AllocateValueBufferLazy();
748 return static_cast<FeatureValue*
>(
static_cast<void*
>(&featureValueBuffer[type->GetFeature(idx).GetOffset()]));
801 return type->GetFeatureCount();
809 return type->GetFeature(idx);
817 size_t featureBit=
type->GetFeature(idx).GetFeatureBit();
819 return (featureBits[featureBit/8] & (1u << featureBit%8))!=0;
832 return featureValueBuffer==
nullptr ? nullptr
896 bool specialFlag)
const;
907 bool specialFlag2)
const;
920 bool specialFlag3)
const;
931 template<std::
size_t FlagCnt>
934 for (
size_t i=0; i<
type->GetFeatureMaskBytes(); i++) {
935 featureBits[i]=scanner.ReadUInt8();
938 if (!specialFlags.empty()) {
939 static_assert(FlagCnt <= 8);
942 flagByte = featureBits[
type->GetFeatureMaskBytes() - 1];
944 flagByte = scanner.ReadUInt8();
947 for (
bool &specialFlag: specialFlags) {
948 specialFlag = (flagByte & mask) != 0;
953 for (
const auto &feature :
type->GetFeatures()) {
954 size_t idx=feature.GetIndex();
957 feature.GetFeature()->HasValue()) {
958 FeatureValue* value=feature.GetFeature()->AllocateValue(GetValueAndAllocateBuffer(idx));
960 value->
Read(scanner);
972 template<std::
size_t FlagCnt>
974 const std::array<bool,FlagCnt> &specialFlags)
const
976 static_assert(FlagCnt <= 8u);
979 for (
const bool &specialFlag: specialFlags) {
981 featureBits[
type->GetFeatureMaskBytes() - 1u] |= mask;
983 featureBits[
type->GetFeatureMaskBytes() - 1u] &= uint8_t(~mask);
988 for (
size_t i = 0; i <
type->GetFeatureMaskBytes(); i++) {
989 writer.Write(featureBits[i]);
992 for (
size_t i = 0; i <
type->GetFeatureMaskBytes(); i++) {
993 writer.Write(featureBits[i]);
998 for (
const bool &specialFlag: specialFlags) {
1005 writer.Write(flagByte);
1008 for (
const auto &feature :
type->GetFeatures()) {
1009 size_t idx=feature.GetIndex();
1012 feature.GetFeature()->HasValue()) {
1015 value->Write(writer);
1023 if (
HasFeature(featureInstance.GetIndex())) {
1025 if (feature->HasValue()) {
1027 const auto *v=
dynamic_cast<const T*
>(value);
1065 std::vector<TypeInfoRef> types;
1066 std::vector<TypeInfoRef> nodeTypes;
1067 std::vector<TypeInfoRef> wayTypes;
1068 std::vector<TypeInfoRef> areaTypes;
1069 std::vector<TypeInfoRef> routeTypes;
1071 uint8_t nodeTypeIdBytes=1;
1072 uint8_t wayTypeIdBytes=1;
1073 uint8_t areaTypeIdBits=1;
1074 uint8_t areaTypeIdBytes=1;
1075 uint8_t routeTypeIdBytes=1;
1077 std::unordered_map<std::string,TypeInfoRef> nameToTypeMap;
1081 std::vector<FeatureRef> features;
1083 std::unordered_map<std::string,FeatureRef> nameToFeatureMap;
1134 return tagRegistry.GetTagId(name);
1139 return tagRegistry.GetTagId(name);
1160 tagRegistry.RegisterSurfaceToGradeMapping(surface,
1172 tagRegistry.RegisterMaxSpeedAlias(alias,
1201 return nodeTypeIdBytes;
1214 return wayTypeIdBytes;
1227 return areaTypeIdBits;
1232 return areaTypeIdBytes;
1245 return routeTypeIdBytes;
1254 return types.size();
1267 assert(index<types.size());
1269 return types[index];
1277 assert(
id<=nodeTypes.size());
1283 return nodeTypes[
id-1];
1291 assert(
id<=wayTypes.size());
1297 return wayTypes[
id-1];
1305 assert(
id<=areaTypes.size());
1311 return areaTypes[
id-1];
1319 assert(
id<=routeTypes.size());
1325 return routeTypes[
id-1];
#define OSMSCOUT_API
Definition CoreImportExport.h:45
TypeInfo & SetAreaId(TypeId id)
bool GetIndexAsAddress() const
Definition TypeConfig.h:499
const T * findValue() const
Definition TypeConfig.h:1020
bool IsInGroup(const std::string &groupName) const
Definition TypeConfig.h:710
bool StoreToDataFile(const std::string &directory) const
TypeInfoRef GetType() const
Definition TypeConfig.h:791
size_t GetOffset() const
Definition TypeFeature.h:280
bool GetFeature(const std::string &name, size_t &index) const
bool CanBeArea() const
Definition TypeConfig.h:387
const TagRegistry & GetTagRegistry() const
Definition TypeConfig.h:1142
TypeInfoRef GetTypeInfo(const std::string &name) const
TypeInfoRef typeInfoIgnore
Definition TypeConfig.h:1115
bool GetIndexAsLocation() const
Definition TypeConfig.h:514
void ClearFeatureValues()
FeatureRef GetFeature(const std::string &name) const
std::string GetDescription(const std::string &languageCode) const
uint8_t GetAreaTypeIdBits() const
Definition TypeConfig.h:1225
TypeInfoRef GetAreaTypeInfo(TypeId id) const
Definition TypeConfig.h:1303
TypeInfo & SetIsPath(bool isPath)
Definition TypeConfig.h:410
uint8_t GetNodeTypeIdBytes() const
Definition TypeConfig.h:1199
bool HasFeature(const std::string &featureName) const
void Read(FileScanner &scanner)
bool IsRoute() const
Definition TypeConfig.h:615
const std::vector< FeatureInstance > & GetFeatures() const
Definition TypeConfig.h:233
bool GetMergeAreas() const
Definition TypeConfig.h:642
TagId tagDataPolygon
Definition TypeConfig.h:1110
static const uint8_t typeWay
Condition applies to ways.
Definition TypeConfig.h:75
TypeInfo & SetLanes(uint8_t lanes)
Definition TypeConfig.h:678
bool HasFeatures() const
Definition TypeConfig.h:205
FeatureValueBuffer & operator=(const FeatureValueBuffer &other)
FeatureValue * AllocateValue(size_t idx)
TypeInfo & SetRouteId(TypeId id)
void RegisterMaxSpeedAlias(const std::string &alias, uint8_t maxSpeed)
Definition TypeConfig.h:1169
const std::vector< TypeInfoRef > & GetRouteTypes() const
Definition TypeConfig.h:1238
static const uint8_t typeNode
Condition applies to nodes.
Definition TypeConfig.h:74
SpecialType
Definition TypeConfig.h:79
@ multipolygon
Definition TypeConfig.h:81
@ none
Definition TypeConfig.h:80
@ route
Definition TypeConfig.h:83
@ routeMaster
Definition TypeConfig.h:82
TypeInfo & SetSpecialType(SpecialType specialType)
Definition TypeConfig.h:564
bool GetPinWay() const
Definition TypeConfig.h:627
void Write(FileWriter &writer, const std::array< bool, FlagCnt > &specialFlags) const
Definition TypeConfig.h:973
FeatureValueBuffer & operator=(FeatureValueBuffer &&other) noexcept
void Write(FileWriter &writer, bool specialFlag1, bool specialFlag2, bool specialFlag3) const
void CopyMissingValues(const FeatureValueBuffer &other)
TypeInfoRef typeInfoCoastline
Internal type for coastlines.
Definition TypeConfig.h:1120
TypeInfo & SetMergeAreas(bool mergeAreas)
Definition TypeConfig.h:635
void Read(FileScanner &scanner, bool &specialFlag)
TypeInfo & CanBeNode(bool canBeNode)
Definition TypeConfig.h:350
static TypeInfoRef Read(FileScanner &scanner)
uint8_t GetAreaTypeIdBytes() const
Definition TypeConfig.h:1230
TypeInfo & SetIndexAsPOI(bool indexAsPOI)
Definition TypeConfig.h:537
TypeId GetRouteId() const
Definition TypeConfig.h:300
void Set(const FeatureValueBuffer &other)
TypeInfo & SetIndex(size_t index)
@ none
Definition Transformation.h:185
std::string GetName() const
Definition TypeConfig.h:324
TypeInfo & SetIgnoreSeaLand(bool ignoreSeaLand)
Definition TypeConfig.h:650
void Read(FileScanner &scanner, bool &specialFlag1, bool &specialFlag2, bool &specialFlag3)
TypeInfo & operator=(const TypeInfo &&other)=delete
uint8_t GetLanes() const
Definition TypeConfig.h:685
const std::vector< TypeInfoRef > & GetWayTypes() const
Definition TypeConfig.h:1207
TypeInfo & AddFeature(const FeatureRef &feature)
bool GetWayAreaType(const TagMap &tagMap, TypeInfoRef &wayType, TypeInfoRef &areaType) const
TypeInfoRef GetWayTypeInfo(TypeId id) const
Definition TypeConfig.h:1289
TypeInfoRef GetNodeTypeInfo(TypeId id) const
Definition TypeConfig.h:1275
TypeInfoRef typeInfoTileLand
Internal type for ground tiles of type "land".
Definition TypeConfig.h:1116
bool GetIndexAsPOI() const
Definition TypeConfig.h:544
static const uint32_t MAX_FORMAT_VERSION
Definition TypeConfig.h:1057
TypeInfoRef typeInfoTileSea
Internal type for ground tiles of type "sea".
Definition TypeConfig.h:1117
TypeInfo & CanBeRelation(bool canBeRelation)
Definition TypeConfig.h:395
uint8_t GetWayTypeIdBytes() const
Definition TypeConfig.h:1212
bool HasConditions() const
Definition TypeConfig.h:334
void Write(FileWriter &writer, bool specialFlag) const
TypeInfoRef typeInfoTileUnknown
Internal type for ground tiles of type "unknown".
Definition TypeConfig.h:1119
TypeInfo & CanBeWay(bool canBeWay)
Definition TypeConfig.h:365
size_t GetFeatureMaskBytes() const
Definition TypeConfig.h:249
bool CanRoute() const
Definition TypeConfig.h:449
SpecialType GetSpecialType() const
Definition TypeConfig.h:570
const std::unordered_set< std::string > & GetGroups() const
Definition TypeConfig.h:705
TypeInfo & SetMultipolygon()
Definition TypeConfig.h:578
bool CanRouteBicycle() const
Definition TypeConfig.h:477
FeatureValue * GetValue(const FeatureValueBuffer &buffer) const
TypeInfo & SetNodeId(TypeId id)
TypeInfo(const TypeInfo &other)=delete
TypeInfoRef typeInfoTileCoast
Internal type for ground tiles of type "coast".
Definition TypeConfig.h:1118
bool HasFeature(size_t idx) const
Definition TypeConfig.h:815
uint8_t GetOnewayLanes() const
Definition TypeConfig.h:697
TypeInfoRef RegisterType(const TypeInfoRef &typeInfo)
TypeInfo & SetIgnore(bool ignore)
Definition TypeConfig.h:666
TypeInfoRef typeInfoOSMTileBorder
Internal type for OSM tile borders.
Definition TypeConfig.h:1121
size_t GetIndex() const
Definition TypeConfig.h:308
TypeInfo & SetIndexAsAddress(bool indexAsAddress)
Definition TypeConfig.h:492
TypeInfo & SetIndexAsLocation(bool indexAsLocation)
Definition TypeConfig.h:507
TypeInfo & CanRouteCar(bool canBeRoute)
Definition TypeConfig.h:442
bool CanRouteFoot() const
Definition TypeConfig.h:472
TypeInfo & CanBeArea(bool canBeArea)
Definition TypeConfig.h:380
bool CanBeWay() const
Definition TypeConfig.h:372
TypeInfo & SetWayId(TypeId id)
TagId tagArea
Definition TypeConfig.h:1108
size_t GetFeatureValueBufferSize() const
Definition TypeConfig.h:266
bool GetOptimizeLowZoom() const
Definition TypeConfig.h:559
const std::vector< FeatureRef > & GetFeatures() const
Definition TypeConfig.h:1377
TypeInfoRef typeInfoOSMSubTileBorder
Internal type for OSM tile borders.
Definition TypeConfig.h:1122
void Read(FileScanner &scanner, bool &specialFlag1, bool &specialFlag2)
bool operator==(const FeatureValueBuffer &other) const
bool operator!=(const FeatureValueBuffer &other) const
TypeInfoRef GetRelationType(const TagMap &tagMap) const
TypeInfo & SetIndexAsRegion(bool indexAsRegion)
Definition TypeConfig.h:522
TypeId GetWayId() const
Definition TypeConfig.h:284
TagId tagJunction
Definition TypeConfig.h:1113
bool CanBeRelation() const
Definition TypeConfig.h:402
bool IsMultipolygon() const
Definition TypeConfig.h:605
bool IsRouteMaster() const
Definition TypeConfig.h:610
bool IsPath() const
Definition TypeConfig.h:417
bool CanRouteCar() const
Definition TypeConfig.h:482
static const uint32_t MIN_FORMAT_VERSION
Definition TypeConfig.h:1056
TypeInfo & SetPinWay(bool pinWay)
Definition TypeConfig.h:620
TagId GetTagId(const std::string &name) const
Definition TypeConfig.h:1137
static const uint8_t typeRelation
Condition applies to relations.
Definition TypeConfig.h:77
bool IsInternal() const
Definition TypeConfig.h:316
TypeInfo & CanRouteBicycle(bool canBeRoute)
Definition TypeConfig.h:432
TypeInfo & SetRoute()
Definition TypeConfig.h:598
static const uint8_t typeArea
Condition applies to areas.
Definition TypeConfig.h:76
bool LoadFromDataFile(const std::string &directory)
TypeInfoRef GetTypeInfo(size_t index) const
Definition TypeConfig.h:1265
FeatureInstance GetFeature(size_t idx) const
Definition TypeConfig.h:807
bool CanRoute(Vehicle vehicle) const
Definition TypeConfig.h:457
bool CanBeNode() const
Definition TypeConfig.h:357
void FreeValue(size_t idx)
bool LoadFromOSTFile(const std::string &filename)
TypeInfoRef GetNodeType(const TagMap &tagMap) const
Type type
The type of the cell.
Definition GroundTile.h:92
const std::unordered_map< std::string, std::string > & GetDescriptions() const
Definition TypeConfig.h:715
TagId tagNatural
Definition TypeConfig.h:1109
TypeInfoRef GetRouteTypeInfo(TypeId id) const
Definition TypeConfig.h:1317
bool GetIndexAsRegion() const
Definition TypeConfig.h:529
TypeInfo & CanRouteFoot(bool canBeRoute)
Definition TypeConfig.h:425
const std::vector< TypeInfoRef > & GetTypes() const
Definition TypeConfig.h:1186
TypeInfo & AddDescription(const std::string &languageCode, const std::string &description)
TypeInfo(TypeInfo &&other)=delete
TypeId GetAreaId() const
Definition TypeConfig.h:292
const std::list< TypeCondition > & GetConditions() const
Definition TypeConfig.h:342
const std::vector< TypeInfoRef > & GetNodeTypes() const
Definition TypeConfig.h:1194
TypeInfo & SetOnewayLanes(uint8_t lanes)
Definition TypeConfig.h:690
TypeInfo & SetOptimizeLowZoom(bool optimize)
Definition TypeConfig.h:552
TypeInfo & SetType(const std::string &name)
void RegisterSurfaceToGradeMapping(const std::string &surface, size_t grade)
Definition TypeConfig.h:1157
TypeId GetMaxTypeId() const
static const char * FILE_TYPES_DAT
Definition TypeConfig.h:1055
bool GetIgnore() const
Definition TypeConfig.h:673
uint8_t GetRouteTypeIdBytes() const
Definition TypeConfig.h:1243
TypeInfo(const std::string &name)
FeatureValue * GetValue(size_t idx) const
Definition TypeConfig.h:830
TypeInfo & SetRouteMaster()
Definition TypeConfig.h:588
uint8_t GetDefaultAccess() const
TypeInfo & AddGroup(const std::string &groupName)
void SetType(const TypeInfoRef &type)
TagId tagType
Definition TypeConfig.h:1111
TagRegistry & GetTagRegistry()
Definition TypeConfig.h:1147
void Write(FileWriter &writer, bool specialFlag1, bool specialFlag2) const
void Write(FileWriter &writer) const
bool GetIgnoreSeaLand() const
Definition TypeConfig.h:657
FeatureValueBuffer()=default
size_t GetSpecialFeatureMaskBytes() const
Definition TypeConfig.h:258
TagId tagRestriction
Definition TypeConfig.h:1112
TypeId GetNodeId() const
Definition TypeConfig.h:275
size_t GetTypeCount() const
Definition TypeConfig.h:1252
const std::vector< TypeInfoRef > & GetAreaTypes() const
Definition TypeConfig.h:1220
FeatureValueBuffer(FeatureValueBuffer &&other) noexcept
FeatureValueBuffer(const FeatureValueBuffer &other)
TypeInfo & operator=(const TypeInfo &other)=delete
void Parse(TagErrorReporter &errorReporter, const TagRegistry &tagRegistry, const ObjectOSMRef &object, const TagMap &tags)
TypeInfo & AddCondition(unsigned char types, const TagConditionRef &condition)
osmscout::Vehicle vehicle
Definition Agents.h:87
const FeatureInstance & GetFeature(size_t idx) const
Definition TypeConfig.h:225
void RegisterFeature(const FeatureRef &feature)
void Read(FileScanner &scanner, std::array< bool, FlagCnt > &specialFlags)
Definition TypeConfig.h:932
size_t GetFeatureCount() const
Definition TypeConfig.h:241
TagId GetTagId(const char *name) const
Definition TypeConfig.h:1132
Definition TypeFeature.h:41
virtual void Read(FileScanner &scanner)=0
N BitsToBytes(N bits)
Definition Number.h:306
uint16_t TypeId
Definition OSMScoutTypes.h:52
std::shared_ptr< TypeConfig > TypeConfigRef
Definition TypeConfig.h:1396
static const TypeId typeIgnore
Definition TypeConfig.h:57
std::shared_ptr< TagCondition > TagConditionRef
Definition Tag.h:68
std::unordered_map< TagId, std::string > TagMap
Definition Tag.h:41
Vehicle
Definition OSMScoutTypes.h:55
@ vehicleBicycle
Definition OSMScoutTypes.h:57
@ vehicleFoot
Definition OSMScoutTypes.h:56
@ vehicleCar
Definition OSMScoutTypes.h:58
std::shared_ptr< TypeInfo > TypeInfoRef
Definition TypeConfig.h:61
uint16_t TagId
Definition Tag.h:39
std::shared_ptr< Feature > FeatureRef
Definition TypeFeature.h:219
static const uint32_t FILE_FORMAT_VERSION
Definition TypeConfig.h:1044
std::shared_ptr< FeatureValueBuffer > FeatureValueBufferRef
Definition TypeConfig.h:1039
Definition TypeConfig.h:95
unsigned char types
Bitset of types the condition can be applied to.
Definition TypeConfig.h:96
TagConditionRef condition
The root condition.
Definition TypeConfig.h:97