Eclipse SUMO - Simulation of Urban MObility
OptionsLoader.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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/****************************************************************************/
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// ===========================================================================
34class OptionsCont;
35
36
37// ===========================================================================
38// class definitions
39// ===========================================================================
44class OptionsLoader : public XERCES_CPP_NAMESPACE::HandlerBase {
45public:
48 OptionsLoader(const bool routeOnly = false);
49
50
53
54
55
56
59
64 virtual void startElement(const XMLCh* const name,
65 XERCES_CPP_NAMESPACE::AttributeList& attributes);
66
67
75 void characters(const XMLCh* const chars, const XERCES3_SIZE_t length);
76
77
82 void endElement(const XMLCh* const name);
84
85
86
87
90
95 void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
96
97
102 void error(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
103
104
109 void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
111
112
113
115 bool errorOccurred() const;
116
118 const std::string& getItem() const {
119 return myItem;
120 }
121
122
123private:
132 void setValue(const std::string& key, const std::string& value);
133
134
144 bool setSecure(const std::string& name, const std::string& value) const;
145
146
147private:
150
151
154
155
156private:
159
162
165
167 std::string myItem;
168
170 std::string myValue;
171
172};
A storage for options typed value containers)
Definition: OptionsCont.h:89
A SAX-Handler for loading options.
Definition: OptionsLoader.h:44
OptionsLoader(const bool routeOnly=false)
Constructor.
bool setSecure(const std::string &name, const std::string &value) const
Tries to set the named option to the given value.
virtual void startElement(const XMLCh *const name, XERCES_CPP_NAMESPACE::AttributeList &attributes)
Called on the occurence of the beginning of a tag.
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Called on an XML-fatal error.
bool myError
The information whether an error occurred.
const std::string & getItem() const
Returns the last item read.
void characters(const XMLCh *const chars, const XERCES3_SIZE_t length)
Called on the occurence of character data.
bool errorOccurred() const
Returns the information whether an error occurred.
void warning(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Called on an XML-warning.
std::string myValue
The currently read characters string.
void endElement(const XMLCh *const name)
Called on the end of an element.
OptionsLoader & operator=(const OptionsLoader &s)
bool myRootOnly
The information whether only the root element should be parsed.
OptionsLoader(const OptionsLoader &s)
OptionsCont & myOptions
The options to fill.
std::string myItem
The name of the currently parsed option.
void setValue(const std::string &key, const std::string &value)
Tries to set the named option to the given value.
void error(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Called on an XML-error.