Eclipse SUMO - Simulation of Urban MObility
NIXMLTypesHandler.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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Importer for edge type information stored in XML
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <iostream>
28 #include <xercesc/sax/HandlerBase.hpp>
29 #include <xercesc/sax/AttributeList.hpp>
30 #include <xercesc/sax/SAXParseException.hpp>
31 #include <xercesc/sax/SAXException.hpp>
36 #include <utils/common/ToString.h>
38 #include <netbuild/NBEdge.h>
39 #include <netbuild/NBTypeCont.h>
40 #include "NIXMLTypesHandler.h"
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
47  : SUMOSAXHandler("xml-types - file"),
48  myTypeCont(tc) {}
49 
50 
52 
53 
54 void
56  const SUMOSAXAttributes& attrs) {
57  switch (element) {
58  case SUMO_TAG_TYPE: {
59  bool ok = true;
60  // get the id, report a warning if not given or empty...
61  myCurrentTypeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
62  const char* const id = myCurrentTypeID.c_str();
63  const std::string defType = myTypeCont.knows(myCurrentTypeID) ? myCurrentTypeID : "";
64  const int priority = attrs.getOpt<int>(SUMO_ATTR_PRIORITY, id, ok, myTypeCont.getPriority(defType));
65  const int numLanes = attrs.getOpt<int>(SUMO_ATTR_NUMLANES, id, ok, myTypeCont.getNumLanes(defType));
66  const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, id, ok, myTypeCont.getSpeed(defType));
67  const std::string allowS = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, id, ok, "");
68  const std::string disallowS = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, id, ok, "");
69  const bool oneway = attrs.getOpt<bool>(SUMO_ATTR_ONEWAY, id, ok, myTypeCont.getIsOneWay(defType));
70  const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id, ok, false);
71  const double width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, id, ok, myTypeCont.getWidth(defType));
72  const double maxWidth = attrs.getOpt<double>(SUMO_ATTR_MAXWIDTH, id, ok, myTypeCont.getMaxWidth(defType));
73  const double minWidth = attrs.getOpt<double>(SUMO_ATTR_MINWIDTH, id, ok, myTypeCont.getMinWidth(defType));
74  const double widthResolution = attrs.getOpt<double>(SUMO_ATTR_WIDTHRESOLUTION, id, ok, myTypeCont.getWidthResolution(defType));
75  const double sidewalkWidth = attrs.getOpt<double>(SUMO_ATTR_SIDEWALKWIDTH, id, ok, myTypeCont.getSidewalkWidth(defType));
76  const double bikeLaneWidth = attrs.getOpt<double>(SUMO_ATTR_BIKELANEWIDTH, id, ok, myTypeCont.getBikeLaneWidth(defType));
77  if (!ok) {
78  return;
79  }
80  // build the type
81  SVCPermissions permissions = myTypeCont.getPermissions(defType);
82  if (allowS != "" || disallowS != "") {
83  permissions = parseVehicleClasses(allowS, disallowS);
84  }
85  myTypeCont.insert(myCurrentTypeID, numLanes, speed, priority, permissions, width, oneway, sidewalkWidth, bikeLaneWidth, widthResolution, maxWidth, minWidth);
86  if (discard) {
88  }
92  };
93  for (int i = 0; i < 10; i++) {
94  if (attrs.hasAttribute(myAttrs[i])) {
96  }
97  }
98  break;
99  }
100  case SUMO_TAG_RESTRICTION: {
101  bool ok = true;
102  const SUMOVehicleClass svc = getVehicleClassID(attrs.get<std::string>(SUMO_ATTR_VCLASS, myCurrentTypeID.c_str(), ok));
103  const double speed = attrs.get<double>(SUMO_ATTR_SPEED, myCurrentTypeID.c_str(), ok);
104  if (ok) {
106  }
107  break;
108  }
109  default:
110  break;
111  }
112 }
113 
114 
115 
116 /****************************************************************************/
117 
SUMOVehicleClass
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
Definition: SUMOVehicleClass.h:133
ToString.h
SUMOSAXAttributes::hasAttribute
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
getVehicleClassID
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
Definition: SUMOVehicleClass.cpp:200
SUMO_ATTR_DISALLOW
@ SUMO_ATTR_DISALLOW
Definition: SUMOXMLDefinitions.h:783
NIXMLTypesHandler.h
NIXMLTypesHandler::NIXMLTypesHandler
NIXMLTypesHandler(NBTypeCont &tc)
Constructor.
Definition: NIXMLTypesHandler.cpp:46
SUMOSAXHandler
SAX-handler base for SUMO-files.
Definition: SUMOSAXHandler.h:41
SUMOSAXAttributes::get
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
Definition: SUMOSAXAttributes.h:492
MsgHandler.h
SUMO_ATTR_NUMLANES
@ SUMO_ATTR_NUMLANES
Definition: SUMOXMLDefinitions.h:383
SUMOSAXHandler.h
NBTypeCont::insert
void insert(const std::string &id, int numLanes, double maxSpeed, int prio, SVCPermissions permissions, double width, bool oneWayIsDefault, double sidewalkWidth, double bikeLaneWidth, double widthResolution, double maxWidth, double minWidth)
Adds a type into the list.
Definition: NBTypeCont.cpp:53
SUMO_ATTR_MAXWIDTH
@ SUMO_ATTR_MAXWIDTH
Definition: SUMOXMLDefinitions.h:388
NBTypeCont::getMaxWidth
double getMaxWidth(const std::string &type) const
Returns the maximum edge/lane widths of the given type.
Definition: NBTypeCont.cpp:205
SUMO_ATTR_SPEED
@ SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:384
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
SUMO_ATTR_DISCARD
@ SUMO_ATTR_DISCARD
Definition: SUMOXMLDefinitions.h:717
SUMO_ATTR_WIDTHRESOLUTION
@ SUMO_ATTR_WIDTHRESOLUTION
Definition: SUMOXMLDefinitions.h:387
NBTypeCont::knows
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:71
NBTypeCont::markAsToDiscard
bool markAsToDiscard(const std::string &id)
Marks a type as to be discarded.
Definition: NBTypeCont.cpp:77
NBTypeCont::getWidthResolution
double getWidthResolution(const std::string &type) const
Returns the resolution for interpreting edge/lane widths of the given type.
Definition: NBTypeCont.cpp:200
parseVehicleClasses
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
Definition: SUMOVehicleClass.cpp:222
SUMO_ATTR_MINWIDTH
@ SUMO_ATTR_MINWIDTH
Definition: SUMOXMLDefinitions.h:389
NBTypeCont::getIsOneWay
bool getIsOneWay(const std::string &type) const
Returns whether edges are one-way per default for the given type.
Definition: NBTypeCont.cpp:189
SUMO_TAG_TYPE
@ SUMO_TAG_TYPE
type
Definition: SUMOXMLDefinitions.h:210
SVCPermissions
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
Definition: SUMOVehicleClass.h:218
NBTypeCont::getSpeed
double getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:177
NBTypeCont.h
SUMO_ATTR_WIDTH
@ SUMO_ATTR_WIDTH
Definition: SUMOXMLDefinitions.h:386
SUMOVehicleClass.h
NBTypeCont::getPriority
int getPriority(const std::string &type) const
Returns the priority for the given type.
Definition: NBTypeCont.cpp:183
SUMOSAXAttributes::getOpt
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
Definition: SUMOSAXAttributes.h:518
SUMO_ATTR_ONEWAY
@ SUMO_ATTR_ONEWAY
Definition: SUMOXMLDefinitions.h:385
NIXMLTypesHandler::~NIXMLTypesHandler
~NIXMLTypesHandler()
Destructor.
Definition: NIXMLTypesHandler.cpp:51
NIXMLTypesHandler::myCurrentTypeID
std::string myCurrentTypeID
The currently parsed type.
Definition: NIXMLTypesHandler.h:81
SUMO_TAG_RESTRICTION
@ SUMO_TAG_RESTRICTION
begin/end of the description of an edge restriction
Definition: SUMOXMLDefinitions.h:61
NIXMLTypesHandler::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag; Parses edge type information.
Definition: NIXMLTypesHandler.cpp:55
StringUtils.h
SUMO_ATTR_PRIORITY
@ SUMO_ATTR_PRIORITY
Definition: SUMOXMLDefinitions.h:382
SUMO_ATTR_SIDEWALKWIDTH
@ SUMO_ATTR_SIDEWALKWIDTH
Definition: SUMOXMLDefinitions.h:390
NBTypeCont::getPermissions
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:221
NBTypeCont
A storage for available types of edges.
Definition: NBTypeCont.h:54
SUMO_ATTR_BIKELANEWIDTH
@ SUMO_ATTR_BIKELANEWIDTH
Definition: SUMOXMLDefinitions.h:391
NBTypeCont::markAsSet
bool markAsSet(const std::string &id, const SumoXMLAttr attr)
Marks an attribute of a type as set.
Definition: NBTypeCont.cpp:88
NBTypeCont::getWidth
double getWidth(const std::string &type) const
Returns the lane width for the given type [m].
Definition: NBTypeCont.cpp:227
NBTypeCont::getNumLanes
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
Definition: NBTypeCont.cpp:171
SUMO_ATTR_ALLOW
@ SUMO_ATTR_ALLOW
Definition: SUMOXMLDefinitions.h:782
SUMO_ATTR_VCLASS
@ SUMO_ATTR_VCLASS
Definition: SUMOXMLDefinitions.h:450
NIXMLTypesHandler::myTypeCont
NBTypeCont & myTypeCont
The type container to fill.
Definition: NIXMLTypesHandler.h:78
NBTypeCont::addRestriction
bool addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction to a type.
Definition: NBTypeCont.cpp:99
config.h
NBTypeCont::getSidewalkWidth
double getSidewalkWidth(const std::string &type) const
Returns the lane width for a sidewalk to be added [m].
Definition: NBTypeCont.cpp:233
NBTypeCont::getMinWidth
double getMinWidth(const std::string &type) const
Returns the minimum edge/lane widths of the given type.
Definition: NBTypeCont.cpp:210
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:372
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
NBTypeCont::getBikeLaneWidth
double getBikeLaneWidth(const std::string &type) const
Returns the lane width for a bike lane to be added [m].
Definition: NBTypeCont.cpp:239
SUMOXMLDefinitions.h
NBEdge.h