Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEGeneralHandler.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// General element handler for netedit
19/****************************************************************************/
20
21#include <utils/xml/XMLSubSys.h>
22
23#include "GNEGeneralHandler.h"
24
25// ===========================================================================
26// method definitions
27// ===========================================================================
28
29GNEGeneralHandler::GNEGeneralHandler(GNENet* net, const std::string& file, const bool allowUndoRedo, const bool overwrite) :
30 GeneralHandler(file),
31 myAdditionalHandler(net, file, allowUndoRedo, overwrite),
32 myDemandHandler(net, file, allowUndoRedo, overwrite),
33 myMeanDataHandler(net, file, allowUndoRedo, overwrite) {
34}
35
36
38
39
40bool
42 if (isAdditionalFile()) {
44 } else if (isRouteFile()) {
46 } else if (isMeanDataFile()) {
48 } else {
49 return true;
50 }
51}
52
53
54bool
60
61
62bool
66
67
68bool
72
73
74bool
78
79
80void
82 switch (tag) {
84 // process in Network handler
85 myQueue.push_back(TagType(tag, TagType::Type::NETWORK));
86 break;
87 case SUMO_TAG_PARAM:
89 if (myQueue.size() > 0) {
90 // try to parse additional or demand element depending of last inserted tag
91 if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
93 } else if (myQueue.back().isDemand() && myDemandHandler.beginParseAttributes(tag, attrs)) {
94 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
95 } else {
96 myQueue.push_back(TagType(tag, TagType::Type::NONE));
97 }
98 } else {
99 myQueue.push_back(TagType(tag, TagType::Type::NONE));
100 }
101 break;
102 case SUMO_TAG_FLOW:
103 if (myQueue.size() > 0) {
104 // try to parse additional or demand element depending of last inserted tag
105 if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
107 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
108 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
109 } else {
110 myQueue.push_back(TagType(tag, TagType::Type::NONE));
111 }
112 } else {
113 myQueue.push_back(TagType(tag, TagType::Type::NONE));
114 }
115 break;
116 default:
117 // try to parse additional or demand element
120 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
121 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
122 } else if (myMeanDataHandler.beginParseAttributes(tag, attrs)) {
123 myQueue.push_back(TagType(tag, TagType::Type::MEANDATA));
124 } else {
125 myQueue.push_back(TagType(tag, TagType::Type::NONE));
126 }
127 break;
128 }
129 // maximum 10 tagTypes
130 if (myQueue.size() > 10) {
131 myQueue.pop_front();
132 }
133}
134
135
136void
138 // check tagType
139 if (myQueue.back().isNetwork()) {
140 // currently ignored (will be implemented in the future)
141 } else if (myQueue.back().isAdditional()) {
142 // end parse additional elements
144 // mark file as additional
146 } else if (myQueue.back().isDemand()) {
147 // end parse demand elements
149 // mark file as demand
151 } else if (myQueue.back().isMeanData()) {
152 // end parse meanData elements
154 // mark file as mean data
156 } else {
157 // mark file as demand
159 }
160}
161
162
164 tag(tag_),
165 myType(type) {
166}
167
168
169bool
171 return (myType == Type::NETWORK);
172}
173
174
175bool
177 return (myType == Type::ADDITIONAL);
178}
179
180
181bool
183 return (myType == Type::DEMAND);
184}
185
186
187bool
189 return (myType == Type::DATA);
190}
191
192
193bool
195 return (myType == Type::MEANDATA);
196}
197
198/****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_LOCATION
@ SUMO_TAG_FLOW
a flow definition using from and to edges or a route
@ SUMO_TAG_PARAM
parameter associated to a certain key
bool beginParseAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
begin parse attributes
void endParseAttributes()
end parse attributes
bool isErrorCreatingElement() const
get flag for mark if a element wasn't created
bool postParserTasks()
run post parser tasks
void endTag()
end element
bool isAdditionalFile() const
check if the parser file is a additional file
void beginTag(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
start element
bool isRouteFile() const
check if the parser file is a route file
~GNEGeneralHandler()
Destructor.
std::list< TagType > myQueue
queue with the inserted tags
bool isMeanDataFile() const
check if the parser file is a meanData file
GNEGeneralHandler(GNENet *net, const std::string &file, const bool allowUndoRedo, const bool overwrite)
Constructor.
bool postParserTasks()
run post parser tasks
GNEAdditionalHandler myAdditionalHandler
additional handler
bool isErrorCreatingElement() const
get flag for check if a element wasn't created
TagType::Type fileType
flag for set file type
GNEMeanDataHandler myMeanDataHandler
meanData handler
GNERouteHandler myDemandHandler
demand handler
bool postParserTasks()
run post parser tasks
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
bool postParserTasks()
run post parser tasks
bool beginParseAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
begin parse attributes
void endParseAttributes()
end parse attributes
bool beginParseAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
begin parse attributes
void endParseAttributes()
end parse attributes
Encapsulated SAX-Attributes.
bool isDemand() const
is network element
bool isData() const
is network element
bool isMeanData() const
is network element
TagType(SumoXMLTag tag, Type type)
constructor
bool isNetwork() const
is network element
bool isAdditional() const
is network element