39 myAttrType(attrType) {
50 myAttrType(attrType) {
54 for (
const auto& keyValue : mapArg) {
59 myMap.insert(keyValue);
61 WRITE_WARNING(
"Invalid conversion from string to double (" + keyValue.second +
")");
83 WRITE_WARNING(
"Invalid conversion from string to double (" + value +
")");
99 for (
const auto& keyValue : mapArg) {
113 const auto i =
myMap.find(key);
114 if (i !=
myMap.end()) {
123 const auto i =
myMap.find(key);
124 if (i !=
myMap.end()) {
128 WRITE_WARNING(
"Invalid conversion from string to double (" + i->second +
")");
131 WRITE_WARNING(
"Invalid conversion from string to double (empty value)");
145 const std::map<std::string, std::string>&
156 for (
const auto& keyValue :
myMap) {
160 result += keyValue.first + kvsep + keyValue.second;
183 for (
const auto& keyValue : paramsMap) {
196 for (
const auto& keyValue : parameters) {
207 for (
const auto& keyValue :
myMap) {
221 for (
const auto& keyValueStr : parameters) {
226 WRITE_WARNING(
"Invalid format of parameter (" + keyValueStr +
")");
241 const std::string& kvsep,
const std::string& sep) {
242 if (value.find(sep) != std::string::npos || value.find(kvsep) == std::string::npos) {
248 if (keyValueStr.size() == 2) {
#define WRITE_WARNING(msg)
@ SUMO_TAG_PARAM
parameter associated to a certain key
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
ParameterisedAttrType
@brie enum for Parameterised type
@ 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 ¶ms)
set the inner key/value map in map<string, string> format
void setParametersStr(const std::string ¶msString, 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 > ¶msMap)
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.
static bool isValidParameterKey(const std::string &value)
whether the given string is a valid key for a parameter
std::vector< std::string > getVector()
return vector of strings
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.