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
134
136 template<typename ElementType, typename ParentType>
137 static void insertParent(ElementType* element, ParentType* parent, const int index = -1) {
138 element->myHierarchicalStructureParents.add(parent, index);
139 parent->myHierarchicalStructureChildren.add(element);
140 }
141
143 template<typename ElementType, typename ParentType>
144 static void removeParent(ElementType* element, ParentType* parent) {
145 element->myHierarchicalStructureParents.remove(parent);
146 parent->myHierarchicalStructureChildren.remove(element);
147 }
148
150 template<typename ElementType, typename ParentType>
151 static void updateParent(ElementType element, const int index, ParentType newParent) {
152 // remove element from old parent
153 auto oldParent = element->myHierarchicalStructureParents.template at<ParentType>(index);
154 oldParent->myHierarchicalStructureChildren.remove(element);
155 // update parent
156 element->myHierarchicalStructureParents.replaceSingle(index, newParent);
157 // insert child in new parent
158 newParent->myHierarchicalStructureChildren.add(element);
159 }
160
162 template<typename ElementType, typename ParentType>
163 static void updateParents(ElementType element, GNEHierarchicalContainerParents<ParentType> newParents) {
164 // remove children
165 for (const auto parent : element->myHierarchicalStructureParents.template get<ParentType>()) {
166 parent->myHierarchicalStructureChildren.remove(element);
167 }
168 // update parents
169 element->myHierarchicalStructureParents.replaceAll(newParents);
170 // restore children
171 for (const auto parent : element->myHierarchicalStructureParents.template get<ParentType>()) {
172 parent->myHierarchicalStructureChildren.add(element);
173 }
174 }
175
177 template<typename ElementType, typename ChildType>
178 static void insertChild(ElementType element, ChildType child) {
179 element->myHierarchicalStructureChildren.add(child);
180 child->myHierarchicalStructureParents.add(element);
181 }
182
184 template<typename ElementType, typename ChildType>
185 static void removeChild(ElementType element, ChildType child) {
186 element->myHierarchicalStructureChildren.remove(child);
187 child->myHierarchicalStructureParents.remove(element);
188 }
189
191 template<typename ElementType, typename ChildType>
192 static void updateChildren(ElementType element, GNEHierarchicalContainerChildren<ChildType> newChildren) {
193 // remove children
194 for (const auto children : element->myHierarchicalStructureChildren.template get<ChildType>()) {
195 children->myHierarchicalStructureParents.remove(element);
196 }
197 // update children
198 element->myHierarchicalStructureChildren.replaceAll(newChildren);
199 // restore children
200 for (const auto children : element->myHierarchicalStructureChildren.template get<ChildType>()) {
201 children->myHierarchicalStructureParents.add(element);
202 }
203 }
204
206
209
211 std::string getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const;
212
214
215private:
218
221
224};
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 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 add(ChildType child)
add child element
Hierarchical structure used for keep parents.
void replaceAll(const GNEHierarchicalContainerParents< ParentType > &newParents)
update all parent element