Eclipse SUMO - Simulation of Urban MObility
GNEGeneralHandler.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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}
40
41
43
44
45bool
48}
49
50
51void
53 switch (tag) {
55 // process in Network handler
56 myQueue.push_back(TagType(tag, true, false, false));
57 break;
58 case SUMO_TAG_PARAM:
60 if (myQueue.size() > 0) {
61 // try to parse additional or demand element depending of last inserted tag
62 if (myQueue.back().additional && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
63 myQueue.push_back(TagType(tag, false, true, false));
64 } else if (myQueue.back().demand && myDemandHandler.beginParseAttributes(tag, attrs)) {
65 myQueue.push_back(TagType(tag, false, false, true));
66 } else {
67 myQueue.push_back(TagType(tag, false, false, false));
68 }
69 } else {
70 myQueue.push_back(TagType(tag, false, false, false));
71 }
72 break;
73 case SUMO_TAG_FLOW:
74 if (myQueue.size() > 0) {
75 // try to parse additional or demand element depending of last inserted tag
76 if (myQueue.back().additional && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
77 myQueue.push_back(TagType(tag, false, true, false));
78 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
79 myQueue.push_back(TagType(tag, false, false, true));
80 } else {
81 myQueue.push_back(TagType(tag, false, false, false));
82 }
83 } else {
84 myQueue.push_back(TagType(tag, false, false, false));
85 }
86 break;
87 default:
88 // try to parse additional or demand element
90 myQueue.push_back(TagType(tag, false, true, false));
91 } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
92 myQueue.push_back(TagType(tag, false, false, true));
93 } else {
94 myQueue.push_back(TagType(tag, false, false, false));
95 }
96 break;
97 }
98 // maximum 10 tagTypes
99 if (myQueue.size() > 10) {
100 myQueue.pop_front();
101 }
102}
103
104
105void
107 // check tagType
108 if (myQueue.back().network) {
109 // currently ignored (will be implemented in the future)
110 } else if (myQueue.back().additional) {
111 // end parse additional elements
113 } else if (myQueue.back().demand) {
114 // end parse demand elements
116 } else {
117 WRITE_ERROR(toString(myQueue.back().tag) + " cannot be processed either with additional handler nor with demand handler");
118 }
119}
120
121
122GNEGeneralHandler::TagType::TagType(SumoXMLTag tag_, const bool network_, const bool additional_, const bool demand_) :
123 tag(tag_),
124 network(network_),
125 additional(additional_),
126 demand(demand_) {
127}
128
129/****************************************************************************/
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:274
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_LOCATION
@ SUMO_TAG_FLOW
a flow definitio nusing a from-to edges instead of a route (used by router)
@ SUMO_TAG_PARAM
parameter associated to a certain key
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
bool beginParseAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
begin parse attributes
void endParseAttributes()
end parse attributes
bool isErrorCreatingElement() const
get flag for check if a element wasn't created
void endTag()
end element
void beginTag(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
start element
~GNEGeneralHandler()
Destructor.
std::list< TagType > myQueue
queue with the inserted tags
GNEGeneralHandler(GNENet *net, const std::string &file, const bool allowUndoRedo, const bool overwrite)
Constructor.
GNEAdditionalHandler myAdditionalHandler
additional handler
bool isErrorCreatingElement() const
get flag for check if a element wasn't created
GNERouteHandler myDemandHandler
demand handler
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
bool beginParseAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
begin parse attributes
bool isErrorCreatingElement() const
get flag for check if a element wasn't created
void endParseAttributes()
end parse attributes
Encapsulated SAX-Attributes.
TagType(SumoXMLTag tag, const bool network, const bool additional, const bool demand)
constructor