Eclipse SUMO - Simulation of Urban MObility
GNEHierarchicalContainer.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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// Container for GNEHierarchicalElements
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23
24// ===========================================================================
25// static member definitions
26// ===========================================================================
27
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
35
36
38 const std::vector<GNEJunction*>& parentJunctions,
39 const std::vector<GNEEdge*>& parentEdges,
40 const std::vector<GNELane*>& parentLanes,
41 const std::vector<GNEAdditional*>& parentAdditionals,
42 const std::vector<GNEDemandElement*>& ParentDemandElements,
43 const std::vector<GNEGenericData*>& parentGenericDatas):
44 myParentJunctions(parentJunctions),
45 myParentEdges(parentEdges),
46 myParentLanes(parentLanes),
47 myParentAdditionals(parentAdditionals),
48 myParentDemandElements(ParentDemandElements),
49 myParentGenericDatas(parentGenericDatas) {
50}
51
52
53size_t
55 return (
56 myParentJunctions.size() +
57 myParentEdges.size() +
58 myParentLanes.size() +
59 myParentAdditionals.size() +
62 myChildJunctions.size() +
63 myChildEdges.size() +
64 myChildLanes.size() +
65 myChildAdditionals.size() +
68 );
69}
70
71
72template <> void
74 // check junction
75 if (checkContainer && (std::find(myParentJunctions.begin(), myParentJunctions.end(), junction) != myParentJunctions.end())) {
76 throw ProcessError(junction->getTagStr() + " with ID='" + junction->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
77 } else {
78 myParentJunctions.push_back(junction);
79 }
80}
81
82
83template <> void
85 // check edge
86 if (checkContainer && (std::find(myParentEdges.begin(), myParentEdges.end(), edge) != myParentEdges.end())) {
87 throw ProcessError(edge->getTagStr() + " with ID='" + edge->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
88 } else {
89 myParentEdges.push_back(edge);
90 }
91}
92
93
94template <> void
96 // check lane
97 if (checkContainer && (std::find(myParentLanes.begin(), myParentLanes.end(), lane) != myParentLanes.end())) {
98 throw ProcessError(lane->getTagStr() + " with ID='" + lane->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
99 } else {
100 myParentLanes.push_back(lane);
101 }
102}
103
104
105template <> void
107 // check additional
108 if (checkContainer && (std::find(myParentAdditionals.begin(), myParentAdditionals.end(), additional) != myParentAdditionals.end())) {
109 throw ProcessError(additional->getTagStr() + " with ID='" + additional->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
110 } else {
111 myParentAdditionals.push_back(additional);
112 }
113}
114
115
116template <> void
118 // check TAZElement
119 if (checkContainer && (std::find(myParentDemandElements.begin(), myParentDemandElements.end(), demandElement) != myParentDemandElements.end())) {
120 throw ProcessError(demandElement->getTagStr() + " with ID='" + demandElement->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
121 } else {
122 myParentDemandElements.push_back(demandElement);
123 }
124}
125
126
127template <> void
129 // check generic data
130 if (checkContainer && (std::find(myParentGenericDatas.begin(), myParentGenericDatas.end(), genericData) != myParentGenericDatas.end())) {
131 throw ProcessError(genericData->getTagStr() + " with ID='" + genericData->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
132 } else {
133 myParentGenericDatas.push_back(genericData);
134 }
135}
136
137
138template <> void
140 // check junction
141 auto it = std::find(myParentJunctions.begin(), myParentJunctions.end(), junction);
142 if (checkContainer && (it == myParentJunctions.end())) {
143 throw ProcessError(junction->getTagStr() + " with ID='" + junction->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
144 } else {
145 myParentJunctions.erase(it);
146 }
147}
148
149
150template <> void
152 // check edge
153 auto it = std::find(myParentEdges.begin(), myParentEdges.end(), edge);
154 if (checkContainer && (it == myParentEdges.end())) {
155 throw ProcessError(edge->getTagStr() + " with ID='" + edge->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
156 } else {
157 myParentEdges.erase(it);
158 }
159}
160
161
162template <> void
164 // check lane
165 auto it = std::find(myParentLanes.begin(), myParentLanes.end(), lane);
166 if (checkContainer && (it == myParentLanes.end())) {
167 throw ProcessError(lane->getTagStr() + " with ID='" + lane->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
168 } else {
169 myParentLanes.erase(it);
170 }
171}
172
173
174template <> void
176 // check additional
177 auto it = std::find(myParentAdditionals.begin(), myParentAdditionals.end(), additional);
178 if (checkContainer && (it == myParentAdditionals.end())) {
179 throw ProcessError(additional->getTagStr() + " with ID='" + additional->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
180 } else {
181 myParentAdditionals.erase(it);
182 }
183}
184
185
186template <> void
188 // check TAZElement
189 auto it = std::find(myParentDemandElements.begin(), myParentDemandElements.end(), demandElement);
190 if (checkContainer && (it == myParentDemandElements.end())) {
191 throw ProcessError(demandElement->getTagStr() + " with ID='" + demandElement->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
192 } else {
193 myParentDemandElements.erase(it);
194 }
195}
196
197
198template <> void
200 // check generic data
201 auto it = std::find(myParentGenericDatas.begin(), myParentGenericDatas.end(), genericData);
202 if (checkContainer && (it == myParentGenericDatas.end())) {
203 throw ProcessError(genericData->getTagStr() + " with ID='" + genericData->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
204 } else {
205 myParentGenericDatas.erase(it);
206 }
207}
208
209
210template <> void
212 // check junction
213 if (checkContainer && (std::find(myChildJunctions.begin(), myChildJunctions.end(), junction) != myChildJunctions.end())) {
214 throw ProcessError(junction->getTagStr() + " with ID='" + junction->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
215 } else {
216 myChildJunctions.push_back(junction);
217 }
218}
219
220
221template <> void
223 // check edge
224 if (checkContainer && (std::find(myChildEdges.begin(), myChildEdges.end(), edge) != myChildEdges.end())) {
225 throw ProcessError(edge->getTagStr() + " with ID='" + edge->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
226 } else {
227 myChildEdges.push_back(edge);
228 }
229}
230
231
232template <> void
234 // check lane
235 if (checkContainer && (std::find(myChildLanes.begin(), myChildLanes.end(), lane) != myChildLanes.end())) {
236 throw ProcessError(lane->getTagStr() + " with ID='" + lane->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
237 } else {
238 myChildLanes.push_back(lane);
239 }
240}
241
242
243template <> void
245 // check additional
246 if (checkContainer && (std::find(myChildAdditionals.begin(), myChildAdditionals.end(), additional) != myChildAdditionals.end())) {
247 throw ProcessError(additional->getTagStr() + " with ID='" + additional->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
248 } else {
249 myChildAdditionals.push_back(additional);
250 }
251}
252
253
254template <> void
256 // disabled due VIA Attributes
257 /*
258 // check demand element
259 if (checkContainer && (std::find(myChildDemandElements.begin(), myChildDemandElements.end(), demandElement) != myChildDemandElements.end())) {
260 throw ProcessError(demandElement->getTagStr() + " with ID='" + demandElement->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
261 } else {
262 myChildDemandElements.push_back(demandElement);
263 }
264 */
265 myChildDemandElements.push_back(demandElement);
266
267}
268
269
270template <> void
272 // check generic data
273 if (checkContainer && (std::find(myChildGenericDatas.begin(), myChildGenericDatas.end(), genericData) != myChildGenericDatas.end())) {
274 throw ProcessError(genericData->getTagStr() + " with ID='" + genericData->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
275 } else {
276 myChildGenericDatas.push_back(genericData);
277 }
278}
279
280
281template <> void
283 // check junction
284 auto it = std::find(myChildJunctions.begin(), myChildJunctions.end(), junction);
285 if (checkContainer && (it == myChildJunctions.end())) {
286 throw ProcessError(junction->getTagStr() + " with ID='" + junction->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
287 } else {
288 myChildJunctions.erase(it);
289 }
290}
291
292
293template <> void
295 // check edge
296 auto it = std::find(myChildEdges.begin(), myChildEdges.end(), edge);
297 if (checkContainer && (it == myChildEdges.end())) {
298 throw ProcessError(edge->getTagStr() + " with ID='" + edge->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
299 } else {
300 myChildEdges.erase(it);
301 }
302}
303
304
305template <> void
307 // check lane
308 auto it = std::find(myChildLanes.begin(), myChildLanes.end(), lane);
309 if (checkContainer && (it == myChildLanes.end())) {
310 throw ProcessError(lane->getTagStr() + " with ID='" + lane->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
311 } else {
312 myChildLanes.erase(it);
313 }
314}
315
316
317template <> void
319 // check additional
320 auto it = std::find(myChildAdditionals.begin(), myChildAdditionals.end(), additional);
321 if (checkContainer && (it == myChildAdditionals.end())) {
322 throw ProcessError(additional->getTagStr() + " with ID='" + additional->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
323 } else {
324 myChildAdditionals.erase(it);
325 }
326}
327
328
329template <> void
331 // check demand element
332 auto it = std::find(myChildDemandElements.begin(), myChildDemandElements.end(), demandElement);
333 if (checkContainer && (it == myChildDemandElements.end())) {
334 throw ProcessError(demandElement->getTagStr() + " with ID='" + demandElement->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
335 } else {
336 myChildDemandElements.erase(it);
337 }
338}
339
340
341template <> void
343 // check generic data
344 auto it = std::find(myChildGenericDatas.begin(), myChildGenericDatas.end(), genericData);
345 if (checkContainer && (it == myChildGenericDatas.end())) {
346 throw ProcessError(genericData->getTagStr() + " with ID='" + genericData->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
347 } else {
348 myChildGenericDatas.erase(it);
349 }
350}
351
352
353template<> const std::vector<GNEJunction*>&
355 return myParentJunctions;
356}
357
358
359template<> const std::vector<GNEEdge*>&
361 return myParentEdges;
362}
363
364
365template<> const std::vector<GNELane*>&
367 return myParentLanes;
368}
369
370
371template<> const std::vector<GNEAdditional*>&
373 return myParentAdditionals;
374}
375
376
377template<> const std::vector<GNEDemandElement*>&
380}
381
382
383template<> const std::vector<GNEGenericData*>&
386}
387
388
389template<> void
390GNEHierarchicalContainer::setParents(const std::vector<GNEJunction*>& newParents) {
391 myParentJunctions = newParents;
392}
393
394
395template<> void
396GNEHierarchicalContainer::setParents(const std::vector<GNEEdge*>& newParents) {
397 myParentEdges = newParents;
398}
399
400
401template<> void
402GNEHierarchicalContainer::setParents(const std::vector<GNELane*>& newParents) {
403 myParentLanes = newParents;
404}
405
406
407template<> void
408GNEHierarchicalContainer::setParents(const std::vector<GNEAdditional*>& newParents) {
409 myParentAdditionals = newParents;
410}
411
412
413template<> void
414GNEHierarchicalContainer::setParents(const std::vector<GNEDemandElement*>& newParents) {
415 myParentDemandElements = newParents;
416}
417
418
419template<> void
420GNEHierarchicalContainer::setParents(const std::vector<GNEGenericData*>& newParents) {
421 myParentGenericDatas = newParents;
422}
423
424
425template<> const std::vector<GNEJunction*>&
427 return myChildJunctions;
428}
429
430
431template<> const std::vector<GNEEdge*>&
433 return myChildEdges;
434}
435
436
437template<> const std::vector<GNELane*>&
439 return myChildLanes;
440}
441
442
443template<> const std::vector<GNEAdditional*>&
445 return myChildAdditionals;
446}
447
448
449template<> const std::vector<GNEDemandElement*>&
452}
453
454
455template<> const std::vector<GNEGenericData*>&
457 return myChildGenericDatas;
458}
459
460
461template<> void
462GNEHierarchicalContainer::setChildren(const std::vector<GNEJunction*>& newChildren) {
463 myChildJunctions = newChildren;
464}
465
466
467template<> void
468GNEHierarchicalContainer::setChildren(const std::vector<GNEEdge*>& newChildren) {
469 myChildEdges = newChildren;
470}
471
472
473template<> void
474GNEHierarchicalContainer::setChildren(const std::vector<GNELane*>& newChildren) {
475 myChildLanes = newChildren;
476}
477
478
479template<> void
480GNEHierarchicalContainer::setChildren(const std::vector<GNEAdditional*>& newChildren) {
481 myChildAdditionals = newChildren;
482}
483
484
485template<> void
486GNEHierarchicalContainer::setChildren(const std::vector<GNEDemandElement*>& newChildren) {
487 myChildDemandElements = newChildren;
488}
489
490
491template<> void
492GNEHierarchicalContainer::setChildren(const std::vector<GNEGenericData*>& newChildren) {
493 myChildGenericDatas = newChildren;
494}
495
496/****************************************************************************/
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
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
An Element which don't belong to GNENet but has influence in the simulation.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
An Element which don't belong to GNENet but has influence in the simulation.
std::vector< GNEEdge * > myChildEdges
vector with the child edges
std::vector< GNEDemandElement * > myChildDemandElements
vector with the child demand elements
std::vector< GNEDemandElement * > myParentDemandElements
vector of parent demand elements
GNEHierarchicalContainer()
default constructor
std::vector< GNELane * > myParentLanes
vector of parent lanes
void addParentElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
add parent element
size_t getContainerSize() const
get container size
std::vector< GNEAdditional * > myChildAdditionals
vector with the child additional
const T & getChildren() const
get children
std::vector< GNEEdge * > myParentEdges
vector of parent edges
void addChildElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
add child element
std::vector< GNEJunction * > myChildJunctions
vector with the child junctions
void removeParentElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
remove parent element
std::vector< GNEJunction * > myParentJunctions
vector of parent junctions
std::vector< GNEAdditional * > myParentAdditionals
vector of parent additionals
std::vector< GNEGenericData * > myParentGenericDatas
vector of parent generic datas
static const bool checkContainer
flag for enable/disable check duplicate elements (only used for debug purposes)
std::vector< GNEGenericData * > myChildGenericDatas
vector with the generic child data elements
void setChildren(const T &newChildren)
set children
void setParents(const T &newParents)
set parents
void removeChildElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
remove child element
const T & getParents() const
get parents
std::vector< GNELane * > myChildLanes
vector with the child lanes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46