SUMO - Simulation of Urban MObility
NBDistrictCont.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A container for districts
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <iostream>
35 #include <utils/common/ToString.h>
37 #include "NBDistrict.h"
38 #include "NBDistrictCont.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
49 
50 
52  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
53  delete((*i).second);
54  }
55  myDistricts.clear();
56 }
57 
58 
59 bool
61  DistrictCont::const_iterator i = myDistricts.find(district->getID());
62  if (i != myDistricts.end()) {
63  return false;
64  }
65  myDistricts.insert(DistrictCont::value_type(district->getID(), district));
66  return true;
67 }
68 
69 
71 NBDistrictCont::retrieve(const std::string& id) const {
72  DistrictCont::const_iterator i = myDistricts.find(id);
73  if (i == myDistricts.end()) {
74  return 0;
75  }
76  return (*i).second;
77 }
78 
79 
80 size_t
82  return myDistricts.size();
83 }
84 
85 
86 bool
87 NBDistrictCont::addSource(const std::string& dist, NBEdge* const source,
88  SUMOReal weight) {
89  NBDistrict* o = retrieve(dist);
90  if (o == 0) {
91  return false;
92  }
93  return o->addSource(source, weight);
94 }
95 
96 
97 bool
98 NBDistrictCont::addSink(const std::string& dist, NBEdge* const destination,
99  SUMOReal weight) {
100  NBDistrict* o = retrieve(dist);
101  if (o == 0) {
102  return false;
103  }
104  return o->addSink(destination, weight);
105 }
106 
107 
108 void
110  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
111  (*i).second->removeFromSinksAndSources(e);
112  }
113 }
114 
115 
116 
117 /****************************************************************************/
118 
size_t size() const
Returns the number of districts inside the container.
bool addSource(NBEdge *const source, SUMOReal weight)
Adds a source.
Definition: NBDistrict.cpp:74
The representation of a single edge during network building.
Definition: NBEdge.h:71
bool addSink(const std::string &dist, NBEdge *const destination, SUMOReal weight)
Adds a sink to the named district.
DistrictCont myDistricts
The instance of the dictionary.
A class representing a single district.
Definition: NBDistrict.h:72
const std::string & getID() const
Returns the id.
Definition: Named.h:60
~NBDistrictCont()
Destructor.
bool insert(NBDistrict *const district)
Adds a district to the dictionary.
bool addSink(NBEdge *const sink, SUMOReal weight)
Adds a sink.
Definition: NBDistrict.cpp:87
bool addSource(const std::string &dist, NBEdge *const source, SUMOReal weight)
Adds a source to the named district.
#define SUMOReal
Definition: config.h:218
NBDistrictCont()
Constructor.
void removeFromSinksAndSources(NBEdge *const e)
Removes the given edge from the lists of sources and sinks in all stored districts.
NBDistrict * retrieve(const std::string &id) const
Returns the districts with the given id.