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 
35 GNEGeneralHandler::GNEGeneralHandler(GNENet* net, const std::string& file, const bool allowUndoRedo) :
36  GeneralHandler(file),
37  myAdditionalHandler(net, allowUndoRedo),
38  myDemandHandler(file, net, allowUndoRedo) {
39 }
40 
41 
43 
44 
45 void
47  switch (tag) {
48  case SUMO_TAG_PARAM:
49  case SUMO_TAG_INTERVAL:
50  if (myQueue.size() > 0) {
51  // try to parse additional or demand element depending of last inserted tag
52  if (myQueue.back().additional && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
53  myQueue.push_back(TagType(tag, true, false));
54  } else if (myQueue.back().demand && myDemandHandler.beginParseAttributes(tag, attrs)) {
55  myQueue.push_back(TagType(tag, false, true));
56  } else {
57  myQueue.push_back(TagType(tag, false, false));
58  }
59  } else {
60  myQueue.push_back(TagType(tag, false, false));
61  }
62  break;
63  case SUMO_TAG_FLOW:
64  if (myQueue.size() > 0) {
65  // try to parse additional or demand element depending of last inserted tag
66  if (myQueue.back().additional && myAdditionalHandler.beginParseAttributes(tag, attrs)) {
67  myQueue.push_back(TagType(tag, true, false));
68  } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
69  myQueue.push_back(TagType(tag, false, true));
70  } else {
71  myQueue.push_back(TagType(tag, false, false));
72  }
73  } else {
74  myQueue.push_back(TagType(tag, false, false));
75  }
76  break;
77  default:
78  // try to parse additional or demand element
79  if (myAdditionalHandler.beginParseAttributes(tag, attrs)) {
80  myQueue.push_back(TagType(tag, true, false));
81  } else if (myDemandHandler.beginParseAttributes(tag, attrs)) {
82  myQueue.push_back(TagType(tag, false, true));
83  } else {
84  myQueue.push_back(TagType(tag, false, false));
85  }
86  break;
87  }
88  // maximum 10 tagTypes
89  if (myQueue.size() > 10) {
90  myQueue.pop_front();
91  }
92 }
93 
94 
95 void
97  // check tagType
98  if (myQueue.back().additional) {
99  // end parse additional elements
101  } else if (myQueue.back().demand) {
102  // end parse demand elements
104  } else {
105  WRITE_ERROR(toString(myQueue.back().tag) + " cannot be processed either with additional handler nor with demand handler");
106  }
107 }
108 
109 
110 GNEGeneralHandler::TagType::TagType(SumoXMLTag tag_, const bool additional_, const bool demand_) :
111  tag(tag_),
112  additional(additional_),
113  demand(demand_) {
114 }
115 
116 /****************************************************************************/
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:288
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ 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
GNEGeneralHandler(GNENet *net, const std::string &file, const bool allowUndoRedo)
Constructor.
void endTag()
end element
void beginTag(SumoXMLTag tag, const SUMOSAXAttributes &attrs)
start element
~GNEGeneralHandler()
Destructor.
std::list< TagType > myQueue
queue with the inserted tags
GNEAdditionalHandler myAdditionalHandler
additional handler
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
void endParseAttributes()
end parse attributes
Encapsulated SAX-Attributes.
TagType(SumoXMLTag tag, const bool additional, const bool demand)
constructor