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