1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    Parameterised.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Jakob Erdmann
13 /// @author  Michael Behrisch
14 /// @author  Melanie Knocke
15 /// @date    Sept 2002
16 /// @version $Id$
17 ///
18 // A super class for objects with additional parameters
19 /****************************************************************************/
20 #ifndef Parameterised_h
21 #define Parameterised_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 
28 #include <map>
29 #include <string>
30 
31 // ===========================================================================
32 // class declarations
33 // ===========================================================================
34 class OutputDevice;
35 
36 // ===========================================================================
37 // class definitions
38 // ===========================================================================
39 /**
40  * @class Parameterised
41  * @brief An upper class for objects with additional parameters
42  */
43 class Parameterised {
44 public:
45     /// @brief Constructor
46     Parameterised();
47 
48     /** @brief Constructor with parameters
49      * @param[in] mapArg Pre-given parameter
50      */
51     Parameterised(const std::map<std::string, std::string>& mapArg);
52 
53     /// @brief Destructor
54     ~Parameterised();
55 
56     /** @brief Sets a parameter
57      * @param[in] key The parameter's name
58      * @param[in] value The parameter's value
59      */
60     void setParameter(const std::string& key, const std::string& value);
61 
62     /** @brief Removes a parameter
63      * @param[in] key The parameter's name
64      */
65     void unsetParameter(const std::string& key);
66 
67     /** @brief Adds or updates all given parameters from the map
68      * @param[in] mapArg The keys/values to insert
69      */
70     void updateParameter(const std::map<std::string, std::string>& mapArg);
71 
72     /** @brief Returns whether the parameter is known
73      * @param[in] key The key to ask for
74      * @return Whether the key is known
75      */
76     bool knowsParameter(const std::string& key) const;
77 
78     /** @brief Returns the value for a given key
79      * @param[in] key The key to ask for
80      * @param[in] defaultValue The default value to return if no value is stored under the key
81      * @return The value stored under the key
82      */
83     const std::string getParameter(const std::string& key, const std::string& defaultValue = "") const;
84 
85     /** @brief Returns the value for a given key converted to a double
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     double getDouble(const std::string& key, const double defaultValue) const;
91 
92     /// @brief Clears the parameter map
93     void clearParameter();
94 
95     /// @brief Returns the inner key/value map
96     const std::map<std::string, std::string>& getParametersMap() const;
97 
98     /// @brief write Params in the given outputdevice
99     void writeParams(OutputDevice& device) const;
100 
101 private:
102     /// @brief The key->value map
103     std::map<std::string, std::string> myMap;
104 };
105 
106 
107 #endif
108 
109 /****************************************************************************/
110 
111