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 /****************************************************************************/
18 // Importer for edge type information stored in XML
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <iostream>
29 #include <xercesc/sax/HandlerBase.hpp>
30 #include <xercesc/sax/AttributeList.hpp>
31 #include <xercesc/sax/SAXParseException.hpp>
32 #include <xercesc/sax/SAXException.hpp>
37 #include <utils/common/ToString.h>
39 #include <netbuild/NBEdge.h>
40 #include <netbuild/NBTypeCont.h>
41 #include "NIXMLTypesHandler.h"
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
48  : SUMOSAXHandler("xml-types - file"),
49  myTypeCont(tc) {}
50 
51 
53 
54 
55 void
57  const SUMOSAXAttributes& attrs) {
58  switch (element) {
59  case SUMO_TAG_TYPE: {
60  bool ok = true;
61  // get the id, report a warning if not given or empty...
62  myCurrentTypeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
63  const char* const id = myCurrentTypeID.c_str();
64  const std::string defType = myTypeCont.knows(myCurrentTypeID) ? myCurrentTypeID : "";
65  const int priority = attrs.getOpt<int>(SUMO_ATTR_PRIORITY, id, ok, myTypeCont.getPriority(defType));
66  const int numLanes = attrs.getOpt<int>(SUMO_ATTR_NUMLANES, id, ok, myTypeCont.getNumLanes(defType));
67  const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, id, ok, myTypeCont.getSpeed(defType));
68  const std::string allowS = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, id, ok, "");
69  const std::string disallowS = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, id, ok, "");
70  const bool oneway = attrs.getOpt<bool>(SUMO_ATTR_ONEWAY, id, ok, myTypeCont.getIsOneWay(defType));
71  const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id, ok, false);
72  const double width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, id, ok, myTypeCont.getWidth(defType));
73  const double maxWidth = attrs.getOpt<double>(SUMO_ATTR_MAXWIDTH, id, ok, myTypeCont.getMaxWidth(defType));
74  const double minWidth = attrs.getOpt<double>(SUMO_ATTR_MINWIDTH, id, ok, myTypeCont.getMinWidth(defType));
75  const double widthResolution = attrs.getOpt<double>(SUMO_ATTR_WIDTHRESOLUTION, id, ok, myTypeCont.getWidthResolution(defType));
76  const double sidewalkWidth = attrs.getOpt<double>(SUMO_ATTR_SIDEWALKWIDTH, id, ok, myTypeCont.getSidewalkWidth(defType));
77  const double bikeLaneWidth = attrs.getOpt<double>(SUMO_ATTR_BIKELANEWIDTH, id, ok, myTypeCont.getBikeLaneWidth(defType));
78  if (!ok) {
79  return;
80  }
81  // build the type
82  SVCPermissions permissions = myTypeCont.getPermissions(defType);
83  if (allowS != "" || disallowS != "") {
84  permissions = parseVehicleClasses(allowS, disallowS);
85  }
86  myTypeCont.insert(myCurrentTypeID, numLanes, speed, priority, permissions, width, oneway, sidewalkWidth, bikeLaneWidth, widthResolution, maxWidth, minWidth);
87  if (discard) {
89  }
93  };
94  for (int i = 0; i < 10; i++) {
95  if (attrs.hasAttribute(myAttrs[i])) {
97  }
98  }
99  break;
100  }
101  case SUMO_TAG_RESTRICTION: {
102  bool ok = true;
103  const SUMOVehicleClass svc = getVehicleClassID(attrs.get<std::string>(SUMO_ATTR_VCLASS, myCurrentTypeID.c_str(), ok));
104  const double speed = attrs.get<double>(SUMO_ATTR_SPEED, myCurrentTypeID.c_str(), ok);
105  if (ok) {
107  }
108  break;
109  }
110  default:
111  break;
112  }
113 }
114 
115 
116 
117 /****************************************************************************/
118 
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
double getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:178
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
std::string myCurrentTypeID
The currently parsed type.
int getPriority(const std::string &type) const
Returns the priority for the given type.
Definition: NBTypeCont.cpp:184
bool markAsSet(const std::string &id, const SumoXMLAttr attr)
Marks an attribute of a type as set.
Definition: NBTypeCont.cpp:89
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
Definition: NBTypeCont.cpp:172
begin/end of the description of an edge restriction
SAX-handler base for SUMO-files.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag; Parses edge type information.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
double getWidth(const std::string &type) const
Returns the lane width for the given type [m].
Definition: NBTypeCont.cpp:228
NBTypeCont & myTypeCont
The type container to fill.
bool addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction to a type.
Definition: NBTypeCont.cpp:100
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:72
double getBikeLaneWidth(const std::string &type) const
Returns the lane width for a bike lane to be added [m].
Definition: NBTypeCont.cpp:240
double getSidewalkWidth(const std::string &type) const
Returns the lane width for a sidewalk to be added [m].
Definition: NBTypeCont.cpp:234
Encapsulated SAX-Attributes.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
double getMinWidth(const std::string &type) const
Returns the minimum edge/lane widths of the given type.
Definition: NBTypeCont.cpp:211
~NIXMLTypesHandler()
Destructor.
NIXMLTypesHandler(NBTypeCont &tc)
Constructor.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
bool markAsToDiscard(const std::string &id)
Marks a type as to be discarded.
Definition: NBTypeCont.cpp:78
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.
double getMaxWidth(const std::string &type) const
Returns the maximum edge/lane widths of the given type.
Definition: NBTypeCont.cpp:206
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:54
bool getIsOneWay(const std::string &type) const
Returns whether edges are one-way per default for the given type.
Definition: NBTypeCont.cpp:190
double getWidthResolution(const std::string &type) const
Returns the resolution for interpreting edge/lane widths of the given type.
Definition: NBTypeCont.cpp:201
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:222
A storage for available types of edges.
Definition: NBTypeCont.h:55