MINT2
PolymorphMap.h
Go to the documentation of this file.
1 #ifndef MINT_POLYMORPH_MAP
2 #define MINT_POLYMORPH_MAP
3 
4 #include <map>
5 
6 namespace MINT{
7 template<typename Key, typename Val>
9 
10  protected:
11  std::map<Key, Val> _map;
12 
13  public:
15  PolymorphMap(const PolymorphMap& other) : _map(other._map){}
16  PolymorphMap(const typename std::map<Key, Val>& other) : _map(other){}
17 
18  virtual ~PolymorphMap(){}
19 
20  std::map<Key, Val>& theMap(){return _map;}
21  const std::map<Key, Val>& theMap()const {return _map;}
22 
23  Val& operator[](const Key& k){return _map[k];}
24  const Val& operator[](const Key& k) const{return _map[k];}
25 
26  typename std::map<Key, Val>::iterator begin(){return _map.begin();}
27  typename std::map<Key, Val>::const_iterator begin() const{return _map.begin();}
28 
29  typename std::map<Key, Val>::iterator end(){return _map.end();}
30  typename std::map<Key, Val>::const_iterator end() const{return _map.end();}
31 
32  typename std::map<Key, Val>::iterator find(const Key& c){return _map.find(c);}
33  typename std::map<Key, Val>::const_iterator find(const Key& c) const{return _map.find(c);}
34 
35  void insert(typename std::map<Key, Val>::const_iterator first
36  , typename std::map<Key, Val>::const_iterator last){
37  _map.insert(first, last);
38  }
39 
40  unsigned int size() const{return _map.size();}
41  bool empty() const{return _map.empty();}
42 
44  _map = other._map;
45  return *this;
46  }
47 
48  void clear(){_map.clear();}
49  void resize(unsigned int N){_map.resize(N);}
50  void resize(unsigned int N, const Val& c){_map.resize(N, c);}
51 
52  operator const typename std::map<Key, Val>& ()const{
53  return this->theMap();
54  }
55  operator typename std::map<Key, Val>& (){
56  return this->theMap();
57  }
58 
60  return _map == v2.theMap();
61  }
63  return !(_map == v2.theMap());
64  }
65 
66  bool operator<(const MINT::PolymorphMap<Key, Val>& v2) const{
67  return _map < v2.theMap();
68  }
69  bool operator>(const MINT::PolymorphMap<Key, Val>& v2) const{
70  return v2 < _map.theMap();
71  }
72 
73 
74  };
75 
76 
77 }// namespace MINT
78 
79 #endif
void resize(unsigned int N, const Val &c)
Definition: PolymorphMap.h:50
Val & operator[](const Key &k)
Definition: PolymorphMap.h:23
virtual ~PolymorphMap()
Definition: PolymorphMap.h:18
void resize(unsigned int N)
Definition: PolymorphMap.h:49
std::map< Key, Val >::const_iterator find(const Key &c) const
Definition: PolymorphMap.h:33
std::map< Key, Val >::iterator end()
Definition: PolymorphMap.h:29
bool operator>(const MINT::PolymorphMap< Key, Val > &v2) const
Definition: PolymorphMap.h:69
std::map< Key, Val > & theMap()
Definition: PolymorphMap.h:20
std::map< Key, Val >::const_iterator begin() const
Definition: PolymorphMap.h:27
std::map< Key, Val > _map
Definition: PolymorphMap.h:11
bool operator==(const MINT::PolymorphMap< Key, Val > &v2) const
Definition: PolymorphMap.h:59
unsigned int size() const
Definition: PolymorphMap.h:40
const std::map< Key, Val > & theMap() const
Definition: PolymorphMap.h:21
bool operator!=(const MINT::PolymorphMap< Key, Val > &v2) const
Definition: PolymorphMap.h:62
std::map< Key, Val >::iterator begin()
Definition: PolymorphMap.h:26
std::map< Key, Val >::const_iterator end() const
Definition: PolymorphMap.h:30
std::map< Key, Val >::iterator find(const Key &c)
Definition: PolymorphMap.h:32
PolymorphMap< Key, Val > & operator=(const PolymorphMap &other)
Definition: PolymorphMap.h:43
PolymorphMap(const PolymorphMap &other)
Definition: PolymorphMap.h:15
bool operator<(const MINT::PolymorphMap< Key, Val > &v2) const
Definition: PolymorphMap.h:66
void insert(typename std::map< Key, Val >::const_iterator first, typename std::map< Key, Val >::const_iterator last)
Definition: PolymorphMap.h:35
const Val & operator[](const Key &k) const
Definition: PolymorphMap.h:24
PolymorphMap(const typename std::map< Key, Val > &other)
Definition: PolymorphMap.h:16
bool empty() const
Definition: PolymorphMap.h:41