SUMO - Simulation of Urban MObility
NIXMLTypesHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Importer for edge type information stored in XML
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <iostream>
36 #include <xercesc/sax/HandlerBase.hpp>
37 #include <xercesc/sax/AttributeList.hpp>
38 #include <xercesc/sax/SAXParseException.hpp>
39 #include <xercesc/sax/SAXException.hpp>
44 #include <utils/common/ToString.h>
46 #include <netbuild/NBEdge.h>
47 #include <netbuild/NBTypeCont.h>
48 #include "NIXMLTypesHandler.h"
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
55  : SUMOSAXHandler("xml-types - file"),
56  myTypeCont(tc) {}
57 
58 
60 
61 
62 void
64  const SUMOSAXAttributes& attrs) {
65  switch (element) {
66  case SUMO_TAG_TYPE: {
67  bool ok = true;
68  // get the id, report a warning if not given or empty...
69  myCurrentTypeID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
70  const char* const id = myCurrentTypeID.c_str();
71  const std::string defType = myTypeCont.knows(myCurrentTypeID) ? myCurrentTypeID : "";
72  const int priority = attrs.getOpt<int>(SUMO_ATTR_PRIORITY, id, ok, myTypeCont.getPriority(defType));
73  const int numLanes = attrs.getOpt<int>(SUMO_ATTR_NUMLANES, id, ok, myTypeCont.getNumLanes(defType));
74  const double speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, id, ok, myTypeCont.getSpeed(defType));
75  const std::string allowS = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, id, ok, "");
76  const std::string disallowS = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, id, ok, "");
77  const bool oneway = attrs.getOpt<bool>(SUMO_ATTR_ONEWAY, id, ok, myTypeCont.getIsOneWay(defType));
78  const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id, ok, false);
79  const double width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, id, ok, myTypeCont.getWidth(defType));
80  const double sidewalkWidth = attrs.getOpt<double>(SUMO_ATTR_SIDEWALKWIDTH, id, ok, myTypeCont.getSidewalkWidth(defType));
81  const double bikeLaneWidth = attrs.getOpt<double>(SUMO_ATTR_BIKELANEWIDTH, id, ok, myTypeCont.getBikeLaneWidth(defType));
82  if (!ok) {
83  return;
84  }
85  // build the type
86  SVCPermissions permissions = myTypeCont.getPermissions(defType);
87  if (allowS != "" || disallowS != "") {
88  permissions = parseVehicleClasses(allowS, disallowS);
89  }
90  myTypeCont.insert(myCurrentTypeID, numLanes, speed, priority, permissions, width, oneway, sidewalkWidth, bikeLaneWidth);
91  if (discard) {
93  }
97  };
98  for (int i = 0; i < 10; i++) {
99  if (attrs.hasAttribute(myAttrs[i])) {
100  myTypeCont.markAsSet(myCurrentTypeID, myAttrs[i]);
101  }
102  }
103  break;
104  }
105  case SUMO_TAG_RESTRICTION: {
106  bool ok = true;
107  const SUMOVehicleClass svc = getVehicleClassID(attrs.get<std::string>(SUMO_ATTR_VCLASS, myCurrentTypeID.c_str(), ok));
108  const double speed = attrs.get<double>(SUMO_ATTR_SPEED, myCurrentTypeID.c_str(), ok);
109  if (ok) {
111  }
112  break;
113  }
114  default:
115  break;
116  }
117 }
118 
119 
120 
121 /****************************************************************************/
122 
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
void insert(const std::string &id, int numLanes, double maxSpeed, int prio, SVCPermissions permissions, double width, bool oneWayIsDefault, double sidewalkWidth, double bikeLaneWidth)
Adds a type into the list.
Definition: NBTypeCont.cpp:61
double getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:181
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:187
bool markAsSet(const std::string &id, const SumoXMLAttr attr)
Marks an attribute of a type as set.
Definition: NBTypeCont.cpp:92
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:175
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:217
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:103
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:75
double getBikeLaneWidth(const std::string &type) const
Returns the lane width for a bike lane to be added [m].
Definition: NBTypeCont.cpp:229
double getSidewalkWidth(const std::string &type) const
Returns the lane width for a sidewalk to be added [m].
Definition: NBTypeCont.cpp:223
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.
~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:81
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.
bool getIsOneWay(const std::string &type) const
Returns whether edges are one-way per default for the given type.
Definition: NBTypeCont.cpp:193
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:211
A storage for available types of edges.
Definition: NBTypeCont.h:62