Loading...
Searching...
No Matches
MapWrapper.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31#ifndef MAPWRAPPER_H_
32#define MAPWRAPPER_H_
33
34// using namespace std;
35
36#include <map>
37
38namespace drain
39{
40
41 template <class K, class V>
43 {
44 public:
45
46 MapWrapper() : m(ownMap) {};
47
48 MapWrapper(map<K,V> &src): m(&src) {};
49
50 virtual ~MapWrapper(){};
51
52 void setMap(map<K,V> &src){
53 m = &src;
54 }
55
56 const Data &get(const K &key) const {
57 typename map<K,V>::iterator iter = this->m->find(key);
58 if (iter != m.end()){
59 return Data();
60 }
61 else {
62 return Data(iter->second);
63 }
64 };
65
66 template<class T>
67 T get(const K &key, const T &defaultValue) const {
68 typename map<K,V>::iterator iter = this->m->find(key);
69 if (iter == m->end()){
70 return defaultValue;
71 //return defaultValue;
72 }
73 else {
74 //*iter;
75 return Data(iter->second);
76 }
77 };
78
79 protected:
80 map<K,V> *m;
81 map<K,V> ownMap;
82 };
83}
84
85#endif /*MAPWRAPPER_H_*/
86
87// Drain
Definition MapWrapper.h:43
Definition DataSelector.cpp:1277