NBDistrictCont.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A container for districts
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 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()) return false;
00061     myDistricts.insert(DistrictCont::value_type(district->getID(), district));
00062     return true;
00063 }
00064 
00065 
00066 NBDistrict *
00067 NBDistrictCont::retrieve(const std::string &id) const throw() {
00068     DistrictCont::const_iterator i = myDistricts.find(id);
00069     if (i==myDistricts.end()) return 0;
00070     return (*i).second;
00071 }
00072 
00073 
00074 void
00075 NBDistrictCont::writeXML(OutputDevice &into) const throw() {
00076     for (DistrictCont::const_iterator i=myDistricts.begin(); i!=myDistricts.end(); i++) {
00077         (*i).second->writeXML(into);
00078     }
00079     into << "\n";
00080 }
00081 
00082 
00083 size_t
00084 NBDistrictCont::size() const throw() {
00085     return myDistricts.size();
00086 }
00087 
00088 
00089 bool
00090 NBDistrictCont::addSource(const std::string &dist, NBEdge * const source,
00091                           SUMOReal weight) throw() {
00092     NBDistrict *o = retrieve(dist);
00093     if (o==0) {
00094         return false;
00095     }
00096     return o->addSource(source, weight);
00097 }
00098 
00099 
00100 bool
00101 NBDistrictCont::addSink(const std::string &dist, NBEdge * const destination,
00102                         SUMOReal weight) throw() {
00103     NBDistrict *o = retrieve(dist);
00104     if (o==0) {
00105         return false;
00106     }
00107     return o->addSink(destination, weight);
00108 }
00109 
00110 
00111 void
00112 NBDistrictCont::removeFromSinksAndSources(NBEdge * const e) throw() {
00113     for (DistrictCont::iterator i=myDistricts.begin(); i!=myDistricts.end(); i++) {
00114         (*i).second->removeFromSinksAndSources(e);
00115     }
00116 }
00117 
00118 
00119 void
00120 NBDistrictCont::reshiftDistrictPositions(SUMOReal xoff, SUMOReal yoff) throw() {
00121     for (DistrictCont::iterator i=myDistricts.begin(); i!=myDistricts.end(); i++) {
00122         (*i).second->reshiftPosition(xoff, yoff);
00123     }
00124 }
00125 
00126 
00127 /****************************************************************************/
00128 

Generated on Wed May 5 00:06:32 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6