Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/options/OptionsLoader.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 OptionsLoader.h
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @date Mon, 17 Dec 2001
18
///
19
// A SAX-Handler for loading options
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <xercesc/sax/HandlerBase.hpp>
25
#include <xercesc/sax/AttributeList.hpp>
26
#include <xercesc/sax/SAXParseException.hpp>
27
#include <xercesc/sax/SAXException.hpp>
28
#include <string>
29
30
31
// ===========================================================================
32
// class declarations
33
// ===========================================================================
34
35
class OptionsCont;
36
37
// ===========================================================================
38
// class definitions
39
// ===========================================================================
40
/**
41
* @class OptionsLoader
42
* @brief A SAX-Handler for loading options
43
*/
44
class OptionsLoader : public XERCES_CPP_NAMESPACE::HandlerBase {
45
46
public:
47
/// @brief Constructor for default option container
48
OptionsLoader(OptionsCont& customOptions, const bool routeOnly = false);
49
50
/// @brief destructor
51
~OptionsLoader();
52
53
/// @name Handlers for the SAX DocumentHandler interface
54
/// @{
55
56
/** @brief Called on the occurrence of the beginning of a tag
57
*
58
* Sets the name of the last item
59
*/
60
virtual void startElement(const XMLCh* const name,
61
XERCES_CPP_NAMESPACE::AttributeList& attributes);
62
63
/** @brief Called on the occurrence of character data
64
*
65
* If this occurs inside a single tag it sets the option named
66
* by the tag to the value given by the character data.
67
* This is considered deprecated in favor of attributes.
68
* @todo Describe better
69
*/
70
void characters(const XMLCh* const chars, const XERCES3_SIZE_t length);
71
72
/** @brief Called on the end of an element
73
*
74
* Resets the element name
75
*/
76
void endElement(const XMLCh* const name);
77
78
/// @}
79
80
/// @name Handlers for the SAX ErrorHandler interface
81
/// @{
82
83
/** @brief Called on an XML-warning
84
*
85
* The warning is reported to the warning-instance of MsgHandler
86
*/
87
void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
88
89
/** @brief Called on an XML-error
90
*
91
* The warning is reported to the error-instance of MsgHandler
92
*/
93
void error(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
94
95
/** @brief Called on an XML-fatal error
96
*
97
* The warning is reported to the error-instance of MsgHandler
98
*/
99
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
100
/// @}
101
102
/// @brief Returns the information whether an error occurred
103
bool errorOccurred() const;
104
105
/// @brief Returns the last item read
106
const std::string& getItem() const {
107
return myItem;
108
}
109
110
private:
111
/// @brief The information whether only the root element should be parsed
112
const bool myRootOnly;
113
114
/// @brief The information whether an error occurred
115
bool myError = false;
116
117
/// @brief The options to fill
118
OptionsCont& myOptions;
119
120
/// @brief The name of the currently parsed option
121
std::string myItem;
122
123
/// @brief The currently read characters string
124
std::string myValue;
125
126
/// @brief Whether a value attribute was read
127
bool myFoundValue;
128
129
/** @brief Tries to set the named option to the given value
130
*
131
* Also evaluates whether it is a boolean or a filename option and
132
* does the relevant checks / modifications.
133
*
134
* @param[in] key The name of the option to set
135
* @param[in] value The new value for the option
136
*/
137
void setValue(const std::string& key, const std::string& value);
138
139
/** @brief Tries to set the named option to the given value
140
*
141
* Checks the item whether it was default before setting it.
142
* Returns the information whether the item was set before (was not a default value)
143
*
144
* @param[in] name The name of the option to set
145
* @param[in] value The new value for the option
146
* @return Whether the option could be set
147
*/
148
bool setSecure(OptionsCont& options, const std::string& name, const std::string& value) const;
149
150
/// @brief invalid copy constructor
151
OptionsLoader(const OptionsLoader& s) = delete;
152
153
/// @brief invalid assignment operator
154
OptionsLoader& operator=(const OptionsLoader& s) = delete;
155
};
156
157