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