SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBTypeCont.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A storage for the available types of an edge
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 <map>
36 #include <iostream>
38 #include <utils/common/ToString.h>
39 #include "NBTypeCont.h"
40 
41 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 void
50 NBTypeCont::setDefaults(int defaultNoLanes,
51  SUMOReal defaultSpeed,
52  int defaultPriority) {
53  myDefaultType.noLanes = defaultNoLanes;
54  myDefaultType.speed = defaultSpeed;
55  myDefaultType.priority = defaultPriority;
56 }
57 
58 
59 bool
60 NBTypeCont::insert(const std::string& id, int noLanes, SUMOReal maxSpeed, int prio,
61  SUMOReal width, SUMOVehicleClass vClass, bool oneWayIsDefault) {
62  SVCPermissions permissions = (vClass == SVC_UNKNOWN ? SVCFreeForAll : vClass);
63  return insert(id, noLanes, maxSpeed, prio, permissions, width, oneWayIsDefault);
64 }
65 
66 
67 bool
68 NBTypeCont::insert(const std::string& id, int noLanes, SUMOReal maxSpeed, int prio,
69  SVCPermissions permissions, SUMOReal width, bool oneWayIsDefault) {
70  TypesCont::iterator i = myTypes.find(id);
71  if (i != myTypes.end()) {
72  return false;
73  }
74  myTypes[id] = TypeDefinition(noLanes, maxSpeed, prio, width, permissions, oneWayIsDefault);
75  return true;
76 }
77 
78 
79 bool
80 NBTypeCont::knows(const std::string& type) const {
81  return myTypes.find(type) != myTypes.end();
82 }
83 
84 
85 bool
86 NBTypeCont::markAsToDiscard(const std::string& id) {
87  TypesCont::iterator i = myTypes.find(id);
88  if (i == myTypes.end()) {
89  return false;
90  }
91  (*i).second.discard = true;
92  return true;
93 }
94 
95 
96 // ------------ Type-dependant Retrieval methods
97 int
98 NBTypeCont::getNumLanes(const std::string& type) const {
99  return getType(type).noLanes;
100 }
101 
102 
103 SUMOReal
104 NBTypeCont::getSpeed(const std::string& type) const {
105  return getType(type).speed;
106 }
107 
108 
109 int
110 NBTypeCont::getPriority(const std::string& type) const {
111  return getType(type).priority;
112 }
113 
114 
115 bool
116 NBTypeCont::getIsOneWay(const std::string& type) const {
117  return getType(type).oneWay;
118 }
119 
120 
121 bool
122 NBTypeCont::getShallBeDiscarded(const std::string& type) const {
123  return getType(type).discard;
124 }
125 
126 
128 NBTypeCont::getPermissions(const std::string& type) const {
129  return getType(type).permissions;
130 }
131 
132 
133 SUMOReal
134 NBTypeCont::getWidth(const std::string& type) const {
135  return getType(type).width;
136 }
137 
138 
140 NBTypeCont::getType(const std::string& name) const {
141  TypesCont::const_iterator i = myTypes.find(name);
142  if (i == myTypes.end()) {
143  return myDefaultType;
144  }
145  return (*i).second;
146 }
147 
148 /****************************************************************************/
149 
int noLanes
The number of lanes of an edge.
Definition: NBTypeCont.h:208
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
const TypeDefinition & getType(const std::string &name) const
Retrieve the name or the default type.
Definition: NBTypeCont.cpp:140
SUMOReal width
The width of lanes of edges of this type [m].
Definition: NBTypeCont.h:220
int SVCPermissions
bool insert(const std::string &id, int noLanes, SUMOReal maxSpeed, int prio, SUMOReal width, SUMOVehicleClass vClasses=SVC_UNKNOWN, bool oneWayIsDefault=false)
Adds a type into the list. This is a simplified convenience form of insert, if only one allowed vehic...
Definition: NBTypeCont.cpp:60
bool getIsOneWay(const std::string &type) const
Returns whether edges are one-way per default for the given type.
Definition: NBTypeCont.cpp:116
SUMOReal speed
The maximal velocity on an edge in m/s.
Definition: NBTypeCont.h:210
bool oneWay
Whether one-way traffic is mostly common for this type (mostly unused)
Definition: NBTypeCont.h:216
SUMOReal getWidth(const std::string &type) const
Returns the lane width for the given type [m/s].
Definition: NBTypeCont.cpp:134
SUMOReal getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:104
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
Definition: NBTypeCont.cpp:98
void setDefaults(int defaultNoLanes, SUMOReal defaultSpeed, int defaultPriority)
Sets the default values.
Definition: NBTypeCont.cpp:50
int getPriority(const std::string &type) const
Returns the priority for the given type.
Definition: NBTypeCont.cpp:110
bool knows(const std::string &type) const
Returns whether the named type is in the container.
Definition: NBTypeCont.cpp:80
const SVCPermissions SVCFreeForAll
bool markAsToDiscard(const std::string &id)
Marks a type as to be discarded.
Definition: NBTypeCont.cpp:86
TypeDefinition myDefaultType
The default type.
Definition: NBTypeCont.h:236
bool getShallBeDiscarded(const std::string &type) const
Returns the information whether edges of this type shall be discarded.
Definition: NBTypeCont.cpp:122
#define SUMOReal
Definition: config.h:215
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:128
int priority
The priority of an edge.
Definition: NBTypeCont.h:212
SVCPermissions permissions
List of vehicle types that are allowed on this edge.
Definition: NBTypeCont.h:214
TypesCont myTypes
The container of types.
Definition: NBTypeCont.h:242
bool discard
Whether edges of this type shall be discarded.
Definition: NBTypeCont.h:218