SUMO - Simulation of Urban MObility
Parameterised.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A super class for objects with additional parameters
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 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"
33 
34 #ifdef CHECK_MEMORY_LEAKS
35 #include <foreign/nvwa/debug_new.h>
36 #endif // CHECK_MEMORY_LEAKS
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
43 
44 
46 
47 
48 Parameterised::Parameterised(const std::map<std::string, std::string>& mapArg)
49  : myMap(mapArg) {
50 }
51 
52 
53 void
54 Parameterised::addParameter(const std::string& key, const std::string& value) {
55  myMap[key] = value;
56 }
57 
58 
59 void
60 Parameterised::addParameter(const std::map<std::string, std::string>& mapArg) {
61  for (std::map<std::string, std::string>::const_iterator i = mapArg.begin(); i != mapArg.end(); ++i) {
62  myMap[(*i).first] = (*i).second;
63  }
64 }
65 
66 
67 void
69  for (std::map<std::string, std::string>::const_iterator i = p.myMap.begin(); i != p.myMap.end(); ++i) {
70  myMap[(*i).first] = (*i).second;
71  }
72 }
73 
74 
75 bool
76 Parameterised::knowsParameter(const std::string& key) const {
77  return myMap.find(key) != myMap.end();
78 }
79 
80 
81 const std::string&
82 Parameterised::getParameter(const std::string& key, const std::string& defaultValue) const {
83  std::map<std::string, std::string>::const_iterator i = myMap.find(key);
84  if (i != myMap.end()) {
85  return (*i).second;
86  }
87  return defaultValue;
88 }
89 
90 
91 void
93  myMap.clear();
94 }
95 
96 void
98  for (std::map<std::string, std::string>::const_iterator j = myMap.begin(); j != myMap.end(); ++j) {
100  out.writeAttr(SUMO_ATTR_KEY, (*j).first);
101  out.writeAttr(SUMO_ATTR_VALUE, (*j).second);
102  out.closeTag();
103  }
104 }
105 
106 /****************************************************************************/
107 
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
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.
parameter associated to a certain key
~Parameterised()
Destructor.
An upper class for objects with additional parameters.
Definition: Parameterised.h:51
void addParameter(const std::string &key, const std::string &value)
Adds a parameter.
Parameterised()
Constructor.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
void writeParams(OutputDevice &out) const
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void clearParameter()
Clears the parameter map.