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-2017 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 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
45 
46 
48  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
49  delete((*i).second);
50  }
51  myDistricts.clear();
52 }
53 
54 
55 bool
57  DistrictCont::const_iterator i = myDistricts.find(district->getID());
58  if (i != myDistricts.end()) {
59  return false;
60  }
61  myDistricts.insert(DistrictCont::value_type(district->getID(), district));
62  return true;
63 }
64 
65 
67 NBDistrictCont::retrieve(const std::string& id) const {
68  DistrictCont::const_iterator i = myDistricts.find(id);
69  if (i == myDistricts.end()) {
70  return 0;
71  }
72  return (*i).second;
73 }
74 
75 
76 int
78  return (int)myDistricts.size();
79 }
80 
81 
82 bool
83 NBDistrictCont::addSource(const std::string& dist, NBEdge* const source,
84  double weight) {
85  NBDistrict* o = retrieve(dist);
86  if (o == 0) {
87  return false;
88  }
89  return o->addSource(source, weight);
90 }
91 
92 
93 bool
94 NBDistrictCont::addSink(const std::string& dist, NBEdge* const destination,
95  double weight) {
96  NBDistrict* o = retrieve(dist);
97  if (o == 0) {
98  return false;
99  }
100  return o->addSink(destination, weight);
101 }
102 
103 
104 void
106  for (DistrictCont::iterator i = myDistricts.begin(); i != myDistricts.end(); i++) {
107  (*i).second->removeFromSinksAndSources(e);
108  }
109 }
110 
111 
112 
113 /****************************************************************************/
114 
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:71
const std::string & getID() const
Returns the id.
Definition: Named.h:66
DistrictCont myDistricts
The instance of the dictionary.
A class representing a single district.
Definition: NBDistrict.h:72
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:90
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:77