Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNEHierarchicalElement.h
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// A abstract class for representation of hierarchical elements
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
25
26// ===========================================================================
27// class definitions
28// ===========================================================================
29
31
32public:
34 friend class GNEChange_Children;
35 friend class GNEDemandElement;
36
39
42
45
47 void clearParents();
48
51
54
57
60
63
66
69
72
75
78
81
84
87
90
93
96
98
101
103 template<typename ParentType>
104 void setParent(ParentType parent) {
106 parents.push_back(parent);
108 }
109
111 template<typename ParentType>
115
117 template<typename ChildType>
118 void addChildElement(ChildType* element) {
120 }
121
123
126
128 template<typename ElementType, typename ParentType>
129 static void insertParent(ElementType* element, ParentType* parent, const int index = -1) {
130 element->myHierarchicalStructureParents.add(parent, index);
131 parent->myHierarchicalStructureChildren.add(element);
132 }
133
135 template<typename ElementType, typename ParentType>
136 static void removeParent(ElementType* element, ParentType* parent) {
137 element->myHierarchicalStructureParents.remove(parent);
138 parent->myHierarchicalStructureChildren.remove(element);
139 }
140
142 template<typename ElementType, typename ParentType>
143 static void updateParent(ElementType element, const int index, ParentType newParent) {
144 // remove element from old parent
145 auto oldParent = element->myHierarchicalStructureParents.template at<ParentType>(index);
146 oldParent->myHierarchicalStructureChildren.remove(element);
147 // update parent
148 element->myHierarchicalStructureParents.replaceSingle(index, newParent);
149 // insert child in new parent
150 newParent->myHierarchicalStructureChildren.add(element);
151 }
152
154 template<typename ElementType, typename ParentType>
155 static void updateParents(ElementType element, GNEHierarchicalContainerParents<ParentType> newParents) {
156 // remove children
157 for (const auto parent : element->myHierarchicalStructureParents.template get<ParentType>()) {
158 parent->myHierarchicalStructureChildren.remove(element);
159 }
160 // update parents
161 element->myHierarchicalStructureParents.replaceAll(newParents);
162 // restore children
163 for (const auto parent : element->myHierarchicalStructureParents.template get<ParentType>()) {
164 parent->myHierarchicalStructureChildren.add(element);
165 }
166 }
167
169 template<typename ElementType, typename ChildType>
170 static void insertChild(ElementType element, ChildType child) {
171 element->myHierarchicalStructureChildren.add(child);
172 child->myHierarchicalStructureParents.add(element);
173 }
174
176 template<typename ElementType, typename ChildType>
177 static void removeChild(ElementType element, ChildType child) {
178 element->myHierarchicalStructureChildren.remove(child);
179 child->myHierarchicalStructureParents.remove(element);
180 }
181
183 template<typename ElementType, typename ChildType>
184 static void updateChildren(ElementType element, GNEHierarchicalContainerChildren<ChildType> newChildren) {
185 // remove children
186 for (const auto children : element->myHierarchicalStructureChildren.template get<ChildType>()) {
187 children->myHierarchicalStructureParents.remove(element);
188 }
189 // update children
190 element->myHierarchicalStructureChildren.replaceAll(newChildren);
191 // restore children
192 for (const auto children : element->myHierarchicalStructureChildren.template get<ChildType>()) {
193 children->myHierarchicalStructureParents.add(element);
194 }
195 }
196
198
201
203 std::string getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const;
204
206
209
212
213private:
216
219
222};
std::set< ChildType > GNEHierarchicalContainerChildrenSet
std::vector< ChildType > GNEHierarchicalContainerChildren
std::vector< ParentType > GNEHierarchicalContainerParents
const GNEHierarchicalContainerChildren< GNEEdge * > & getChildEdges() const
get child edges
GNEHierarchicalStructureChildren myHierarchicalStructureChildren
hierarchical structure with children
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
const GNEHierarchicalContainerChildren< GNEGenericData * > & getChildGenericDatas() const
return child generic data elements
static void updateChildren(ElementType element, GNEHierarchicalContainerChildren< ChildType > newChildren)
update all children elements
GNEHierarchicalElement()
default Constructor
const GNEHierarchicalContainerChildren< GNELane * > & getChildLanes() const
get child lanes
const GNEHierarchicalContainerParents< GNEGenericData * > & getParentGenericDatas() const
get parent demand elements
static void insertChild(ElementType element, ChildType child)
insert child element
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
bool checkChildAdditionalsOverlapping() const
check if children are overlapped (Used by Rerouters)
const GNEHierarchicalContainerChildrenSet< GNETAZSourceSink * > & getChildTAZSourceSinks() const
return child TAZSourceSinks (Set)
void addChildElement(ChildType *element)
add child without updating parent (ONLY used if we're creating elements without undo-redo)
bool checkChildDemandElementsOverlapping() const
check if child demand elements are overlapped
const GNEHierarchicalContainerChildren< GNEJunction * > & getChildJunctions() const
get child junctions
GNEHierarchicalStructureParents myHierarchicalStructureParents
hierarchical structure with parents
void setParent(ParentType parent)
edit parent and childrens without maintain integrity (use carefully)
const GNEHierarchicalContainerParents< GNEJunction * > & getParentJunctions() const
get parent junctions
static void removeChild(ElementType element, ChildType child)
remove child element
static void insertParent(ElementType *element, ParentType *parent, const int index=-1)
insert parent element
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
const GNEHierarchicalStructureParents getParents() const
get parents(used in GNE_Change)
const GNEHierarchicalContainerParents< GNEAdditional * > getParentStoppingPlaces() const
get parent stoppingPlaces (used by plans)
static void updateParent(ElementType element, const int index, ParentType newParent)
update single parent element
const GNEHierarchicalContainerChildren< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
std::string getNewListOfParents(const GNENetworkElement *currentElement, const GNENetworkElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
GNEHierarchicalElement(const GNEHierarchicalElement &)=delete
Invalidated copy constructor.
void clearParents()
clear hierarchical structure parents (used in GNE_Change)
static void removeParent(ElementType *element, ParentType *parent)
remove parent element
static void updateParents(ElementType element, GNEHierarchicalContainerParents< ParentType > newParents)
update all parent elements
void setParents(const GNEHierarchicalContainerParents< ParentType > &parents)
set multiple parent element (ONLY use in constructors)
const GNEHierarchicalContainerParents< GNEAdditional * > getParentTAZs() const
get parent TAZs (used by plans)
Hierarchical structure used for keep children.
void add(ChildType child)
add child element
Hierarchical structure used for keep parents.
void replaceAll(const GNEHierarchicalContainerParents< ParentType > &newParents)
update all parent element