Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/common/Parameterised.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2002-2025 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
/****************************************************************************/
14
/// @file Parameterised.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @author Melanie Knocke
19
/// @date Sept 2002
20
///
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
// ===========================================================================
32
class OutputDevice;
33
34
// ===========================================================================
35
// class definitions
36
// ===========================================================================
37
/**
38
* @class Parameterised
39
* @brief An upper class for objects with additional parameters
40
*/
41
class Parameterised {
42
43
public:
44
/// @brief parameters map
45
typedef std::map<std::string, std::string> Map;
46
47
/// @brief Default constructor
48
Parameterised();
49
50
/**@brief Constructor with parameters (for Strings)
51
* @param[in] mapArg Pre-given parameter
52
*/
53
Parameterised(const Parameterised::Map& mapArg);
54
55
/// @brief Destructor
56
virtual ~Parameterised();
57
58
/**@brief Sets a parameter
59
* @param[in] key The parameter's name
60
* @param[in] value The parameter's value
61
*/
62
virtual void setParameter(const std::string& key, const std::string& value);
63
64
/**@brief Removes a parameter
65
* @param[in] key The parameter's name
66
*/
67
void unsetParameter(const std::string& key);
68
69
/**@brief Adds or updates all given parameters from the map
70
* @param[in] mapArg The keys/values to insert
71
*/
72
void updateParameters(const Parameterised::Map& mapArg);
73
74
/**@brief Adds or appends all given parameters from the map
75
* @param[in] mapArg The keys/values to insert
76
*/
77
void mergeParameters(const Parameterised::Map& mapArg, const std::string separator = " ", bool uniqueValues = true);
78
79
/**@brief Returns whether the parameter is set
80
* @param[in] key The key to ask for
81
* @return Whether the key is known
82
*/
83
bool hasParameter(const std::string& key) const;
84
85
/**@brief Returns the value for a given key
86
* @param[in] key The key to ask for
87
* @param[in] defaultValue The default value to return if no value is stored under the key
88
* @return The value stored under the key
89
*/
90
virtual const std::string getParameter(const std::string& key, const std::string defaultValue = "") const;
91
92
/**@brief Returns the value for a given key converted to a double
93
* @param[in] key The key to ask for
94
* @param[in] defaultValue The default value to return if no value is stored under the key
95
* @return The value stored under the key
96
*/
97
double getDouble(const std::string& key, const double defaultValue) const;
98
99
/// @brief Clears the parameter map
100
void clearParameter();
101
102
/// @brief Returns the inner key/value map
103
const Parameterised::Map& getParametersMap() const;
104
105
/// @brief Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
106
std::string getParametersStr(const std::string kvsep = "=", const std::string sep = "|") const;
107
108
/// @brief set the given key/value map in map<string, string> format
109
void setParameters(const Parameterised& params);
110
111
/// @brief set the given key/value vector in map<string, string> format
112
void setParameters(const std::vector<std::pair<std::string, std::string> >& params);
113
114
/**@brief set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
115
* @param[in] paramsString A serialized key-value map
116
* @param[in] kvsep The separater between key and value
117
* @param[in] sep The separater between map entries
118
*/
119
void setParametersStr(const std::string& paramsString, const std::string kvsep = "=", const std::string sep = "|");
120
121
/// @brief write Params in the given outputdevice
122
void writeParams(OutputDevice& device) const;
123
124
/// @brief check if given string can be parsed to a parameters map "key1=value1|key2=value2|...|keyN=valueN"
125
static bool areParametersValid(const std::string& value, bool report = false, const std::string kvsep = "=", const std::string sep = "|");
126
127
/// @brief check if given string can be parsed to an attributes map "key1=value1|key2=value2|...|keyN=valueN" (used in generic datas)
128
static bool areAttributesValid(const std::string& value, bool report = false, const std::string kvsep = "=", const std::string sep = "|");
129
130
private:
131
/// @brief check if given string can be parsed to a parameter of type "key=value"
132
static bool isParameterValid(const std::string& value, const std::string& kvsep, const std::string& sep);
133
134
/// @brief The key->value map
135
Parameterised::Map myMap;
136
};
137
138