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 /****************************************************************************/ 10 /// @file NBTypeCont.h 11 /// @author Daniel Krajzewicz 12 /// @author Jakob Erdmann 13 /// @author Sascha Krieg 14 /// @author Michael Behrisch 15 /// @author Walter Bamberger 16 /// @date Tue, 20 Nov 2001 17 /// @version $Id$ 18 /// 19 // A storage for available types of edges 20 /****************************************************************************/ 21 #ifndef NBTypeCont_h 22 #define NBTypeCont_h 23 24 25 // =========================================================================== 26 // included modules 27 // =========================================================================== 28 #include <config.h> 29 30 #include <string> 31 #include <map> 32 #include <utils/common/SUMOVehicleClass.h> 33 #include <netbuild/NBEdge.h> 34 35 36 // =========================================================================== 37 // class declarations 38 // =========================================================================== 39 class OutputDevice; 40 41 42 // =========================================================================== 43 // class definitions 44 // =========================================================================== 45 /** 46 * @class NBTypeCont 47 * @brief A storage for available types of edges 48 * 49 * NBTypeCont stores properties of edge-types of edges. Additionally, a default 50 * type is stored which is used if no type information is given. 51 * 52 * This structure also contains a structure for determining node types using edge 53 * speeds. 54 */ 55 class NBTypeCont { 56 public: 57 /// @brief Constructor NBTypeCont()58 NBTypeCont() {} 59 60 61 /// @brief Destructor ~NBTypeCont()62 ~NBTypeCont() {} 63 64 65 /** @brief Sets the default values 66 * @param[in] defaultNumLanes The default number of lanes an edge has 67 * @param[in] defaultLaneWidth The default width of lanes 68 * @param[in] defaultSpeed The default speed allowed on an edge 69 * @param[in] defaultPriority The default priority of an edge 70 * @param[in] defaultPermissions The default permissions of an edge 71 */ 72 void setDefaults(int defaultNumLanes, double defaultLaneWidth, 73 double defaultSpeed, int defaultPriority, 74 SVCPermissions defaultPermissions); 75 76 77 /** @brief Adds a type into the list 78 * @param[in] id The id of the type 79 * @param[in] numLanes The number of lanes an edge of this type has 80 * @param[in] maxSpeed The speed allowed on an edge of this type 81 * @param[in] prio The priority of an edge of this type 82 * @param[in] permissions The encoding of vehicle classes allowed on an edge of this type 83 * @param[in] width The width of lanes of edgesof this type 84 * @param[in] oneWayIsDefault Whether edges of this type are one-way per default 85 * @return Whether the type could be added (no type with the same id existed) 86 */ 87 void insert(const std::string& id, int numLanes, 88 double maxSpeed, int prio, 89 SVCPermissions permissions, 90 double width, bool oneWayIsDefault, 91 double sidewalkWidth, 92 double bikeLaneWidth); 93 94 /** @brief Returns the number of known types 95 * @return The number of known edge types (excluding the default) 96 */ size()97 int size() const { 98 return (int) myTypes.size(); 99 } 100 101 102 /** @brief Returns whether the named type is in the container 103 * @return Whether the named type is known 104 */ 105 bool knows(const std::string& type) const; 106 107 108 /** @brief Marks a type as to be discarded 109 * @param[in] id The id of the type 110 */ 111 bool markAsToDiscard(const std::string& id); 112 113 /** @brief Marks an attribute of a type as set 114 * @param[in] id The id of the type 115 * @param[in] attr The id of the attribute 116 */ 117 bool markAsSet(const std::string& id, const SumoXMLAttr attr); 118 119 /** @brief Adds a restriction to a type 120 * @param[in] id The id of the type 121 * @param[in] svc The vehicle class the restriction refers to 122 * @param[in] speed The restricted speed 123 */ 124 bool addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed); 125 126 /** @brief Copy restrictions to a type 127 * @param[in] fromId The id of the source type 128 * @param[in] toId The id of the destination type 129 */ 130 bool copyRestrictionsAndAttrs(const std::string& fromId, const std::string& toId); 131 132 /// @brief writes all types a s XML 133 void writeTypes(OutputDevice& into) const; 134 135 /// @name Type-dependant Retrieval methods 136 /// @{ 137 138 /** @brief Returns the number of lanes for the given type 139 * 140 * If the named type is not known, the default is returned 141 * @param[in] type The name of the type to return the lane number for 142 * @return The number of lanes an edge of this type has 143 */ 144 int getNumLanes(const std::string& type) const; 145 146 147 /** @brief Returns the maximal velocity for the given type [m/s] 148 * 149 * If the named type is not known, the default is returned 150 * @param[in] type The name of the type to return the speed for 151 * @return The allowed speed on edges of this type 152 */ 153 double getSpeed(const std::string& type) const; 154 155 156 /** @brief Returns the priority for the given type 157 * 158 * If the named type is not known, the default is returned 159 * @param[in] type The name of the type to return the priority for 160 * @return The priority of edges of this type 161 */ 162 int getPriority(const std::string& type) const; 163 164 165 /** @brief Returns whether edges are one-way per default for the given type 166 * 167 * If the named type is not known, the default is returned 168 * @param[in] type The name of the type to return the one-way information for 169 * @return Whether edges of this type are one-way per default 170 * @todo There is no default for one-way!? 171 */ 172 bool getIsOneWay(const std::string& type) const; 173 174 175 /** @brief Returns the information whether edges of this type shall be discarded. 176 * 177 * Returns false if the type is not known. 178 * @param[in] type The id of the type 179 * @return Whether edges of this type shall be discarded. 180 */ 181 bool getShallBeDiscarded(const std::string& type) const; 182 183 184 /** @brief Returns whether an attribute of a type was set 185 * @param[in] type The id of the type 186 * @param[in] attr The id of the attribute 187 * @return Whether the attribute was set 188 */ 189 bool wasSet(const std::string& type, const SumoXMLAttr attr) const; 190 191 192 /** @brief Returns allowed vehicle classes for the given type 193 * 194 * If the named type is not known, the default is returned 195 * @param[in] type The name of the type to return the list of allowed vehicles classes for 196 * @return List of vehicles class which may use edges of the given type 197 */ 198 SVCPermissions getPermissions(const std::string& type) const; 199 200 201 /** @brief Returns the lane width for the given type [m] 202 * 203 * If the named type is not known, the default is returned 204 * @param[in] type The name of the type to return the width for 205 * @return The width of lanes of edges of this type 206 */ 207 double getWidth(const std::string& type) const; 208 209 210 /** @brief Returns the lane width for a sidewalk to be added [m] 211 * 212 * If the named type is not known, the default is returned 213 * @param[in] type The name of the type to return the width for 214 * @return The width of lanes of edges of this type 215 */ 216 double getSidewalkWidth(const std::string& type) const; 217 218 219 /** @brief Returns the lane width for a bike lane to be added [m] 220 * 221 * If the named type is not known, the default is returned 222 * @param[in] type The name of the type to return the width for 223 * @return The width of lanes of edges of this type 224 */ 225 double getBikeLaneWidth(const std::string& type) const; 226 /// @} 227 228 229 private: 230 struct TypeDefinition { 231 /// @brief Constructor TypeDefinitionTypeDefinition232 TypeDefinition() : 233 numLanes(1), speed((double) 13.89), priority(-1), 234 permissions(SVC_UNSPECIFIED), 235 oneWay(true), discard(false), 236 width(NBEdge::UNSPECIFIED_WIDTH), 237 sidewalkWidth(NBEdge::UNSPECIFIED_WIDTH), 238 bikeLaneWidth(NBEdge::UNSPECIFIED_WIDTH) { 239 } 240 241 /// @brief Constructor TypeDefinitionTypeDefinition242 TypeDefinition(int _numLanes, double _speed, int _priority, 243 double _width, SVCPermissions _permissions, bool _oneWay, 244 double _sideWalkWidth, 245 double _bikeLaneWidth) : 246 numLanes(_numLanes), speed(_speed), priority(_priority), 247 permissions(_permissions), 248 oneWay(_oneWay), discard(false), width(_width), 249 sidewalkWidth(_sideWalkWidth), 250 bikeLaneWidth(_bikeLaneWidth) { 251 } 252 253 /// @brief The number of lanes of an edge 254 int numLanes; 255 /// @brief The maximal velocity on an edge in m/s 256 double speed; 257 /// @brief The priority of an edge 258 int priority; 259 /// @brief List of vehicle types that are allowed on this edge 260 SVCPermissions permissions; 261 /// @brief Whether one-way traffic is mostly common for this type (mostly unused) 262 bool oneWay; 263 /// @brief Whether edges of this type shall be discarded 264 bool discard; 265 /// @brief The width of lanes of edges of this type [m] 266 double width; 267 /* @brief The width of the sidewalk that should be added as an additional lane 268 * a value of NBEdge::UNSPECIFIED_WIDTH indicates that no sidewalk should be added */ 269 double sidewalkWidth; 270 /* @brief The width of the bike lane that should be added as an additional lane 271 * a value of NBEdge::UNSPECIFIED_WIDTH indicates that no bike lane should be added */ 272 double bikeLaneWidth; 273 /// @brief The vehicle class specific speed restrictions 274 std::map<SUMOVehicleClass, double> restrictions; 275 /// @brief The attributes which have been set 276 std::set<SumoXMLAttr> attrs; 277 278 }; 279 280 281 /** @brief Retrieve the name or the default type 282 * 283 * If no name is given, the default type is returned 284 * @param[in] name The name of the type to retrieve 285 * @return The named type 286 */ 287 const TypeDefinition& getType(const std::string& name) const; 288 289 290 private: 291 /// @brief The default type 292 TypeDefinition myDefaultType; 293 294 /// @brief A container of types, accessed by the string id 295 typedef std::map<std::string, TypeDefinition> TypesCont; 296 297 /// @brief The container of types 298 TypesCont myTypes; 299 300 301 private: 302 /** @brief invalid copy constructor */ 303 NBTypeCont(const NBTypeCont& s); 304 305 /** @brief invalid assignment operator */ 306 NBTypeCont& operator=(const NBTypeCont& s); 307 308 309 }; 310 311 312 #endif 313 314 /****************************************************************************/ 315 316