SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
13 // Copyright (C) 2001-2014 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>
40 #include "NIXMLTypesHandler.h"
41 #include <netbuild/NBTypeCont.h>
46 #include <utils/common/ToString.h>
48 
49 #ifdef CHECK_MEMORY_LEAKS
50 #include <foreign/nvwa/debug_new.h>
51 #endif // CHECK_MEMORY_LEAKS
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
58  : SUMOSAXHandler("xml-types - file"),
59  myTypeCont(tc) {}
60 
61 
63 
64 
65 void
67  const SUMOSAXAttributes& attrs) {
68  if (element != SUMO_TAG_TYPE) {
69  return;
70  }
71  bool ok = true;
72  // get the id, report a warning if not given or empty...
73  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
74  int priority = attrs.getOpt<int>(SUMO_ATTR_PRIORITY, id.c_str(), ok, myTypeCont.getPriority(""));
75  int noLanes = myTypeCont.getNumLanes("");
76  noLanes = attrs.getOpt<int>(SUMO_ATTR_NUMLANES, id.c_str(), ok, noLanes);
77  SUMOReal speed = attrs.getOpt<SUMOReal>(SUMO_ATTR_SPEED, id.c_str(), ok, (SUMOReal) myTypeCont.getSpeed(""));
78  std::string allowS = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, id.c_str(), ok, "");
79  std::string disallowS = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, id.c_str(), ok, "");
80  bool oneway = attrs.getOpt<bool>(SUMO_ATTR_ONEWAY, id.c_str(), ok, false);
81  bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id.c_str(), ok, false);
82  SUMOReal width = attrs.getOpt<SUMOReal>(SUMO_ATTR_WIDTH, id.c_str(), ok, NBEdge::UNSPECIFIED_WIDTH);
83  SUMOReal sidewalkWidth = attrs.getOpt<SUMOReal>(SUMO_ATTR_SIDEWALKWIDTH, id.c_str(), ok, NBEdge::UNSPECIFIED_WIDTH);
84  if (!ok) {
85  return;
86  }
87  // build the type
88  SVCPermissions permissions = parseVehicleClasses(allowS, disallowS);
89  if (!myTypeCont.insert(id, noLanes, speed, priority, permissions, width, oneway, sidewalkWidth)) {
90  WRITE_ERROR("Duplicate type occured. ID='" + id + "'");
91  } else {
92  if (discard) {
94  }
95  }
96 }
97 
98 
99 
100 /****************************************************************************/
101 
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:201
SAX-handler base for SUMO-files.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag; Parses edge type information.
NBTypeCont & myTypeCont
The type container to fill.
SUMOReal getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:104
Encapsulated SAX-Attributes.
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
Definition: NBTypeCont.cpp:98
int getPriority(const std::string &type) const
Returns the priority for the given type.
Definition: NBTypeCont.cpp:110
~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 insert(const std::string &id, int noLanes, SUMOReal maxSpeed, int prio, SUMOReal width, SUMOVehicleClass vClasses=SVC_IGNORING, bool oneWayIsDefault=false, SUMOReal sidewalkWidth=NBEdge::UNSPECIFIED_WIDTH)
Adds a type into the list. This is a simplified convenience form of insert, if only one allowed vehic...
Definition: NBTypeCont.cpp:60
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
bool markAsToDiscard(const std::string &id)
Marks a type as to be discarded.
Definition: NBTypeCont.cpp:86
#define SUMOReal
Definition: config.h:215
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.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
A storage for available types of edges.
Definition: NBTypeCont.h:56