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