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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // A container for districts
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <string>
32 #include <iostream>
34 #include <utils/common/ToString.h>
36 #include "NBDistrict.h"
37 #include "NBDistrictCont.h"
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
44 
45 
47  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
48  delete((*i).second);
49  }
50  myDistricts.clear();
51 }
52 
53 
54 bool
56  DistrictCont::const_iterator i = myDistricts.find(district->getID());
57  if (i != myDistricts.end()) {
58  return false;
59  }
60  myDistricts.insert(DistrictCont::value_type(district->getID(), district));
61  return true;
62 }
63 
64 
66 NBDistrictCont::retrieve(const std::string& id) const {
67  DistrictCont::const_iterator i = myDistricts.find(id);
68  if (i == myDistricts.end()) {
69  return 0;
70  }
71  return (*i).second;
72 }
73 
74 
75 int
77  return (int)myDistricts.size();
78 }
79 
80 
81 bool
82 NBDistrictCont::addSource(const std::string& dist, NBEdge* const source,
83  double weight) {
84  NBDistrict* o = retrieve(dist);
85  if (o == 0) {
86  return false;
87  }
88  return o->addSource(source, weight);
89 }
90 
91 
92 bool
93 NBDistrictCont::addSink(const std::string& dist, NBEdge* const destination,
94  double weight) {
95  NBDistrict* o = retrieve(dist);
96  if (o == 0) {
97  return false;
98  }
99  return o->addSink(destination, weight);
100 }
101 
102 
103 void
105  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
106  (*i).second->removeFromSinksAndSources(e);
107  }
108 }
109 
110 
111 
112 /****************************************************************************/
113 
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:70
const std::string & getID() const
Returns the id.
Definition: Named.h:65
DistrictCont myDistricts
The instance of the dictionary.
A class representing a single district.
Definition: NBDistrict.h:71
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:89
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:76