SUMO - Simulation of Urban MObility
|
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 00041 #ifdef CHECK_MEMORY_LEAKS 00042 #include <foreign/nvwa/debug_new.h> 00043 #endif // CHECK_MEMORY_LEAKS 00044 00045 00046 // =========================================================================== 00047 // method definitions 00048 // =========================================================================== 00049 void 00050 NBTypeCont::setDefaults(int defaultNoLanes, 00051 SUMOReal defaultSpeed, 00052 int defaultPriority) { 00053 myDefaultType.noLanes = defaultNoLanes; 00054 myDefaultType.speed = defaultSpeed; 00055 myDefaultType.priority = defaultPriority; 00056 } 00057 00058 00059 bool 00060 NBTypeCont::insert(const std::string& id, int noLanes, SUMOReal maxSpeed, int prio, 00061 SUMOReal width, SUMOVehicleClass vClass, bool oneWayIsDefault) { 00062 SVCPermissions permissions = (vClass == SVC_UNKNOWN ? SVCFreeForAll : vClass); 00063 return insert(id, noLanes, maxSpeed, prio, permissions, width, oneWayIsDefault); 00064 } 00065 00066 00067 bool 00068 NBTypeCont::insert(const std::string& id, int noLanes, SUMOReal maxSpeed, int prio, 00069 SVCPermissions permissions, SUMOReal width, bool oneWayIsDefault) { 00070 TypesCont::iterator i = myTypes.find(id); 00071 if (i != myTypes.end()) { 00072 return false; 00073 } 00074 myTypes[id] = TypeDefinition(noLanes, maxSpeed, prio, width, permissions, oneWayIsDefault); 00075 return true; 00076 } 00077 00078 00079 bool 00080 NBTypeCont::knows(const std::string& type) const { 00081 return myTypes.find(type) != myTypes.end(); 00082 } 00083 00084 00085 bool 00086 NBTypeCont::markAsToDiscard(const std::string& id) { 00087 TypesCont::iterator i = myTypes.find(id); 00088 if (i == myTypes.end()) { 00089 return false; 00090 } 00091 (*i).second.discard = true; 00092 return true; 00093 } 00094 00095 00096 // ------------ Type-dependant Retrieval methods 00097 int 00098 NBTypeCont::getNumLanes(const std::string& type) const { 00099 return getType(type).noLanes; 00100 } 00101 00102 00103 SUMOReal 00104 NBTypeCont::getSpeed(const std::string& type) const { 00105 return getType(type).speed; 00106 } 00107 00108 00109 int 00110 NBTypeCont::getPriority(const std::string& type) const { 00111 return getType(type).priority; 00112 } 00113 00114 00115 bool 00116 NBTypeCont::getIsOneWay(const std::string& type) const { 00117 return getType(type).oneWay; 00118 } 00119 00120 00121 bool 00122 NBTypeCont::getShallBeDiscarded(const std::string& type) const { 00123 return getType(type).discard; 00124 } 00125 00126 00127 SVCPermissions 00128 NBTypeCont::getPermissions(const std::string& type) const { 00129 return getType(type).permissions; 00130 } 00131 00132 00133 SUMOReal 00134 NBTypeCont::getWidth(const std::string& type) const { 00135 return getType(type).width; 00136 } 00137 00138 00139 const NBTypeCont::TypeDefinition& 00140 NBTypeCont::getType(const std::string& name) const { 00141 TypesCont::const_iterator i = myTypes.find(name); 00142 if (i == myTypes.end()) { 00143 return myDefaultType; 00144 } 00145 return (*i).second; 00146 } 00147 00148 /****************************************************************************/ 00149