xpmap.h
1 /* Distributed under the Apache License, Version 2.0.
2  See accompanying NOTICE file for details.*/
3 
4 #ifndef __XPMAP_H__
5 #define __XPMAP_H__
6 
7 #include "xparray.h"
8 
9 template <class KEY, class TYPE>
10 class CXpMap
11 {
12  protected:
13 
14  struct SNode
15  {
16  SNode(const KEY& Key, const TYPE& Value) : m_Key(Key), m_Value(Value) {}
17  virtual ~SNode() {}
18 
19  KEY m_Key;
20  TYPE m_Value;
21  };
22 
24 
26  public:
27 
28  CXpMap(const int nGrowBy = 10);
29  CXpMap(const CXpMap& Map);
30  virtual ~CXpMap();
31 
32  INT_PTR Insert(const KEY& Key, const TYPE& Value);
33 
34  void Remove(const KEY& Key);
35  void RemoveAll();
36 
37  inline INT_PTR GetCount() const;
38 
39  inline bool HasKey(const KEY& Key) const;
40  inline INT_PTR FindKey(const KEY& Key) const;
41  inline bool FindValue(const KEY& Key, TYPE& Value) const;
42 
43  inline const KEY& GetKey(const INT_PTR nIndex) const;
44  inline KEY& GetKey(const INT_PTR nIndex);
45 
46  inline const TYPE& GetValue(const INT_PTR nIndex) const;
47  inline TYPE& GetValue(const INT_PTR nIndex);
48 
49  inline void GetPair(const INT_PTR nIndex, KEY& Key, TYPE& Value) const ;
50 
51  inline CXpMap Union(const CXpMap& Right) const;
52  inline CXpMap Intersection(const CXpMap& Right) const;
53  inline CXpMap Difference(const CXpMap& Right) const;
54 
55  inline const TYPE& operator[](const INT_PTR nIndex) const;
56  inline TYPE& operator[](const INT_PTR nIndex);
57 
58  HRESULT Copy(const CXpMap& Map);
59 
60  bool operator==(const CXpMap& Map) const;
61  CXpMap& operator=(const CXpMap& Map);
62 
63  protected:
64  bool BinarySearch(const KEY& Key, INT_PTR& nIndex) const;
65 };
66 
67 #include "xpmap.inl"
68 
69 #endif //__XPMAP_H__
Definition: xpmap.h:11
HRESULT Copy(const CXpMap &Map)
bool BinarySearch(const KEY &Key, INT_PTR &nIndex) const
CXpMap Intersection(const CXpMap &Right) const
const TYPE & operator[](const INT_PTR nIndex) const
CXpArray< SNode * > CPtrArray
Definition: xpmap.h:23
CXpMap Union(const CXpMap &Right) const
CPtrArray m_SortedArray
Definition: xpmap.h:25
INT_PTR FindKey(const KEY &Key) const
bool HasKey(const KEY &Key) const
void GetPair(const INT_PTR nIndex, KEY &Key, TYPE &Value) const
virtual ~CXpMap()
bool FindValue(const KEY &Key, TYPE &Value) const
CXpMap(const CXpMap &Map)
CXpMap Difference(const CXpMap &Right) const
KEY & GetKey(const INT_PTR nIndex)
void RemoveAll()
const KEY & GetKey(const INT_PTR nIndex) const
bool operator==(const CXpMap &Map) const
void Remove(const KEY &Key)
CXpMap & operator=(const CXpMap &Map)
TYPE & operator[](const INT_PTR nIndex)
TYPE & GetValue(const INT_PTR nIndex)
INT_PTR Insert(const KEY &Key, const TYPE &Value)
const TYPE & GetValue(const INT_PTR nIndex) const
INT_PTR GetCount() const
CXpMap(const int nGrowBy=10)
Definition: xpmap.h:15
SNode(const KEY &Key, const TYPE &Value)
Definition: xpmap.h:16
TYPE m_Value
Definition: xpmap.h:20
KEY m_Key
Definition: xpmap.h:19
virtual ~SNode()
Definition: xpmap.h:17

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.