Minsky
constMap.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2013
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef CONSTMAP_H
20 #define CONSTMAP_H
21 
22 namespace minsky
23 {
24  // a map with a const [] that returns a default object
25  template <class K, class V>
26  struct ConstMap: public std::map<K,V>
27  {
28  ConstMap() {}
29  template <class T>
30  explicit ConstMap(const T& x): std::map<K,V>(x) {}
31  template <class T, class U>
32  ConstMap(const T& x, const U& y): std::map<K,V>(x,y) {}
33 
34  using std::map<K,V>::operator[];
35  V operator[](const K& k) const {
36  typename std::map<K,V>::const_iterator i=this->find(k);
37  if (i!=this->end())
38  return i->second;
39  else
40  return V();
41  }
42  };
43 }
44 
45 #include "constMap.cd"
46 #include "constMap.xcd"
47 #endif
V operator[](const K &k) const
Definition: constMap.h:35
STL namespace.
ConstMap(const T &x)
Definition: constMap.h:30
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
ConstMap(const T &x, const U &y)
Definition: constMap.h:32