Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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
44 void clearParents();
45
48
51
54
57
60
63
66
69
72
75
77
80
83
86
89
92
95
98
101
104
106
109
111 template<typename ParentType>
112 void setParent(ParentType parent) {
114 parents.push_back(parent);
116 }
117
119 template<typename ParentType>
123
125 template<typename ChildType>
126 void addChildElement(ChildType* element) {
128 }
129
131 template<typename ChildType>
132 void sortChildren(std::vector<ChildType*> sortedChildrens) {
133 // remove elements and add again
134 for (auto child : sortedChildrens) {
136 }
137 for (auto child : sortedChildrens) {
139 }
140 }
141
143
146
148 template<typename ElementType, typename ParentType>
149 static void insertParent(ElementType* element, ParentType* parent, const int index = -1) {
150 element->myHierarchicalStructureParents.add(parent, index);
151 parent->myHierarchicalStructureChildren.add(element);
152 }
153
155 template<typename ElementType, typename ParentType>
156 static void removeParent(ElementType* element, ParentType* parent) {
157 element->myHierarchicalStructureParents.remove(parent);
158 parent->myHierarchicalStructureChildren.remove(element);
159 }
160
162 template<typename ElementType, typename ParentType>
163 static void updateParent(ElementType element, const int index, ParentType newParent) {
164 // remove element from old parent
165 auto oldParent = element->myHierarchicalStructureParents.template at<ParentType>(index);
166 oldParent->myHierarchicalStructureChildren.remove(element);
167 // update parent
168 element->myHierarchicalStructureParents.replaceSingle(index, newParent);
169 // insert child in new parent
170 newParent->myHierarchicalStructureChildren.add(element);
171 }
172
174 template<typename ElementType, typename ParentType>
175 static void updateParents(ElementType element, GNEHierarchicalContainerParents<ParentType> newParents) {
176 // remove children
177 for (const auto parent : element->myHierarchicalStructureParents.template get<ParentType>()) {
178 parent->myHierarchicalStructureChildren.remove(element);
179 }
180 // update parents
181 element->myHierarchicalStructureParents.replaceAll(newParents);
182 // restore children
183 for (const auto parent : element->myHierarchicalStructureParents.template get<ParentType>()) {
184 parent->myHierarchicalStructureChildren.add(element);
185 }
186 }
187
189 template<typename ElementType, typename ChildType>
190 static void insertChild(ElementType element, ChildType child) {
191 element->myHierarchicalStructureChildren.add(child);
192 child->myHierarchicalStructureParents.add(element);
193 }
194
196 template<typename ElementType, typename ChildType>
197 static void removeChild(ElementType element, ChildType child) {
198 element->myHierarchicalStructureChildren.remove(child);
199 child->myHierarchicalStructureParents.remove(element);
200 }
201
203 template<typename ElementType, typename ChildType>
204 static void updateChildren(ElementType element, GNEHierarchicalContainerChildren<ChildType> newChildren) {
205 // remove children
206 for (const auto children : element->myHierarchicalStructureChildren.template get<ChildType>()) {
207 children->myHierarchicalStructureParents.remove(element);
208 }
209 // update children
210 element->myHierarchicalStructureChildren.replaceAll(newChildren);
211 // restore children
212 for (const auto children : element->myHierarchicalStructureChildren.template get<ChildType>()) {
213 children->myHierarchicalStructureParents.add(element);
214 }
215 }
216
218
221
223 std::string getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const;
224
226
227private:
230
233
236};
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
const GNEHierarchicalContainerChildrenSet< GNETAZSourceSink * > & getChildTAZSourceSinks() const
return child TAZSourceSinks (Set)
void sortChildren(std::vector< ChildType * > sortedChildrens)
Sort childrens.
void addChildElement(ChildType *element)
add child without updating parent (ONLY used if we're creating elements without undo-redo)
const GNEHierarchicalStructureChildren & getChildren() const
get child container
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 GNEHierarchicalContainerParents< GNEAdditional * > getParentStoppingPlaces() const
get parent stoppingPlaces (used by plans)
const GNEHierarchicalStructureParents & getParents() const
get parents container
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 remove(ChildType child)
remove child element
void add(ChildType child)
add child element
Hierarchical structure used for keep parents.
void replaceAll(const GNEHierarchicalContainerParents< ParentType > &newParents)
update all parent element