SUMO - Simulation of Urban MObility

NBTypeCont.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00010 // A storage for the available types of an edge
00011 /****************************************************************************/
00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00014 /****************************************************************************/
00015 //
00016 //   This file is part of SUMO.
00017 //   SUMO is free software: you can redistribute it and/or modify
00018 //   it under the terms of the GNU General Public License as published by
00019 //   the Free Software Foundation, either version 3 of the License, or
00020 //   (at your option) any later version.
00021 //
00022 /****************************************************************************/
00023 
00024 
00025 // ===========================================================================
00026 // included modules
00027 // ===========================================================================
00028 #ifdef _MSC_VER
00029 #include <windows_config.h>
00030 #else
00031 #include <config.h>
00032 #endif
00033 
00034 #include <string>
00035 #include <map>
00036 #include <iostream>
00037 #include <utils/common/MsgHandler.h>
00038 #include <utils/common/ToString.h>
00039 #include "NBTypeCont.h"
00040 #include "NBJunctionTypesMatrix.h"
00041 
00042 #ifdef CHECK_MEMORY_LEAKS
00043 #include <foreign/nvwa/debug_new.h>
00044 #endif // CHECK_MEMORY_LEAKS
00045 
00046 
00047 // ===========================================================================
00048 // method definitions
00049 // ===========================================================================
00050 void
00051 NBTypeCont::setDefaults(int defaultNoLanes,
00052                         SUMOReal defaultSpeed,
00053                         int defaultPriority) {
00054     myDefaultType.noLanes = defaultNoLanes;
00055     myDefaultType.speed = defaultSpeed;
00056     myDefaultType.priority = defaultPriority;
00057 }
00058 
00059 
00060 bool
00061 NBTypeCont::insert(const std::string& id, int noLanes, SUMOReal maxSpeed, int prio,
00062                    SUMOReal width, SUMOVehicleClass vClass, bool oneWayIsDefault) {
00063     SUMOVehicleClasses allow;
00064     if (vClass != SVC_UNKNOWN) {
00065         allow.insert(vClass);
00066     }
00067     return insert(id, noLanes, maxSpeed, prio, allow, SUMOVehicleClasses(), width, oneWayIsDefault);
00068 }
00069 
00070 
00071 bool
00072 NBTypeCont::insert(const std::string& id, int noLanes, SUMOReal maxSpeed, int prio,
00073                    const SUMOVehicleClasses& allow, const SUMOVehicleClasses& disallow,
00074                    SUMOReal width, bool oneWayIsDefault) {
00075     TypesCont::iterator i = myTypes.find(id);
00076     if (i != myTypes.end()) {
00077         return false;
00078     }
00079     NBTypeCont::TypeDefinition td(noLanes, maxSpeed, prio, width);
00080     td.allowed.insert(allow.begin(), allow.end());
00081     td.notAllowed.insert(disallow.begin(), disallow.end());
00082     td.oneWay = oneWayIsDefault;
00083     myTypes[id] = td;
00084     return true;
00085 }
00086 
00087 
00088 bool
00089 NBTypeCont::knows(const std::string& type) const {
00090     return myTypes.find(type) != myTypes.end();
00091 }
00092 
00093 
00094 SumoXMLNodeType
00095 NBTypeCont::getJunctionType(SUMOReal speed1, SUMOReal speed2) const {
00096     return myJunctionTypes.getType(speed1, speed2);
00097 }
00098 
00099 
00100 bool
00101 NBTypeCont::markAsToDiscard(const std::string& id) {
00102     TypesCont::iterator i = myTypes.find(id);
00103     if (i == myTypes.end()) {
00104         return false;
00105     }
00106     (*i).second.discard = true;
00107     return true;
00108 }
00109 
00110 
00111 // ------------ Type-dependant Retrieval methods
00112 int
00113 NBTypeCont::getNumLanes(const std::string& type) const {
00114     return getType(type).noLanes;
00115 }
00116 
00117 
00118 SUMOReal
00119 NBTypeCont::getSpeed(const std::string& type) const {
00120     return getType(type).speed;
00121 }
00122 
00123 
00124 int
00125 NBTypeCont::getPriority(const std::string& type) const {
00126     return getType(type).priority;
00127 }
00128 
00129 
00130 bool
00131 NBTypeCont::getIsOneWay(const std::string& type) const {
00132     return getType(type).oneWay;
00133 }
00134 
00135 
00136 bool
00137 NBTypeCont::getShallBeDiscarded(const std::string& type) const {
00138     return getType(type).discard;
00139 }
00140 
00141 
00142 const SUMOVehicleClasses&
00143 NBTypeCont::getAllowedClasses(const std::string& type) const {
00144     return getType(type).allowed;
00145 }
00146 
00147 
00148 const SUMOVehicleClasses&
00149 NBTypeCont::getDisallowedClasses(const std::string& type) const {
00150     return getType(type).notAllowed;
00151 }
00152 
00153 
00154 SUMOReal
00155 NBTypeCont::getWidth(const std::string& type) const {
00156     return getType(type).width;
00157 }
00158 
00159 
00160 const NBTypeCont::TypeDefinition&
00161 NBTypeCont::getType(const std::string& name) const {
00162     TypesCont::const_iterator i = myTypes.find(name);
00163     if (i == myTypes.end()) {
00164         return myDefaultType;
00165     }
00166     return (*i).second;
00167 }
00168 
00169 /****************************************************************************/
00170 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines