libcdos-fw
CFMap.h
1 #ifndef __CF_MAP_H__
2 #define __CF_MAP_H__
3 
4 #include <Core/CFTypes.h>
5 #include <map>
6 
20 template<typename K, typename V>
21 class CFMap {
22 public:
26  CFMap() : m_map(std::map<K, V>()) {}
27 
32  CFMap(const CFMap& other)
33  : m_map(other.m_map) {
34 
35  }
36 
42  ~CFMap() {}
43 
51  bool isEmpty() const {
52  return m_map.empty();
53  }
54 
63  bool contain(K key) const {
64  return (m_map.end() != m_map.find(key));
65  }
66 
73  void insert(K key, V val) {
74  m_map.insert( std::pair<K, V>(key, val) );
75  }
76 
82  void remove(K key) {
83  m_map.erase(key);
84  }
85 
90  void clear() {
91  m_map.clear();
92  }
93 
100  V value(K key) {
101  return m_map[key];
102  }
103 
111  V operator[] (K key) {
112  return value(key);
113  }
114 
115 private:
116  std::map<K, V> m_map;
117 };
118 
119 #endif // __CF_MAP_H__
CFMap()
默认构造函数.
Definition: CFMap.h:26
V operator[](K key)
从map中获取与key相关联的数据元素。
Definition: CFMap.h:111
bool isEmpty() const
判断该map是否为空。
Definition: CFMap.h:51
结构与枚举类型定义.
~CFMap()
析构函数.
Definition: CFMap.h:42
bool contain(K key) const
判断该map是否包含key键。
Definition: CFMap.h:63
CFMap 容器类.
Definition: CFMap.h:21
CFMap(const CFMap &other)
拷贝构造函数.
Definition: CFMap.h:32
V value(K key)
从map中获取与key相关联的数据元素。
Definition: CFMap.h:100
void insert(K key, V val)
将key-val进行关联并插入到map中。
Definition: CFMap.h:73
void clear()
清除该CFMap中的所有元素。
Definition: CFMap.h:90