Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEHierarchicalContainer.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// Container for GNEHierarchicalElements
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23
24#define CHECK_DUPLICATES
25
26// ===========================================================================
27// member method definitions
28// ===========================================================================
29
31
32
34 const std::vector<GNEJunction*>& parentJunctions,
35 const std::vector<GNEEdge*>& parentEdges,
36 const std::vector<GNELane*>& parentLanes,
37 const std::vector<GNEAdditional*>& parentAdditionals,
38 const std::vector<GNEDemandElement*>& ParentDemandElements,
39 const std::vector<GNEGenericData*>& parentGenericDatas):
40 myParentJunctions(parentJunctions),
41 myParentEdges(parentEdges),
42 myParentLanes(parentLanes),
43 myParentAdditionals(parentAdditionals),
44 myParentDemandElements(ParentDemandElements),
45 myParentGenericDatas(parentGenericDatas) {
46}
47
48
49size_t
51 return (
52 myParentJunctions.size() +
53 myParentEdges.size() +
54 myParentLanes.size() +
55 myParentAdditionals.size() +
58 myChildJunctions.size() +
59 myChildEdges.size() +
60 myChildLanes.size() +
61 myChildAdditionals.size() +
64 );
65}
66
67
68template <> void
72
73
74template <> void
78
79
80template <> void
84
85
86template <> void
90
91
92template <> void
96
97
98template <> void
102
103
104template <> void
106 // check junction
107 auto it = std::find(myParentJunctions.begin(), myParentJunctions.end(), junction);
108 if (it == myParentJunctions.end()) {
109 throw ProcessError(junction->getTagStr() + " with ID='" + junction->getID() + "' is not a parent element");
110 } else {
111 myParentJunctions.erase(it);
112 }
113}
114
115
116template <> void
118 // check edge
119 auto it = std::find(myParentEdges.begin(), myParentEdges.end(), edge);
120 if (it == myParentEdges.end()) {
121 throw ProcessError(edge->getTagStr() + " with ID='" + edge->getID() + "' is not a parent element");
122 } else {
123 myParentEdges.erase(it);
124 }
125}
126
127
128template <> void
130 // check lane
131 auto it = std::find(myParentLanes.begin(), myParentLanes.end(), lane);
132 if (it == myParentLanes.end()) {
133 throw ProcessError(lane->getTagStr() + " with ID='" + lane->getID() + "' is not a parent element");
134 } else {
135 myParentLanes.erase(it);
136 }
137}
138
139
140template <> void
142 // check additional
143 auto it = std::find(myParentAdditionals.begin(), myParentAdditionals.end(), additional);
144 if (it == myParentAdditionals.end()) {
145 throw ProcessError(additional->getTagStr() + " with ID='" + additional->getID() + "' is not a parent element");
146 } else {
147 myParentAdditionals.erase(it);
148 }
149}
150
151
152template <> void
154 // check TAZElement
155 auto it = std::find(myParentDemandElements.begin(), myParentDemandElements.end(), demandElement);
156 if (it == myParentDemandElements.end()) {
157 throw ProcessError(demandElement->getTagStr() + " is not a parent element");
158 } else {
159 myParentDemandElements.erase(it);
160 }
161}
162
163
164template <> void
166 // check generic data
167 auto it = std::find(myParentGenericDatas.begin(), myParentGenericDatas.end(), genericData);
168 if (it == myParentGenericDatas.end()) {
169 throw ProcessError(genericData->getTagStr() + " is not a parent element");
170 } else {
171 myParentGenericDatas.erase(it);
172 }
173}
174
175
176template <> void
180
181
182template <> void
186
187
188template <> void
192
193
194template <> void
198
199
200template <> void
202 myChildDemandElements.push_back(demandElement);
203
204}
205
206
207template <> void
209 myChildGenericDatas.push_back(genericData);
210}
211
212
213template <> void
215 // check junction
216 auto it = std::find(myChildJunctions.begin(), myChildJunctions.end(), junction);
217 if (it == myChildJunctions.end()) {
218 throw ProcessError(junction->getTagStr() + " is not a child element");
219 } else {
220 myChildJunctions.erase(it);
221 }
222}
223
224
225template <> void
227 // check edge
228 auto it = std::find(myChildEdges.begin(), myChildEdges.end(), edge);
229 if (it == myChildEdges.end()) {
230 throw ProcessError(edge->getTagStr() + " is not a child element");
231 } else {
232 myChildEdges.erase(it);
233 }
234}
235
236
237template <> void
239 // check lane
240 auto it = std::find(myChildLanes.begin(), myChildLanes.end(), lane);
241 if (it == myChildLanes.end()) {
242 throw ProcessError(lane->getTagStr() + " is not a child element");
243 } else {
244 myChildLanes.erase(it);
245 }
246}
247
248
249template <> void
251 // check additional
252 auto it = std::find(myChildAdditionals.begin(), myChildAdditionals.end(), additional);
253 if (it == myChildAdditionals.end()) {
254 throw ProcessError(additional->getTagStr() + " is not a child element");
255 } else {
256 myChildAdditionals.erase(it);
257 }
258}
259
260
261template <> void
263 // check demand element
264 auto it = std::find(myChildDemandElements.begin(), myChildDemandElements.end(), demandElement);
265 if (it == myChildDemandElements.end()) {
266 throw ProcessError(demandElement->getTagStr() + " is not a child element");
267 } else {
268 myChildDemandElements.erase(it);
269 }
270}
271
272
273template <> void
275 // check generic data
276 auto it = std::find(myChildGenericDatas.begin(), myChildGenericDatas.end(), genericData);
277 if (it == myChildGenericDatas.end()) {
278 throw ProcessError(genericData->getTagStr() + " is not a child element");
279 } else {
280 myChildGenericDatas.erase(it);
281 }
282}
283
284
285template<> const std::vector<GNEJunction*>&
289
290
291template<> const std::vector<GNEEdge*>&
295
296
297template<> const std::vector<GNELane*>&
301
302
303template<> const std::vector<GNEAdditional*>&
307
308
309template<> const std::vector<GNEDemandElement*>&
313
314
315template<> const std::vector<GNEGenericData*>&
319
320
321template<> void
322GNEHierarchicalContainer::setParents(const std::vector<GNEJunction*>& newParents) {
323 myParentJunctions = newParents;
324}
325
326
327template<> void
328GNEHierarchicalContainer::setParents(const std::vector<GNEEdge*>& newParents) {
329 myParentEdges = newParents;
330}
331
332
333template<> void
334GNEHierarchicalContainer::setParents(const std::vector<GNELane*>& newParents) {
335 myParentLanes = newParents;
336}
337
338
339template<> void
340GNEHierarchicalContainer::setParents(const std::vector<GNEAdditional*>& newParents) {
341 myParentAdditionals = newParents;
342}
343
344
345template<> void
346GNEHierarchicalContainer::setParents(const std::vector<GNEDemandElement*>& newParents) {
347 myParentDemandElements = newParents;
348}
349
350
351template<> void
352GNEHierarchicalContainer::setParents(const std::vector<GNEGenericData*>& newParents) {
353 myParentGenericDatas = newParents;
354}
355
356
357template<> const std::vector<GNEJunction*>&
361
362
363template<> const std::vector<GNEEdge*>&
367
368
369template<> const std::vector<GNELane*>&
373
374
375template<> const std::vector<GNEAdditional*>&
379
380
381template<> const std::vector<GNEDemandElement*>&
385
386
387template<> const std::vector<GNEGenericData*>&
391
392
393template<> void
394GNEHierarchicalContainer::setChildren(const std::vector<GNEJunction*>& newChildren) {
395 myChildJunctions = newChildren;
396}
397
398
399template<> void
400GNEHierarchicalContainer::setChildren(const std::vector<GNEEdge*>& newChildren) {
401 myChildEdges = newChildren;
402}
403
404
405template<> void
406GNEHierarchicalContainer::setChildren(const std::vector<GNELane*>& newChildren) {
407 myChildLanes = newChildren;
408}
409
410
411template<> void
412GNEHierarchicalContainer::setChildren(const std::vector<GNEAdditional*>& newChildren) {
413 myChildAdditionals = newChildren;
414}
415
416
417template<> void
418GNEHierarchicalContainer::setChildren(const std::vector<GNEDemandElement*>& newChildren) {
419 myChildDemandElements = newChildren;
420}
421
422
423template<> void
424GNEHierarchicalContainer::setChildren(const std::vector<GNEGenericData*>& newChildren) {
425 myChildGenericDatas = newChildren;
426}
427
428/****************************************************************************/
An Element which don't belong to GNENet but has influence in the simulation.
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
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
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
std::vector< GNEJunction * > myChildJunctions
vector with the child junctions
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
void removeParentElement(T *element)
remove parent element
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 addChildElement(T *element)
add child element
const T & getParents() const
get parents
void removeChildElement(T *element)
remove child element
void addParentElement(T *element)
add parent element
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