SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parameterised.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A RGB-color definition
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include "Parameterised.h"
32 
33 #ifdef CHECK_MEMORY_LEAKS
34 #include <foreign/nvwa/debug_new.h>
35 #endif // CHECK_MEMORY_LEAKS
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42 
43 
45 
46 
47 Parameterised::Parameterised(const std::map<std::string, std::string>& mapArg)
48  : myMap(mapArg)
49 { }
50 
51 
52 void
53 Parameterised::addParameter(const std::string& key, const std::string& value) {
54  myMap[key] = value;
55 }
56 
57 
58 void
59 Parameterised::addParameter(const std::map<std::string, std::string>& mapArg) {
60  for (std::map<std::string, std::string>::const_iterator i = mapArg.begin(); i != mapArg.end(); ++i) {
61  myMap[(*i).first] = (*i).second;
62  }
63 }
64 
65 
66 void
68  for (std::map<std::string, std::string>::const_iterator i = p.myMap.begin(); i != p.myMap.end(); ++i) {
69  myMap[(*i).first] = (*i).second;
70  }
71 }
72 
73 
74 bool
75 Parameterised::knowsParameter(const std::string& key) const {
76  return myMap.find(key) != myMap.end();
77 }
78 
79 
80 const std::string&
81 Parameterised::getParameter(const std::string& key, const std::string& defaultValue) const {
82  std::map<std::string, std::string>::const_iterator i = myMap.find(key);
83  if (i != myMap.end()) {
84  return (*i).second;
85  }
86  return defaultValue;
87 }
88 
89 
90 void
92  myMap.clear();
93 }
94 
95 
96 /****************************************************************************/
97 
std::map< std::string, std::string > myMap
The key->value map.
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
~Parameterised()
Destructor.
An upper class for objects with additional parameters.
Definition: Parameterised.h:47
void addParameter(const std::string &key, const std::string &value)
Adds a parameter.
Parameterised()
Constructor.
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
void clearParameter()
Clears the parameter map.