/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2002-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 Parameterised.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @author Melanie Knocke18/// @date Sept 200219///20// A super class for objects with additional parameters21/****************************************************************************/22#pragma once23#include <config.h>24#include <map>25#include <string>26#include <vector>2728// ===========================================================================29// class declarations30// ===========================================================================31class OutputDevice;3233// ===========================================================================34// class definitions35// ===========================================================================36/**37* @class Parameterised38* @brief An upper class for objects with additional parameters39*/40class Parameterised {4142public:43/// @brief parameters map44typedef std::map<std::string, std::string> Map;4546/// @brief Default constructor47Parameterised();4849/**@brief Constructor with parameters (for Strings)50* @param[in] mapArg Pre-given parameter51*/52Parameterised(const Parameterised::Map& mapArg);5354/// @brief Destructor55virtual ~Parameterised();5657/**@brief Sets a parameter58* @param[in] key The parameter's name59* @param[in] value The parameter's value60*/61virtual void setParameter(const std::string& key, const std::string& value);6263/**@brief Removes a parameter64* @param[in] key The parameter's name65*/66void unsetParameter(const std::string& key);6768/**@brief Adds or updates all given parameters from the map69* @param[in] mapArg The keys/values to insert70*/71void updateParameters(const Parameterised::Map& mapArg);7273/**@brief Adds or appends all given parameters from the map74* @param[in] mapArg The keys/values to insert75*/76void mergeParameters(const Parameterised::Map& mapArg, const std::string separator = " ", bool uniqueValues = true);7778/**@brief Returns whether the parameter is set79* @param[in] key The key to ask for80* @return Whether the key is known81*/82bool hasParameter(const std::string& key) const;8384/**@brief Returns the value for a given key85* @param[in] key The key to ask for86* @param[in] defaultValue The default value to return if no value is stored under the key87* @return The value stored under the key88*/89virtual const std::string getParameter(const std::string& key, const std::string defaultValue = "") const;9091/**@brief Returns the value for a given key converted to a double92* @param[in] key The key to ask for93* @param[in] defaultValue The default value to return if no value is stored under the key94* @return The value stored under the key95*/96double getDouble(const std::string& key, const double defaultValue) const;9798/// @brief Clears the parameter map99void clearParameter();100101/// @brief Returns the inner key/value map102const Parameterised::Map& getParametersMap() const;103104/// @brief Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"105std::string getParametersStr(const std::string kvsep = "=", const std::string sep = "|") const;106107/// @brief set the given key/value map in map<string, string> format108void setParameters(const Parameterised& params);109110/// @brief set the given key/value vector in map<string, string> format111void setParameters(const std::vector<std::pair<std::string, std::string> >& params);112113/**@brief set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"114* @param[in] paramsString A serialized key-value map115* @param[in] kvsep The separater between key and value116* @param[in] sep The separater between map entries117*/118void setParametersStr(const std::string& paramsString, const std::string kvsep = "=", const std::string sep = "|");119120/// @brief write Params in the given outputdevice121void writeParams(OutputDevice& device) const;122123/// @brief check if given string can be parsed to a parameters map "key1=value1|key2=value2|...|keyN=valueN"124static bool areParametersValid(const std::string& value, bool report = false, const std::string kvsep = "=", const std::string sep = "|");125126/// @brief check if given string can be parsed to an attributes map "key1=value1|key2=value2|...|keyN=valueN" (used in generic datas)127static bool areAttributesValid(const std::string& value, bool report = false, const std::string kvsep = "=", const std::string sep = "|");128129private:130/// @brief check if given string can be parsed to a parameter of type "key=value"131static bool isParameterValid(const std::string& value, const std::string& kvsep, const std::string& sep);132133/// @brief The key->value map134Parameterised::Map myMap;135};136137138