Eclipse 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.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 // A container for districts
20 /****************************************************************************/
21 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
26 #include <utils/common/ToString.h>
28 #include "NBDistrict.h"
29 #include "NBDistrictCont.h"
30 
31 
32 // ===========================================================================
33 // method definitions
34 // ===========================================================================
36 
37 
39  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
40  delete ((*i).second);
41  }
42  myDistricts.clear();
43 }
44 
45 
46 bool
48  DistrictCont::const_iterator i = myDistricts.find(district->getID());
49  if (i != myDistricts.end()) {
50  return false;
51  }
52  myDistricts.insert(DistrictCont::value_type(district->getID(), district));
53  return true;
54 }
55 
56 
58 NBDistrictCont::retrieve(const std::string& id) const {
59  DistrictCont::const_iterator i = myDistricts.find(id);
60  if (i == myDistricts.end()) {
61  return nullptr;
62  }
63  return (*i).second;
64 }
65 
66 
67 int
69  return (int)myDistricts.size();
70 }
71 
72 
73 bool
74 NBDistrictCont::addSource(const std::string& dist, NBEdge* const source,
75  double weight) {
76  NBDistrict* o = retrieve(dist);
77  if (o == nullptr) {
78  return false;
79  }
80  return o->addSource(source, weight);
81 }
82 
83 
84 bool
85 NBDistrictCont::addSink(const std::string& dist, NBEdge* const destination,
86  double weight) {
87  NBDistrict* o = retrieve(dist);
88  if (o == nullptr) {
89  return false;
90  }
91  return o->addSink(destination, weight);
92 }
93 
94 
95 void
97  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
98  (*i).second->removeFromSinksAndSources(e);
99  }
100 }
101 
102 
103 /****************************************************************************/
NBDistrict * retrieve(const std::string &id) const
Returns the districts with the given id.
NBDistrictCont()
Constructor.
DistrictCont myDistricts
The instance of the dictionary.
bool addSink(const std::string &dist, NBEdge *const destination, double weight)
Adds a sink to the named district.
bool insert(NBDistrict *const district)
Adds a district to the dictionary.
bool addSource(const std::string &dist, NBEdge *const source, double weight)
Adds a source to the named district.
void removeFromSinksAndSources(NBEdge *const e)
Removes the given edge from the lists of sources and sinks in all stored districts.
int size() const
Returns the number of districts inside the container.
~NBDistrictCont()
Destructor.
A class representing a single district.
Definition: NBDistrict.h:62
bool addSink(NBEdge *const sink, double weight)
Adds a sink.
Definition: NBDistrict.cpp:81
bool addSource(NBEdge *const source, double weight)
Adds a source.
Definition: NBDistrict.cpp:68
The representation of a single edge during network building.
Definition: NBEdge.h:92
const std::string & getID() const
Returns the id.
Definition: Named.h:74