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.dev/sumo
3 // Copyright (C) 2001-2024 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 
53 size_t
55  return (
56  myParentJunctions.size() +
57  myParentEdges.size() +
58  myParentLanes.size() +
59  myParentAdditionals.size() +
60  myParentDemandElements.size() +
61  myParentGenericDatas.size() +
62  myChildJunctions.size() +
63  myChildEdges.size() +
64  myChildLanes.size() +
65  myChildAdditionals.size() +
66  myChildDemandElements.size() +
67  myChildGenericDatas.size()
68  );
69 }
70 
71 
72 template <> 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 
83 template <> 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 
94 template <> 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 
105 template <> 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 
116 template <> 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 
127 template <> 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 
138 template <> 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 
150 template <> 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 
162 template <> 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 
174 template <> 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 
186 template <> 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 
198 template <> 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 
210 template <> 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 
221 template <> 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 
232 template <> 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 
243 template <> 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 
254 template <> void
256  /*
257  // check demand element
258  if (checkContainer && (std::find(myChildDemandElements.begin(), myChildDemandElements.end(), demandElement) != myChildDemandElements.end())) {
259  throw ProcessError(demandElement->getTagStr() + " with ID='" + demandElement->getID() + "' was already inserted in " + demandElement->getTagStr() + " with ID='" + demandElement->getID() + "'");
260  } else {
261  myChildDemandElements.push_back(demandElement);
262  }
263  */
264  myChildDemandElements.push_back(demandElement);
265 
266 }
267 
268 
269 template <> void
271  // check generic data
272  if (checkContainer && (std::find(myChildGenericDatas.begin(), myChildGenericDatas.end(), genericData) != myChildGenericDatas.end())) {
273  throw ProcessError(genericData->getTagStr() + " with ID='" + genericData->getID() + "' was already inserted in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
274  } else {
275  myChildGenericDatas.push_back(genericData);
276  }
277 }
278 
279 
280 template <> void
282  // check junction
283  auto it = std::find(myChildJunctions.begin(), myChildJunctions.end(), junction);
284  if (checkContainer && (it == myChildJunctions.end())) {
285  throw ProcessError(junction->getTagStr() + " with ID='" + junction->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
286  } else {
287  myChildJunctions.erase(it);
288  }
289 }
290 
291 
292 template <> void
294  // check edge
295  auto it = std::find(myChildEdges.begin(), myChildEdges.end(), edge);
296  if (checkContainer && (it == myChildEdges.end())) {
297  throw ProcessError(edge->getTagStr() + " with ID='" + edge->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
298  } else {
299  myChildEdges.erase(it);
300  }
301 }
302 
303 
304 template <> void
306  // check lane
307  auto it = std::find(myChildLanes.begin(), myChildLanes.end(), lane);
308  if (checkContainer && (it == myChildLanes.end())) {
309  throw ProcessError(lane->getTagStr() + " with ID='" + lane->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
310  } else {
311  myChildLanes.erase(it);
312  }
313 }
314 
315 
316 template <> void
318  // check additional
319  auto it = std::find(myChildAdditionals.begin(), myChildAdditionals.end(), additional);
320  if (checkContainer && (it == myChildAdditionals.end())) {
321  throw ProcessError(additional->getTagStr() + " with ID='" + additional->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
322  } else {
323  myChildAdditionals.erase(it);
324  }
325 }
326 
327 
328 template <> void
330  // check demand element
331  auto it = std::find(myChildDemandElements.begin(), myChildDemandElements.end(), demandElement);
332  if (checkContainer && (it == myChildDemandElements.end())) {
333  throw ProcessError(demandElement->getTagStr() + " with ID='" + demandElement->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
334  } else {
335  myChildDemandElements.erase(it);
336  }
337 }
338 
339 
340 template <> void
342  // check generic data
343  auto it = std::find(myChildGenericDatas.begin(), myChildGenericDatas.end(), genericData);
344  if (checkContainer && (it == myChildGenericDatas.end())) {
345  throw ProcessError(genericData->getTagStr() + " with ID='" + genericData->getID() + "' doesn't exist in " + hierarchicalElement->getTagStr() + " with ID='" + hierarchicalElement->getID() + "'");
346  } else {
347  myChildGenericDatas.erase(it);
348  }
349 }
350 
351 
352 template<> const std::vector<GNEJunction*>&
354  return myParentJunctions;
355 }
356 
357 
358 template<> const std::vector<GNEEdge*>&
360  return myParentEdges;
361 }
362 
363 
364 template<> const std::vector<GNELane*>&
366  return myParentLanes;
367 }
368 
369 
370 template<> const std::vector<GNEAdditional*>&
372  return myParentAdditionals;
373 }
374 
375 
376 template<> const std::vector<GNEDemandElement*>&
378  return myParentDemandElements;
379 }
380 
381 
382 template<> const std::vector<GNEGenericData*>&
384  return myParentGenericDatas;
385 }
386 
387 
388 template<> void
389 GNEHierarchicalContainer::setParents(const std::vector<GNEJunction*>& newParents) {
390  myParentJunctions = newParents;
391 }
392 
393 
394 template<> void
395 GNEHierarchicalContainer::setParents(const std::vector<GNEEdge*>& newParents) {
396  myParentEdges = newParents;
397 }
398 
399 
400 template<> void
401 GNEHierarchicalContainer::setParents(const std::vector<GNELane*>& newParents) {
402  myParentLanes = newParents;
403 }
404 
405 
406 template<> void
407 GNEHierarchicalContainer::setParents(const std::vector<GNEAdditional*>& newParents) {
408  myParentAdditionals = newParents;
409 }
410 
411 
412 template<> void
413 GNEHierarchicalContainer::setParents(const std::vector<GNEDemandElement*>& newParents) {
414  myParentDemandElements = newParents;
415 }
416 
417 
418 template<> void
419 GNEHierarchicalContainer::setParents(const std::vector<GNEGenericData*>& newParents) {
420  myParentGenericDatas = newParents;
421 }
422 
423 
424 template<> const std::vector<GNEJunction*>&
426  return myChildJunctions;
427 }
428 
429 
430 template<> const std::vector<GNEEdge*>&
432  return myChildEdges;
433 }
434 
435 
436 template<> const std::vector<GNELane*>&
438  return myChildLanes;
439 }
440 
441 
442 template<> const std::vector<GNEAdditional*>&
444  return myChildAdditionals;
445 }
446 
447 
448 template<> const std::vector<GNEDemandElement*>&
450  return myChildDemandElements;
451 }
452 
453 
454 template<> const std::vector<GNEGenericData*>&
456  return myChildGenericDatas;
457 }
458 
459 
460 template<> void
461 GNEHierarchicalContainer::setChildren(const std::vector<GNEJunction*>& newChildren) {
462  myChildJunctions = newChildren;
463 }
464 
465 
466 template<> void
467 GNEHierarchicalContainer::setChildren(const std::vector<GNEEdge*>& newChildren) {
468  myChildEdges = newChildren;
469 }
470 
471 
472 template<> void
473 GNEHierarchicalContainer::setChildren(const std::vector<GNELane*>& newChildren) {
474  myChildLanes = newChildren;
475 }
476 
477 
478 template<> void
479 GNEHierarchicalContainer::setChildren(const std::vector<GNEAdditional*>& newChildren) {
480  myChildAdditionals = newChildren;
481 }
482 
483 
484 template<> void
485 GNEHierarchicalContainer::setChildren(const std::vector<GNEDemandElement*>& newChildren) {
486  myChildDemandElements = newChildren;
487 }
488 
489 
490 template<> void
491 GNEHierarchicalContainer::setChildren(const std::vector<GNEGenericData*>& newChildren) {
492  myChildGenericDatas = newChildren;
493 }
494 
495 /****************************************************************************/
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
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
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 & getParents() const
get parents
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
const T & getChildren() const
get children
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
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