Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
Parameterised.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2002-2026 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/****************************************************************************/
21// A super class for objects with additional parameters
22/****************************************************************************/
23#pragma once
24#include <config.h>
25#include <map>
26#include <string>
27#include <vector>
28
29// ===========================================================================
30// class definitions
31// ===========================================================================
37
38public:
40 typedef std::map<std::string, std::string> Map;
41
44
48 Parameterised(const Parameterised::Map& mapArg);
49
51 virtual ~Parameterised();
52
57 virtual void setParameter(const std::string& key, const std::string& value);
58
62 void unsetParameter(const std::string& key);
63
67 void updateParameters(const Parameterised::Map& mapArg);
68
72 void mergeParameters(const Parameterised::Map& mapArg, const std::string separator = " ", bool uniqueValues = true);
73
78 bool hasParameter(const std::string& key) const;
79
85 virtual const std::string getParameter(const std::string& key, const std::string defaultValue = "") const;
86
92 double getDouble(const std::string& key, const double defaultValue) const;
93
95 void clearParameter();
96
99
101 std::string getParametersStr(const std::string kvsep = "=", const std::string sep = "|") const;
102
104 void setParameters(const Parameterised& params);
105
107 void setParameters(const std::vector<std::pair<std::string, std::string> >& params);
108
114 void setParametersStr(const std::string& paramsString, const std::string kvsep = "=", const std::string sep = "|");
115
117 static bool areParametersValid(const std::string& value, bool report = false, const std::string kvsep = "=", const std::string sep = "|");
118
120 static bool areAttributesValid(const std::string& value, bool report = false, const std::string kvsep = "=", const std::string sep = "|");
121
122private:
124 static bool isParameterValid(const std::string& value, const std::string& kvsep, const std::string& sep);
125
128};
An upper class for objects with additional parameters.
static bool areAttributesValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to an attributes map "key1=value1|key2=value2|....
static bool isParameterValid(const std::string &value, const std::string &kvsep, const std::string &sep)
check if given string can be parsed to a parameter of type "key=value"
Parameterised::Map myMap
The key->value map.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void unsetParameter(const std::string &key)
Removes a parameter.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
std::map< std::string, std::string > Map
parameters map
double getDouble(const std::string &key, const double defaultValue) const
Returns the value for a given key converted to a double.
Parameterised()
Default constructor.
void setParameters(const Parameterised &params)
set the given key/value map in map<string, string> format
void mergeParameters(const Parameterised::Map &mapArg, const std::string separator=" ", bool uniqueValues=true)
Adds or appends all given parameters from the map.
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
virtual ~Parameterised()
Destructor.
void clearParameter()
Clears the parameter map.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
void updateParameters(const Parameterised::Map &mapArg)
Adds or updates all given parameters from the map.