|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A container for districts 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 <iostream> 00032 #include <utils/common/MsgHandler.h> 00033 #include <utils/common/ToString.h> 00034 #include <utils/iodevices/OutputDevice.h> 00035 #include "NBDistrict.h" 00036 #include "NBDistrictCont.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 NBDistrictCont::NBDistrictCont() throw() {} 00047 00048 00049 NBDistrictCont::~NBDistrictCont() throw() { 00050 for (DistrictCont::iterator i=myDistricts.begin(); i!=myDistricts.end(); i++) { 00051 delete((*i).second); 00052 } 00053 myDistricts.clear(); 00054 } 00055 00056 00057 bool 00058 NBDistrictCont::insert(NBDistrict* const district) throw() { 00059 DistrictCont::const_iterator i = myDistricts.find(district->getID()); 00060 if (i!=myDistricts.end()) { 00061 return false; 00062 } 00063 myDistricts.insert(DistrictCont::value_type(district->getID(), district)); 00064 return true; 00065 } 00066 00067 00068 NBDistrict* 00069 NBDistrictCont::retrieve(const std::string& id) const throw() { 00070 DistrictCont::const_iterator i = myDistricts.find(id); 00071 if (i==myDistricts.end()) { 00072 return 0; 00073 } 00074 return (*i).second; 00075 } 00076 00077 00078 size_t 00079 NBDistrictCont::size() const throw() { 00080 return myDistricts.size(); 00081 } 00082 00083 00084 bool 00085 NBDistrictCont::addSource(const std::string& dist, NBEdge* const source, 00086 SUMOReal weight) throw() { 00087 NBDistrict* o = retrieve(dist); 00088 if (o==0) { 00089 return false; 00090 } 00091 return o->addSource(source, weight); 00092 } 00093 00094 00095 bool 00096 NBDistrictCont::addSink(const std::string& dist, NBEdge* const destination, 00097 SUMOReal weight) throw() { 00098 NBDistrict* o = retrieve(dist); 00099 if (o==0) { 00100 return false; 00101 } 00102 return o->addSink(destination, weight); 00103 } 00104 00105 00106 void 00107 NBDistrictCont::removeFromSinksAndSources(NBEdge* const e) throw() { 00108 for (DistrictCont::iterator i=myDistricts.begin(); i!=myDistricts.end(); i++) { 00109 (*i).second->removeFromSinksAndSources(e); 00110 } 00111 } 00112 00113 00114 00115 /****************************************************************************/ 00116