Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netbuild/NBDistrictCont.h
169667 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file NBDistrictCont.h
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @date Sept 2002
18
///
19
// A container for districts
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <map>
25
#include <string>
26
27
28
// ===========================================================================
29
// class declarations
30
// ===========================================================================
31
class NBDistrict;
32
class NBEdge;
33
class NBNodeCont;
34
class OutputDevice;
35
36
37
// ===========================================================================
38
// class definitions
39
// ===========================================================================
40
/**
41
* @class NBDistrictCont
42
* @brief A container for districts
43
*
44
* A simple storage for district instances. Allows addition an retrieval of
45
* districts, filling them with sources/sinks, and some other methods which
46
* operate at all stored districts.
47
*
48
* @see NBDistrict
49
*/
50
class NBDistrictCont {
51
public:
52
/// @brief Constructor
53
NBDistrictCont();
54
55
56
/// @brief Destructor
57
~NBDistrictCont();
58
59
60
/** @brief Adds a district to the dictionary
61
*
62
* @param[in] district The district to add
63
* @return false if the districts already was in the dictionary
64
*/
65
bool insert(NBDistrict* const district);
66
67
68
/** @brief Returns the districts with the given id
69
*
70
* @param[in] id The id of the district to retrieve
71
* @return The district with the given id if there was one having it, 0 otherwise
72
*/
73
NBDistrict* retrieve(const std::string& id) const;
74
75
76
/** @brief Returns the pointer to the begin of the stored districts
77
* @return The iterator to the beginning of stored edges
78
*/
79
std::map<std::string, NBDistrict*>::const_iterator begin() const {
80
return myDistricts.begin();
81
}
82
83
84
/** @brief Returns the pointer to the end of the stored districts
85
* @return The iterator to the end of stored edges
86
*/
87
std::map<std::string, NBDistrict*>::const_iterator end() const {
88
return myDistricts.end();
89
}
90
91
92
/** @brief Returns the number of districts inside the container */
93
int size() const;
94
95
96
/** @brief Adds a source to the named district
97
*
98
* At first, the district is tried to be retrieved. If this fails, false is
99
* returned. Otherwise the retrieved districts NBDistrict::addSource-method
100
* is called.
101
*
102
* @see NBDistrict::addSource
103
* @param[in] dist The id of the district to add the source to
104
* @param[in] source An edge that shall be used as source
105
* @param[in] weight An optional weight of the source
106
* @return Whether the source could be added (the district exists and the suorce was not added to it before)
107
*/
108
bool addSource(const std::string& dist, NBEdge* const source,
109
double weight);
110
111
112
/** @brief Adds a sink to the named district
113
*
114
* At first, the district is tried to be retrieved. If this fails, false is
115
* returned. Otherwise the retrieved districts NBDistrict::addSink-method
116
* is called.
117
*
118
* @see NBDistrict::addSink
119
* @param[in] dist The id of the district to add the sink to
120
* @param[in] source An edge that shall be used as sink
121
* @param[in] weight An optional weight of the source
122
* @return Whether the source could be added (the district exists and the suorce was not added to it before)
123
*/
124
bool addSink(const std::string& dist, NBEdge* const destination,
125
double weight);
126
127
128
/** @brief Removes the given edge from the lists of sources and sinks in all stored districts
129
*
130
* This method simply goes through all stored districts and calls their method
131
* NBDistrict::removeFromSinksAndSources.
132
*
133
* @see NBDistrict::removeFromSinksAndSources
134
* @param[in] e The edge to remove from sinks/sources
135
*/
136
void removeFromSinksAndSources(NBEdge* const e);
137
138
139
private:
140
/// @brief The type of the dictionary where a node may be found by her id
141
typedef std::map<std::string, NBDistrict*> DistrictCont;
142
143
/// @brief The instance of the dictionary
144
DistrictCont myDistricts;
145
146
147
private:
148
/** invalid copy constructor */
149
NBDistrictCont(const NBDistrictCont& s);
150
151
/** invalid assignment operator */
152
NBDistrictCont& operator=(const NBDistrictCont& s);
153
154
155
};
156
157