Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEHierarchicalStructureParents.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Structure for GNEHierarchicalElements centered in parents
19/****************************************************************************/
20
29
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
37
38
39void
49
50// get functions
51
56
57
62
63
68
69
74
75
80
81
86
87
92
93// at functions
94
95template<> GNEJunction*
97 return myParentJunctions.at(index);
98}
99
100
101template<> GNEEdge*
103 return myParentEdges.at(index);
104}
105
106
107template<> GNELane*
109 return myParentLanes.at(index);
110}
111
112
113template<> GNEAdditional*
115 return myParentAdditionals.at(index);
116}
117
118
119template<> GNETAZSourceSink*
121 return myParentTAZSourceSinks.at(index);
122}
123
124
125template<> GNEDemandElement*
127 return myParentDemandElements.at(index);
128}
129
130
131template<> GNEGenericData*
133 return myParentGenericDatas.at(index);
134}
135
136// add functions
137
138template <> void
140 if (index == -1) {
141 myParentJunctions.push_back(parent);
142 } else if ((index < 0) || (index > (int)myParentJunctions.size())) {
143 myParentJunctions.insert(myParentJunctions.begin() + index, parent);
144 } else {
145 throw ProcessError("invalid index in GNEHierarchicalStructureParents::add");
146 }
147}
148
149
150template <> void
152 if (index == -1) {
153 myParentEdges.push_back(parent);
154 } else if ((index < 0) || (index > (int)myParentEdges.size())) {
155 myParentEdges.insert(myParentEdges.begin() + index, parent);
156 } else {
157 throw ProcessError("invalid index in GNEHierarchicalStructureParents::add");
158 }
159}
160
161
162template <> void
164 if (index == -1) {
165 myParentLanes.push_back(parent);
166 } else if ((index < 0) || (index > (int)myParentLanes.size())) {
167 myParentLanes.insert(myParentLanes.begin() + index, parent);
168 } else {
169 throw ProcessError("invalid index in GNEHierarchicalStructureParents::add");
170 }
171}
172
173
174template <> void
176 if (index == -1) {
177 myParentAdditionals.push_back(parent);
178 } else if ((index < 0) || (index > (int)myParentAdditionals.size())) {
179 myParentAdditionals.insert(myParentAdditionals.begin() + index, parent);
180 } else {
181 throw ProcessError("invalid index in GNEHierarchicalStructureParents::add");
182 }
183}
184
185
186template <> void
188 if (index == -1) {
189 myParentTAZSourceSinks.push_back(parent);
190 } else if ((index < 0) || (index > (int)myParentTAZSourceSinks.size())) {
191 myParentTAZSourceSinks.insert(myParentTAZSourceSinks.begin() + index, parent);
192 } else {
193 throw ProcessError("invalid index in GNEHierarchicalStructureParents::add");
194 }
195}
196
197
198template <> void
200 if (index == -1) {
201 myParentDemandElements.push_back(parent);
202 } else if ((index < 0) || (index > (int)myParentDemandElements.size())) {
203 myParentDemandElements.insert(myParentDemandElements.begin() + index, parent);
204 } else {
205 throw ProcessError("invalid index in GNEHierarchicalStructureParents::add");
206 }
207}
208
209
210template <> void
212 if (index == -1) {
213 myParentGenericDatas.push_back(parent);
214 } else if ((index < 0) || (index > (int)myParentGenericDatas.size())) {
215 myParentGenericDatas.insert(myParentGenericDatas.begin() + index, parent);
216 } else {
217 throw ProcessError("invalid index in GNEHierarchicalStructureParents::add");
218 }
219}
220
221// remove functions
222
223template <> void
225 auto it = std::find(myParentJunctions.begin(), myParentJunctions.end(), junction);
226 if (it != myParentJunctions.end()) {
227 myParentJunctions.erase(it);
228 } else {
229 throw ProcessError(junction->getTagStr() + " with ID='" + junction->getID() + "' is not a parent parent");
230 }
231}
232
233
234template <> void
236 auto it = std::find(myParentEdges.begin(), myParentEdges.end(), edge);
237 if (it != myParentEdges.end()) {
238 myParentEdges.erase(it);
239 } else {
240 throw ProcessError(edge->getTagStr() + " with ID='" + edge->getID() + "' is not a parent parent");
241 }
242}
243
244
245template <> void
247 auto it = std::find(myParentLanes.begin(), myParentLanes.end(), lane);
248 if (it != myParentLanes.end()) {
249 myParentLanes.erase(it);
250 } else {
251 throw ProcessError(lane->getTagStr() + " with ID='" + lane->getID() + "' is not a parent parent");
252 }
253}
254
255
256template <> void
258 auto it = std::find(myParentAdditionals.begin(), myParentAdditionals.end(), additional);
259 if (it != myParentAdditionals.end()) {
260 myParentAdditionals.erase(it);
261 } else {
262 throw ProcessError(additional->getTagStr() + " with ID='" + additional->getID() + "' is not a parent parent");
263 }
264}
265
266
267template <> void
269 auto it = std::find(myParentTAZSourceSinks.begin(), myParentTAZSourceSinks.end(), TAZSourceSink);
270 if (it != myParentTAZSourceSinks.end()) {
271 myParentTAZSourceSinks.erase(it);
272 } else {
273 throw ProcessError(TAZSourceSink->getTagStr() + " with ID='" + TAZSourceSink->getID() + "' is not a parent parent");
274 }
275}
276
277
278template <> void
280 auto it = std::find(myParentDemandElements.begin(), myParentDemandElements.end(), demandElement);
281 if (it != myParentDemandElements.end()) {
282 myParentDemandElements.erase(it);
283 } else {
284 throw ProcessError(demandElement->getTagStr() + " is not a parent parent");
285 }
286}
287
288
289template <> void
291 auto it = std::find(myParentGenericDatas.begin(), myParentGenericDatas.end(), genericData);
292 if (it != myParentGenericDatas.end()) {
293 myParentGenericDatas.erase(it);
294 } else {
295 throw ProcessError(genericData->getTagStr() + " is not a parent parent");
296 }
297}
298
299// updateParentElement functions
300
301template <> void
303 if ((index >= 0) && (index < (int)myParentJunctions.size())) {
304 myParentJunctions[index] = newParent;
305 } else {
306 throw ProcessError("Invalid index " + toString(newParent->getID()) + " updating junction parents");
307 }
308}
309
310
311template <> void
313 if ((index >= 0) && (index < (int)myParentEdges.size())) {
314 myParentEdges[index] = newParent;
315 } else {
316 throw ProcessError("Invalid index " + toString(newParent->getID()) + " updating edge parents");
317 }
318}
319
320
321template <> void
323 if ((index >= 0) && (index < (int)myParentLanes.size())) {
324 myParentLanes[index] = newParent;
325 } else {
326 throw ProcessError("Invalid index " + toString(newParent->getID()) + " updating lane parents");
327 }
328}
329
330
331template <> void
333 if ((index >= 0) && (index < (int)myParentAdditionals.size())) {
334 myParentAdditionals[index] = newParent;
335 } else {
336 throw ProcessError("Invalid index " + toString(newParent->getID()) + " updating additional parents");
337 }
338}
339
340
341template <> void
343 if ((index >= 0) && (index < (int)myParentTAZSourceSinks.size())) {
344 myParentTAZSourceSinks[index] = newParent;
345 } else {
346 throw ProcessError("Invalid index " + toString(newParent->getID()) + " updating sourceSink parents");
347 }
348}
349
350
351template <> void
353 if ((index >= 0) && (index < (int)myParentDemandElements.size())) {
354 myParentDemandElements[index] = newParent;
355 } else {
356 throw ProcessError("Invalid index " + toString(newParent->getID()) + " updating demand parent parents");
357 }
358}
359
360
361template <> void
363 if ((index >= 0) && (index < (int)myParentGenericDatas.size())) {
364 myParentGenericDatas[index] = newParent;
365 } else {
366 throw ProcessError("Invalid index " + toString(newParent->getID()) + " updating generic data parents");
367 }
368}
369
370// updateParents functions
371
372template <> void
376
377
378template <> void
382
383
384template <> void
388
389
390template <> void
394
395
396template <> void
400
401
402template <> void
406
407
408template <> void
412
413/****************************************************************************/
std::vector< ParentType > GNEHierarchicalContainerParents
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const std::string getID() const
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNEHierarchicalContainerParents< GNETAZSourceSink * > myParentTAZSourceSinks
parents TAZSourceSinks (Unused, but needed for function addElementInParentsAndChildren)
void remove(ParentType parent)
remove parent element
void replaceAll(const GNEHierarchicalContainerParents< ParentType > &newParents)
update all parent element
ParentType at(const int index) const
get parent at the given position
GNEHierarchicalContainerParents< GNEJunction * > myParentJunctions
parents junctions
GNEHierarchicalContainerParents< GNEDemandElement * > myParentDemandElements
parents demand elements
GNEHierarchicalContainerParents< GNELane * > myParentLanes
parents lanes
const GNEHierarchicalContainerParents< ParentType > & get() const
get parents
GNEHierarchicalContainerParents< GNEAdditional * > myParentAdditionals
parents additionals
GNEHierarchicalContainerParents< GNEGenericData * > myParentGenericDatas
parents generic datas
void add(ParentType parent, const int index=-1)
add parent element
void replaceSingle(const int index, ParentType newParent)
update single parent element
GNEHierarchicalContainerParents< GNEEdge * > myParentEdges
parents edges