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-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/****************************************************************************/
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 declarations
31// ===========================================================================
32class OutputDevice;
33
34// ===========================================================================
35// class definitions
36// ===========================================================================
42
43public:
45 typedef std::map<std::string, std::string> Map;
46
49
53 Parameterised(const Parameterised::Map& mapArg);
54
56 virtual ~Parameterised();
57
62 virtual void setParameter(const std::string& key, const std::string& value);
63
67 void unsetParameter(const std::string& key);
68
72 void updateParameters(const Parameterised::Map& mapArg);
73
77 void mergeParameters(const Parameterised::Map& mapArg, const std::string separator = " ", bool uniqueValues = true);
78
83 bool hasParameter(const std::string& key) const;
84
90 virtual const std::string getParameter(const std::string& key, const std::string defaultValue = "") const;
91
97 double getDouble(const std::string& key, const double defaultValue) const;
98
104 std::vector<double> getDoubles(const std::string& key, std::vector<double> defaultValue = std::vector<double>()) const;
105
107 void clearParameter();
108
111
113 std::string getParametersStr(const std::string kvsep = "=", const std::string sep = "|") const;
114
116 void setParameters(const Parameterised& params);
117
123 void setParametersStr(const std::string& paramsString, const std::string kvsep = "=", const std::string sep = "|");
124
126 void writeParams(OutputDevice& device) const;
127
129 static bool areParametersValid(const std::string& value, bool report = false, const std::string kvsep = "=", const std::string sep = "|");
130
132 static bool areAttributesValid(const std::string& value, bool report = false, const std::string kvsep = "=", const std::string sep = "|");
133
134private:
136 static bool isParameterValid(const std::string& value, const std::string& kvsep, const std::string& sep);
137
140};
Static storage of an output device and its base (abstract) implementation.
An upper class for objects with additional parameters.
std::vector< double > getDoubles(const std::string &key, std::vector< double > defaultValue=std::vector< double >()) const
Returns the value for a given key converted to a list of doubles.
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 inner 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.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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.