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-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// General element handler for netedit
19/****************************************************************************/
20
21
22// ===========================================================================
23// included modules
24// ===========================================================================
25
26#include <utils/xml/XMLSubSys.h>
27
28#include "GNEGeneralHandler.h"
29
30
31// ===========================================================================
32// method definitions
33// ===========================================================================
34
35GNEGeneralHandler::GNEGeneralHandler(GNENet* net, const std::string& file, const bool allowUndoRedo, const bool overwrite) :
36 GeneralHandler(file),
37 myAdditionalHandler(net, allowUndoRedo, overwrite),
38 myDemandHandler(file, net, allowUndoRedo, overwrite),
39 myMeanDataHandler(net, allowUndoRedo, overwrite) {
40}
41
42
44
45
46bool
48 if (isAdditionalFile()) {
50 } else if (isRouteFile()) {
52 } else if (isMeanDataFile()) {
54 } else {
55 return true;
56 }
57}
58
59
60bool
66
67
68bool
72
73
74bool
78
79
80bool
84
85
86void
88 switch (tag) {
90 // process in Network handler
91 myQueue.push_back(TagType(tag, TagType::Type::NETWORK));
92 break;
93 case SUMO_TAG_PARAM:
95 if (myQueue.size() > 0) {
96 // try to parse additional or demand element depending of last inserted tag
97 if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
99 } else if (myQueue.back().isDemand() && myDemandHandler.beginParseAttributes(tag, attrs)) {
100 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
101 } else {
102 myQueue.push_back(TagType(tag, TagType::Type::NONE));
103 }
104 } else {
105 myQueue.push_back(TagType(tag, TagType::Type::NONE));
106 }
107 break;
108 case SUMO_TAG_FLOW:
109 if (myQueue.size() > 0) {
110 // try to parse additional or demand element depending of last inserted tag
111 if (myQueue.back().isAdditional() && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
113 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
114 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
115 } else {
116 myQueue.push_back(TagType(tag, TagType::Type::NONE));
117 }
118 } else {
119 myQueue.push_back(TagType(tag, TagType::Type::NONE));
120 }
121 break;
122 default:
123 // try to parse additional or demand element
126 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
127 myQueue.push_back(TagType(tag, TagType::Type::DEMAND));
128 } else if (myMeanDataHandler.beginParseAttributes(tag, attrs)) {
129 myQueue.push_back(TagType(tag, TagType::Type::MEANDATA));
130 } else {
131 myQueue.push_back(TagType(tag, TagType::Type::NONE));
132 }
133 break;
134 }
135 // maximum 10 tagTypes
136 if (myQueue.size() > 10) {
137 myQueue.pop_front();
138 }
139}
140
141
142void
144 // check tagType
145 if (myQueue.back().isNetwork()) {
146 // currently ignored (will be implemented in the future)
147 } else if (myQueue.back().isAdditional()) {
148 // end parse additional elements
150 // mark file as additional
152 } else if (myQueue.back().isDemand()) {
153 // end parse demand elements
155 // mark file as demand
157 } else if (myQueue.back().isMeanData()) {
158 // end parse meanData elements
160 // mark file as mean data
162 } else {
163 // mark file as demand
165 }
166}
167
168
170 tag(tag_),
171 myType(type) {
172}
173
174
175bool
177 return (myType == Type::NETWORK);
178}
179
180
181bool
183 return (myType == Type::ADDITIONAL);
184}
185
186
187bool
189 return (myType == Type::DEMAND);
190}
191
192
193bool
195 return (myType == Type::DATA);
196}
197
198
199bool
201 return (myType == Type::MEANDATA);
202}
203
204/****************************************************************************/
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