Eclipse SUMO - Simulation of Urban MObility
Parameterised.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2020 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 <map>
25 #include <string>
26 
27 // ===========================================================================
28 // class declarations
29 // ===========================================================================
30 class OutputDevice;
31 
32 // ===========================================================================
33 // class definitions
34 // ===========================================================================
40 public:
41 
43  enum class ParameterisedAttrType {
45  STRING,
47  DOUBLE
48  };
49 
51  Parameterised();
52 
57 
61  Parameterised(const std::map<std::string, std::string>& mapArg);
62 
67  Parameterised(ParameterisedAttrType attrType, const std::map<std::string, std::string>& mapArg);
68 
71 
76  virtual void setParameter(const std::string& key, const std::string& value);
77 
81  void unsetParameter(const std::string& key);
82 
86  void updateParameters(const std::map<std::string, std::string>& mapArg);
87 
92  bool knowsParameter(const std::string& key) const;
93 
99  const std::string getParameter(const std::string& key, const std::string defaultValue = "") const;
100 
106  double getDouble(const std::string& key, const double defaultValue) const;
107 
109  void clearParameter();
110 
112  const std::map<std::string, std::string>& getParametersMap() const;
113 
115  std::string getParametersStr(const std::string kvsep = "=", const std::string sep = "|") const;
116 
118  void setParameters(const Parameterised& params);
119 
121  void setParametersMap(const std::map<std::string, std::string>& paramsMap);
122 
128  void setParametersStr(const std::string& paramsString, const std::string kvsep = "=", const std::string sep = "|");
129 
131  void writeParams(OutputDevice& device) const;
132 
134  static bool areParametersValid(const std::string& value, bool report = false, ParameterisedAttrType attrType = ParameterisedAttrType::STRING,
135  const std::string kvsep = "=", const std::string sep = "|");
136 
137 private:
139  static bool isParameterValid(const std::string& value, ParameterisedAttrType attrType,
140  const std::string& kvsep, const std::string& sep);
141 
144 
146  std::map<std::string, std::string> myMap;
147 };
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
An upper class for objects with additional parameters.
Definition: Parameterised.h:39
ParameterisedAttrType
@brie enum for Parameterised type
Definition: Parameterised.h:43
@ STRING
Parameterised accept strings.
@ DOUBLE
Parameterised only accept doubles.
static bool isParameterValid(const std::string &value, ParameterisedAttrType attrType, const std::string &kvsep, const std::string &sep)
check if given string can be parsed to a parameter of type "key=value"
void unsetParameter(const std::string &key)
Removes a parameter.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
double getDouble(const std::string &key, const double defaultValue) const
Returns the value for a given key converted to a double.
Parameterised()
Default constructor (for Strings)
void setParameters(const Parameterised &params)
set the inner key/value map in map<string, string> format
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"
~Parameterised()
Destructor.
void clearParameter()
Clears the parameter map.
const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
std::map< std::string, std::string > myMap
The key->value map.
ParameterisedAttrType myAttrType
parameterised type
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 std::map< std::string, std::string > &mapArg)
Adds or updates all given parameters from the map.
void setParametersMap(const std::map< std::string, std::string > &paramsMap)
set the inner key/value map in map<string, string> format
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.