/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file OptionsLoader.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @date Mon, 17 Dec 200117///18// A SAX-Handler for loading options19/****************************************************************************/20#pragma once21#include <config.h>2223#include <xercesc/sax/HandlerBase.hpp>24#include <xercesc/sax/AttributeList.hpp>25#include <xercesc/sax/SAXParseException.hpp>26#include <xercesc/sax/SAXException.hpp>27#include <string>282930// ===========================================================================31// class declarations32// ===========================================================================3334class OptionsCont;3536// ===========================================================================37// class definitions38// ===========================================================================39/**40* @class OptionsLoader41* @brief A SAX-Handler for loading options42*/43class OptionsLoader : public XERCES_CPP_NAMESPACE::HandlerBase {4445public:46/// @brief Constructor for default option container47OptionsLoader(OptionsCont& customOptions, const bool routeOnly = false);4849/// @brief destructor50~OptionsLoader();5152/// @name Handlers for the SAX DocumentHandler interface53/// @{5455/** @brief Called on the occurrence of the beginning of a tag56*57* Sets the name of the last item58*/59virtual void startElement(const XMLCh* const name,60XERCES_CPP_NAMESPACE::AttributeList& attributes);6162/** @brief Called on the occurrence of character data63*64* If this occurs inside a single tag it sets the option named65* by the tag to the value given by the character data.66* This is considered deprecated in favor of attributes.67* @todo Describe better68*/69void characters(const XMLCh* const chars, const XERCES3_SIZE_t length);7071/** @brief Called on the end of an element72*73* Resets the element name74*/75void endElement(const XMLCh* const name);7677/// @}7879/// @name Handlers for the SAX ErrorHandler interface80/// @{8182/** @brief Called on an XML-warning83*84* The warning is reported to the warning-instance of MsgHandler85*/86void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exception);8788/** @brief Called on an XML-error89*90* The warning is reported to the error-instance of MsgHandler91*/92void error(const XERCES_CPP_NAMESPACE::SAXParseException& exception);9394/** @brief Called on an XML-fatal error95*96* The warning is reported to the error-instance of MsgHandler97*/98void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exception);99/// @}100101/// @brief Returns the information whether an error occurred102bool errorOccurred() const;103104/// @brief Returns the last item read105const std::string& getItem() const {106return myItem;107}108109private:110/// @brief The information whether only the root element should be parsed111const bool myRootOnly;112113/// @brief The information whether an error occurred114bool myError = false;115116/// @brief The options to fill117OptionsCont& myOptions;118119/// @brief The name of the currently parsed option120std::string myItem;121122/// @brief The currently read characters string123std::string myValue;124125/// @brief Whether a value attribute was read126bool myFoundValue;127128/** @brief Tries to set the named option to the given value129*130* Also evaluates whether it is a boolean or a filename option and131* does the relevant checks / modifications.132*133* @param[in] key The name of the option to set134* @param[in] value The new value for the option135*/136void setValue(const std::string& key, const std::string& value);137138/** @brief Tries to set the named option to the given value139*140* Checks the item whether it was default before setting it.141* Returns the information whether the item was set before (was not a default value)142*143* @param[in] name The name of the option to set144* @param[in] value The new value for the option145* @return Whether the option could be set146*/147bool setSecure(OptionsCont& options, const std::string& name, const std::string& value) const;148149/// @brief invalid copy constructor150OptionsLoader(const OptionsLoader& s) = delete;151152/// @brief invalid assignment operator153OptionsLoader& operator=(const OptionsLoader& s) = delete;154};155156157