libosmscout 1.1.1
Loading...
Searching...
No Matches
LanesFeature.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_FEATURE_LANES_FEATURE_H
2#define OSMSCOUT_FEATURE_LANES_FEATURE_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2014 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 <osmscout/TypeConfig.h>
25
27
29
30namespace osmscout {
31
33 {
34 private:
35
36 uint8_t lanes=0;
37 std::vector<LaneTurn> turnForward;
38 std::vector<LaneTurn> turnBackward;
39 std::string destinationForward;
40 std::string destinationBackward;
41
42 public:
43 LanesFeatureValue() = default;
44
45 explicit LanesFeatureValue(uint8_t lanes)
46 : lanes(lanes)
47 {
48 // no code
49 }
50
51 void SetLanes(uint8_t forwardLanes,
52 uint8_t backwardLanes)
53 {
54 this->lanes=((forwardLanes & uint8_t(0x7u)) << 2) |
55 ((backwardLanes & uint8_t(0x7u)) << 5);
56 }
57
58 bool HasSingleLane() const
59 {
60 return GetLanes()==0;
61 }
62
63 uint8_t GetForwardLanes() const
64 {
65 return (lanes >> 2) & (uint8_t)0x07;
66 }
67
68 uint8_t GetBackwardLanes() const
69 {
70 return (lanes >> 5) & (uint8_t)0x07;
71 }
72
73 uint8_t GetLanes() const;
74
75 void SetTurnLanes(const std::vector<LaneTurn>& turnForward,
76 const std::vector<LaneTurn>& turnBackward)
77 {
78 this->turnForward=turnForward;
79 this->turnBackward=turnBackward;
80 }
81
82 std::vector<LaneTurn> GetTurnForward() const
83 {
84 return turnForward;
85 }
86
87 std::vector<LaneTurn> GetTurnBackward() const
88 {
89 return turnBackward;
90 }
91
92 std::string GetDestinationForward() const
93 {
94 return destinationForward;
95 }
96
97 std::string GetDestinationBackward() const
98 {
99 return destinationBackward;
100 }
101
102 void SetDestinationLanes(const std::string_view& destinationForward,
103 const std::string_view& destinationBackward)
104 {
105 this->destinationForward=destinationForward;
106 this->destinationBackward=destinationBackward;
107 }
108
109 std::string GetLabel(const Locale &/*locale*/, size_t /*labelIndex*/) const override
110 {
111 if (HasSingleLane()) {
112 return "1";
113 }
114
115 return std::to_string(GetForwardLanes()) + " " + std::to_string(GetBackwardLanes());
116 }
117
118 void Read(FileScanner& scanner) override;
119 void Write(FileWriter& writer) override;
120
121 LanesFeatureValue& operator=(const FeatureValue& other) override;
122 bool operator==(const FeatureValue& other) const override;
123 };
124
126 {
127 private:
128 TagId tagOneway=0;
129 TagId tagLanes=0;
130 TagId tagLanesForward=0;
131 TagId tagLanesBackward=0;
132 TagId tagTurnLanes=0;
133 TagId tagTurnLanesForward=0;
134 TagId tagTurnLanesBackward=0;
135 TagId tagDestinationLanes=0;
136 TagId tagDestinationLanesForward=0;
137 TagId tagDestinationLanesBackward=0;
138
139 public:
141 static const char* const NAME;
142
144 static const char* const NAME_LABEL;
145
147 static const size_t NAME_LABEL_INDEX;
148
149 public:
151 void Initialize(TagRegistry& tagRegistry) override;
152
153 std::string GetName() const override;
154
155 size_t GetValueAlignment() const override;
156 size_t GetValueSize() const override;
157 FeatureValue* AllocateValue(void* buffer) override;
158
159 void Parse(TagErrorReporter& reporter,
160 const TagRegistry& tagRegistry,
161 const FeatureInstance& feature,
162 const ObjectOSMRef& object,
163 const TagMap& tags,
164 FeatureValueBuffer& buffer) const override;
165 };
166
168
169}
170
171#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition TypeFeature.h:41
Definition FeatureReader.h:143
void Parse(TagErrorReporter &reporter, const TagRegistry &tagRegistry, const FeatureInstance &feature, const ObjectOSMRef &object, const TagMap &tags, FeatureValueBuffer &buffer) const override
FeatureValue * AllocateValue(void *buffer) override
static const char *const NAME_LABEL
Definition LanesFeature.h:144
static const size_t NAME_LABEL_INDEX
Definition LanesFeature.h:147
std::string GetName() const override
size_t GetValueAlignment() const override
void Initialize(TagRegistry &tagRegistry) override
static const char *const NAME
Definition LanesFeature.h:141
size_t GetValueSize() const override
void Write(FileWriter &writer) override
std::string GetDestinationForward() const
Definition LanesFeature.h:92
LanesFeatureValue & operator=(const FeatureValue &other) override
std::vector< LaneTurn > GetTurnBackward() const
Definition LanesFeature.h:87
uint8_t GetForwardLanes() const
Definition LanesFeature.h:63
bool operator==(const FeatureValue &other) const override
void Read(FileScanner &scanner) override
void SetLanes(uint8_t forwardLanes, uint8_t backwardLanes)
Definition LanesFeature.h:51
std::string GetDestinationBackward() const
Definition LanesFeature.h:97
std::string GetLabel(const Locale &, size_t) const override
Definition LanesFeature.h:109
LanesFeatureValue(uint8_t lanes)
Definition LanesFeature.h:45
void SetTurnLanes(const std::vector< LaneTurn > &turnForward, const std::vector< LaneTurn > &turnBackward)
Definition LanesFeature.h:75
void SetDestinationLanes(const std::string_view &destinationForward, const std::string_view &destinationBackward)
Definition LanesFeature.h:102
std::vector< LaneTurn > GetTurnForward() const
Definition LanesFeature.h:82
bool HasSingleLane() const
Definition LanesFeature.h:58
uint8_t GetBackwardLanes() const
Definition LanesFeature.h:68
Definition TagErrorReporter.h:33
Definition Area.h:39
std::unordered_map< TagId, std::string > TagMap
Definition Tag.h:41
FeatureValueReader< LanesFeature, LanesFeatureValue > LanesFeatureValueReader
Definition LanesFeature.h:167
uint16_t TagId
Definition Tag.h:39