SUMO - Simulation of Urban MObility
NBDistrictCont.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A container for districts
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
26 #include <iostream>
28 #include <utils/common/ToString.h>
30 #include "NBDistrict.h"
31 #include "NBDistrictCont.h"
32 
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
38 
39 
41  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
42  delete((*i).second);
43  }
44  myDistricts.clear();
45 }
46 
47 
48 bool
50  DistrictCont::const_iterator i = myDistricts.find(district->getID());
51  if (i != myDistricts.end()) {
52  return false;
53  }
54  myDistricts.insert(DistrictCont::value_type(district->getID(), district));
55  return true;
56 }
57 
58 
60 NBDistrictCont::retrieve(const std::string& id) const {
61  DistrictCont::const_iterator i = myDistricts.find(id);
62  if (i == myDistricts.end()) {
63  return nullptr;
64  }
65  return (*i).second;
66 }
67 
68 
69 int
71  return (int)myDistricts.size();
72 }
73 
74 
75 bool
76 NBDistrictCont::addSource(const std::string& dist, NBEdge* const source,
77  double weight) {
78  NBDistrict* o = retrieve(dist);
79  if (o == nullptr) {
80  return false;
81  }
82  return o->addSource(source, weight);
83 }
84 
85 
86 bool
87 NBDistrictCont::addSink(const std::string& dist, NBEdge* const destination,
88  double weight) {
89  NBDistrict* o = retrieve(dist);
90  if (o == nullptr) {
91  return false;
92  }
93  return o->addSink(destination, weight);
94 }
95 
96 
97 void
99  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
100  (*i).second->removeFromSinksAndSources(e);
101  }
102 }
103 
104 
105 
106 /****************************************************************************/
107 
NBDistrict * retrieve(const std::string &id) const
Returns the districts with the given id.
The representation of a single edge during network building.
Definition: NBEdge.h:65
const std::string & getID() const
Returns the id.
Definition: Named.h:78
DistrictCont myDistricts
The instance of the dictionary.
A class representing a single district.
Definition: NBDistrict.h:65
bool addSource(const std::string &dist, NBEdge *const source, double weight)
Adds a source to the named district.
~NBDistrictCont()
Destructor.
bool addSink(const std::string &dist, NBEdge *const destination, double weight)
Adds a sink to the named district.
int size() const
Returns the number of districts inside the container.
bool addSink(NBEdge *const sink, double weight)
Adds a sink.
Definition: NBDistrict.cpp:83
bool insert(NBDistrict *const district)
Adds a district to the dictionary.
NBDistrictCont()
Constructor.
void removeFromSinksAndSources(NBEdge *const e)
Removes the given edge from the lists of sources and sinks in all stored districts.
bool addSource(NBEdge *const source, double weight)
Adds a source.
Definition: NBDistrict.cpp:70