Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/od/ODDistrictHandler.h
169668 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 ODDistrictHandler.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Sept 2002
19
///
20
// An XML-Handler for districts
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <string>
26
#include <utility>
27
#include <utils/xml/SUMOSAXHandler.h>
28
29
30
// ===========================================================================
31
// class declarations
32
// ===========================================================================
33
class ODDistrict;
34
class ODDistrictCont;
35
36
37
// ===========================================================================
38
// class definitions
39
// ===========================================================================
40
/**
41
* @class ODDistrictHandler
42
* @brief An XML-Handler for districts
43
*
44
* This SUMOSAXHandler parses districts and their sinks and sources from
45
* and stores them into a the district container given at initialisation.
46
*/
47
class ODDistrictHandler : public SUMOSAXHandler {
48
public:
49
/** @brief Constructor
50
*
51
* Saves the given district containe in order to fill it.
52
* @param[in] cont The container of districts to fill
53
* @param[in] file The file that will be processed
54
*/
55
ODDistrictHandler(ODDistrictCont& cont, const std::string& file);
56
57
58
/// @brief Destructor
59
~ODDistrictHandler();
60
61
62
protected:
63
/// @name inherited from GenericSAXHandler
64
//@{
65
66
/** @brief Called when an opening-tag occurs
67
*
68
* Processes district elements via openDistrict, their sinks (via
69
* addSink) and sources (via addSource).
70
*
71
* @param[in] element The enum of the currently opened element
72
* @param[in] attrs Attributes of the currently opened element
73
* @exception ProcessError If an error within the parsed file occurs
74
* @see GenericSAXHandler::myStartElement
75
*/
76
void myStartElement(int element,
77
const SUMOSAXAttributes& attrs);
78
79
80
/** @brief Called when a closing tag occurs
81
*
82
* Processes district elements via closeDistrict.
83
*
84
* @param[in] element ID of the currently opened element
85
* @exception ProcessError If an error within the parsed file occurs
86
*/
87
void myEndElement(int element);
88
//@}
89
90
91
private:
92
/** @brief Begins the parsing of a district
93
*
94
* Tries to retrieve the id of a district, adds a message to the
95
* error handler if this fails. Otherwise builds a new district
96
* with this id at myCurrentDistrict.
97
*
98
* @param[in] attrs Attributes of the currently opened element
99
*/
100
void openDistrict(const SUMOSAXAttributes& attrs);
101
102
103
/** @brief Adds a read source to the current district
104
*
105
* Tries to get the id and the weight of the currently parsed source
106
* from the attributes using getValues. If the retrieval could be
107
* done without errors (weight>=0), the so retrieved weighted source
108
* is added to myCurrentDistrict using addSource. (getValues checks
109
* whether myCurrentDistrict is valid)
110
*
111
* @param[in] attrs Attributes of the currently opened element
112
* @todo Checking whether myCurrentDistrict is valid through getValues is not quite nice
113
*/
114
void addSource(const SUMOSAXAttributes& attrs);
115
116
117
/** @brief Adds a read sink to the current district
118
*
119
* Tries to get the id and the weight of the currently parsed sink
120
* from the attributes using getValues. If the retrieval could be
121
* done without errors (weight>=0), the so retrieved weighted sink
122
* is added to myCurrentDistrict using addSink. (getValues checks
123
* whether myCurrentDistrict is valid)
124
*
125
* @param[in] attrs Attributes of the currently opened element
126
* @todo Checking whether myCurrentDistrict is valid through getValues is not quite nice
127
*/
128
void addSink(const SUMOSAXAttributes& attrs);
129
130
131
/** @brief Closes the processing of the current district
132
*
133
* Adds myCurrentDistrict to myContainer.
134
*/
135
void closeDistrict();
136
137
138
/** @brief Returns the id and weight for a taz/tazSink/tazSource
139
*
140
* Checks whether myCurrentDistrict (the currently processed
141
* district) is !=0; in this case, both the id and the weight
142
* are parsed. If one of them is missing or the weight is not numerical,
143
* an error is generated and reported to MsgHandler. The "type"-parameter
144
* is used in order to inform the user whether a source or a sink was
145
* processed. In the case of an error, the returned weight is -1.
146
*
147
* If no error occurs, the correct id and weight are returned.
148
*
149
* @param[in] attrs Attributes of the currently opened element
150
* @param[in] type The type of the currntly processed connection (sink/source)
151
* @return The id and the weight of a taz
152
*/
153
std::pair<std::string, double> parseTAZ(const SUMOSAXAttributes& attrs);
154
155
private:
156
/// The container to add read districts to
157
ODDistrictCont& myContainer;
158
159
/// The currently parsed district
160
ODDistrict* myCurrentDistrict;
161
162
163
private:
164
/// @brief invalidated copy constructor
165
ODDistrictHandler(const ODDistrictHandler& s);
166
167
/// @brief invalidated assignment operator
168
ODDistrictHandler& operator=(const ODDistrictHandler& s);
169
170
171
};
172
173