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.dev/sumo
3 // Copyright (C) 2001-2024 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 // ===========================================================================
34 
35 class OptionsCont;
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
44 class OptionsLoader : public XERCES_CPP_NAMESPACE::HandlerBase {
45 
46 public:
48  OptionsLoader(OptionsCont& customOptions, const bool routeOnly = false);
49 
52 
55 
60  virtual void startElement(const XMLCh* const name,
61  XERCES_CPP_NAMESPACE::AttributeList& attributes);
62 
70  void characters(const XMLCh* const chars, const XERCES3_SIZE_t length);
71 
76  void endElement(const XMLCh* const name);
77 
79 
82 
87  void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
88 
93  void error(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
94 
99  void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exception);
101 
103  bool errorOccurred() const;
104 
106  const std::string& getItem() const {
107  return myItem;
108  }
109 
110 private:
112  const bool myRootOnly;
113 
115  bool myError = false;
116 
119 
121  std::string myItem;
122 
124  std::string myValue;
125 
134  void setValue(const std::string& key, const std::string& value);
135 
145  bool setSecure(OptionsCont& options, const std::string& name, const std::string& value) const;
146 
148  OptionsLoader(const OptionsLoader& s) = delete;
149 
151  OptionsLoader& operator=(const OptionsLoader& s) = delete;
152 };
A storage for options typed value containers)
Definition: OptionsCont.h:89
A SAX-Handler for loading options.
Definition: OptionsLoader.h:44
~OptionsLoader()
destructor
OptionsLoader(OptionsCont &customOptions, const bool routeOnly=false)
Constructor for default option container.
virtual void startElement(const XMLCh *const name, XERCES_CPP_NAMESPACE::AttributeList &attributes)
Called on the occurrence of the beginning of a tag.
const std::string & getItem() const
Returns the last item read.
void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Called on an XML-fatal error.
bool myError
The information whether an error occurred.
void characters(const XMLCh *const chars, const XERCES3_SIZE_t length)
Called on the occurrence of character data.
bool errorOccurred() const
Returns the information whether an error occurred.
OptionsLoader(const OptionsLoader &s)=delete
invalid copy constructor
void warning(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Called on an XML-warning.
std::string myValue
The currently read characters string.
bool setSecure(OptionsCont &options, const std::string &name, const std::string &value) const
Tries to set the named option to the given value.
OptionsLoader & operator=(const OptionsLoader &s)=delete
invalid assignment operator
void endElement(const XMLCh *const name)
Called on the end of an element.
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.
const bool myRootOnly
The information whether only the root element should be parsed.
void error(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Called on an XML-error.