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.org/sumo
3 // Copyright (C) 2001-2019 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 /****************************************************************************/
15 // A container for districts
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <string>
25 #include <iostream>
27 #include <utils/common/ToString.h>
29 #include "NBDistrict.h"
30 #include "NBDistrictCont.h"
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
37 
38 
40  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
41  delete ((*i).second);
42  }
43  myDistricts.clear();
44 }
45 
46 
47 bool
49  DistrictCont::const_iterator i = myDistricts.find(district->getID());
50  if (i != myDistricts.end()) {
51  return false;
52  }
53  myDistricts.insert(DistrictCont::value_type(district->getID(), district));
54  return true;
55 }
56 
57 
59 NBDistrictCont::retrieve(const std::string& id) const {
60  DistrictCont::const_iterator i = myDistricts.find(id);
61  if (i == myDistricts.end()) {
62  return nullptr;
63  }
64  return (*i).second;
65 }
66 
67 
68 int
70  return (int)myDistricts.size();
71 }
72 
73 
74 bool
75 NBDistrictCont::addSource(const std::string& dist, NBEdge* const source,
76  double weight) {
77  NBDistrict* o = retrieve(dist);
78  if (o == nullptr) {
79  return false;
80  }
81  return o->addSource(source, weight);
82 }
83 
84 
85 bool
86 NBDistrictCont::addSink(const std::string& dist, NBEdge* const destination,
87  double weight) {
88  NBDistrict* o = retrieve(dist);
89  if (o == nullptr) {
90  return false;
91  }
92  return o->addSink(destination, weight);
93 }
94 
95 
96 void
98  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
99  (*i).second->removeFromSinksAndSources(e);
100  }
101 }
102 
103 
104 
105 /****************************************************************************/
106 
ToString.h
NBDistrictCont::~NBDistrictCont
~NBDistrictCont()
Destructor.
Definition: NBDistrictCont.cpp:39
MsgHandler.h
NBDistrictCont::retrieve
NBDistrict * retrieve(const std::string &id) const
Returns the districts with the given id.
Definition: NBDistrictCont.cpp:59
NBDistrict.h
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NBDistrictCont::addSource
bool addSource(const std::string &dist, NBEdge *const source, double weight)
Adds a source to the named district.
Definition: NBDistrictCont.cpp:75
OutputDevice.h
NBDistrictCont::myDistricts
DistrictCont myDistricts
The instance of the dictionary.
Definition: NBDistrictCont.h:146
NBDistrictCont.h
NBDistrictCont::insert
bool insert(NBDistrict *const district)
Adds a district to the dictionary.
Definition: NBDistrictCont.cpp:48
NBDistrict::addSink
bool addSink(NBEdge *const sink, double weight)
Adds a sink.
Definition: NBDistrict.cpp:82
NBDistrictCont::addSink
bool addSink(const std::string &dist, NBEdge *const destination, double weight)
Adds a sink to the named district.
Definition: NBDistrictCont.cpp:86
config.h
NBDistrictCont::removeFromSinksAndSources
void removeFromSinksAndSources(NBEdge *const e)
Removes the given edge from the lists of sources and sinks in all stored districts.
Definition: NBDistrictCont.cpp:97
NBDistrictCont::NBDistrictCont
NBDistrictCont()
Constructor.
Definition: NBDistrictCont.cpp:36
NBDistrict::addSource
bool addSource(NBEdge *const source, double weight)
Adds a source.
Definition: NBDistrict.cpp:69
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
NBDistrict
A class representing a single district.
Definition: NBDistrict.h:64
NBDistrictCont::size
int size() const
Returns the number of districts inside the container.
Definition: NBDistrictCont.cpp:69