Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/handlers/CommonHandler.h
169678 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 CommonHandler.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Dec 2024
17
///
18
// Collection of functions used in handlers
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <utils/xml/CommonXMLStructure.h>
24
#include <utils/xml/SUMOSAXHandler.h>
25
26
// ===========================================================================
27
// class definitions
28
// ===========================================================================
29
/**
30
* @class CommonHandler
31
* @brief The XML-Handler for network loading
32
*
33
* The SAX2-handler responsible for parsing networks and routes to load.
34
* This is an extension of the MSRouteHandler as routes and vehicles may also
35
* be loaded from network descriptions.
36
*/
37
class CommonHandler {
38
39
public:
40
/**@brief Constructor
41
* @param[in] filename Name of the parsed file
42
*/
43
CommonHandler(const std::string& filename);
44
45
/// @brief Destructor
46
virtual ~CommonHandler();
47
48
/// @brief force overwritte elements (used if we're reloading elements)
49
void forceOverwriteElements();
50
51
/// @brief force remain elements (used if we're reloading elements)
52
void forceRemainElements();
53
54
/// @brief abort loading
55
void abortLoading();
56
57
/// @brief get flag for mark if a element wasn't created
58
bool isErrorCreatingElement() const;
59
60
/// @brief force overwritte elements (used if we're reloading elements)
61
bool isForceOverwriteElements() const;
62
63
/// @brief force remain elements (used if we're reloading elements)
64
bool isForceRemainElements() const;
65
66
/// @brief abort loading
67
bool isAbortLoading() const;
68
69
protected:
70
/// @brief filename
71
const std::string myFilename;
72
73
/// @brief common XML Structure
74
CommonXMLStructure myCommonXMLStructure;
75
76
/// @brief flag for mark if a element wasn't created
77
bool myErrorCreatingElement = false;
78
79
/// @brief overwrite elements
80
bool myOverwriteElements = false;
81
82
/// @brief remain elements
83
bool myRemainElements = false;
84
85
/// @brief abort loading
86
bool myAbortLoading = false;
87
88
/// @brief parse generic parameters
89
void parseParameters(const SUMOSAXAttributes& attrs);
90
91
/// @brief get embedded route from children
92
CommonXMLStructure::SumoBaseObject* getEmbeddedRoute(const CommonXMLStructure::SumoBaseObject* sumoBaseObject) const;
93
94
/// @name check functions
95
/// @{
96
97
/// @brief check parsed parents
98
void checkParsedParent(const SumoXMLTag currentTag, const std::vector<SumoXMLTag>& parentTags, bool& ok);
99
100
/// @brief check list of IDs
101
bool checkListOfVehicleTypes(const SumoXMLTag tag, const std::string& id, const std::vector<std::string>& vTypeIDs);
102
103
/// @brief check if the given object is within a distribution (VType or routes)
104
bool checkWithinDistribution(CommonXMLStructure::SumoBaseObject* obj);
105
106
/// @brief check vehicle parents
107
bool checkVehicleParents(CommonXMLStructure::SumoBaseObject* obj);
108
109
/// @brief check person plan parents
110
bool checkPersonPlanParents(CommonXMLStructure::SumoBaseObject* obj);
111
112
/// @brief check container plan parents
113
bool checkContainerPlanParents(CommonXMLStructure::SumoBaseObject* obj);
114
115
/// @brief check stop parents
116
bool checkStopParents(CommonXMLStructure::SumoBaseObject* obj);
117
118
/// @brief check if the given int value is NOT negative
119
bool checkNegative(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const int value, const bool canBeZero);
120
121
/// @brief check if the given double value is NOT negative
122
bool checkNegative(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const double value, const bool canBeZero);
123
124
/// @brief check if the given SUMOTime value is NOT negative
125
bool checkNegative(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const SUMOTime value, const bool canBeZero);
126
127
/// @brief check if the given filename is valid
128
bool checkFileName(const SumoXMLTag tag, const std::string& id, const SumoXMLAttr attribute, const std::string& value);
129
130
/// @brief check if the given additional ID is valid
131
bool checkValidAdditionalID(const SumoXMLTag tag, const std::string& value);
132
133
/// @brief check if the given detector ID is valid
134
bool checkValidDetectorID(const SumoXMLTag tag, const std::string& value);
135
136
/// @brief check if the given demand elmement ID is valid
137
bool checkValidDemandElementID(const SumoXMLTag tag, const std::string& value);
138
139
/// @}
140
141
/// @brief write warning overwritting element
142
void writeWarningOverwriting(const SumoXMLTag tag, const std::string& id);
143
144
/// @brief write warning duplicated element
145
bool writeWarningDuplicated(const SumoXMLTag tag, const std::string& id, const SumoXMLTag checkedTag);
146
147
/// @brief write error and enable error creating element
148
bool writeError(const std::string& error);
149
150
/// @brief write error "invalid position"
151
bool writeErrorInvalidPosition(const SumoXMLTag tag, const std::string& id);
152
153
/// @brief write error "empty edges"
154
bool writeErrorEmptyEdges(const SumoXMLTag tag, const std::string& id);
155
156
/// @brief write error "invalid list of lanes"
157
bool writeErrorInvalidLanes(const SumoXMLTag tag, const std::string& id);
158
159
/// @brief write error "invalid parent element" giving ids of current and parent element
160
bool writeErrorInvalidParent(const SumoXMLTag tag, const std::string& id, const SumoXMLTag parentTag, const std::string& parentID);
161
162
/// @brief write error "invalid parent element" giving only the id of parent element
163
bool writeErrorInvalidParent(const SumoXMLTag tag, const SumoXMLTag parentTag, const std::string& parentID);
164
165
/// @brief write error "invalid parent element" without giving IDs
166
bool writeErrorInvalidParent(const SumoXMLTag tag, const SumoXMLTag parentTag);
167
168
private:
169
/// @brief invalidate default onstructor
170
CommonHandler() = delete;
171
172
/// @brief invalidate copy constructor
173
CommonHandler(const CommonHandler& s) = delete;
174
175
/// @brief invalidate assignment operator
176
CommonHandler& operator=(const CommonHandler& s) = delete;
177
};
178
179