OpenNI 1.5.4
XnStringsHashT.h
Go to the documentation of this file.
1 #ifndef _XN_STRINGS_HASH_T_H_
2 #define _XN_STRINGS_HASH_T_H_
3 
4 //---------------------------------------------------------------------------
5 // Includes
6 //---------------------------------------------------------------------------
7 #include "XnHashT.h"
8 
9 //---------------------------------------------------------------------------
10 // Code
11 //---------------------------------------------------------------------------
13 {
14 public:
15  static XnHashCode Hash(const XnChar* const& key)
16  {
17  XnUInt32 nCRC = 0;
18  xnOSStrCRC32(key, &nCRC);
19 
20  // convert from UINT32 to XnHashValue
21  return nCRC % (1 << (sizeof(XnHashCode)*8));
22  }
23 
24  static XnInt32 Compare(const XnChar* const& key1, const XnChar* const& key2)
25  {
26  return strcmp(key1, key2);
27  }
28 };
29 
30 template<class TValue>
32 {
33 public:
36 
37  static TLinkedNode* Allocate(TPair const& pair)
38  {
39  XnChar* pKeyCopy = xnOSStrDup(pair.Key());
40  if (pKeyCopy == NULL)
41  {
42  return NULL;
43  }
44 
45  return XN_NEW(TLinkedNode, TPair(pKeyCopy, pair.Value()));
46  }
47 
48  static void Deallocate(TLinkedNode* pNode)
49  {
50  XN_ASSERT(pNode != NULL);
51  XN_ASSERT(pNode->value.Key() != NULL);
52 
53  xnOSFree(pNode->value.Key());
54  XN_DELETE(pNode);
55  }
56 };
57 
58 template<class TValue>
59 class XnStringsHashT : public XnHashT<const XnChar*, TValue, XnStringsHashKeyManager, XnStringsNodeAllocator<TValue> >
60 {
62 
63 public:
65 
67  {
68  *this = other;
69  }
70 
72  {
73  Base::operator=(other);
74  // no other members
75  return *this;
76  }
77 };
78 
79 class XnStringsSet : public XnStringsHashT<void*>
80 {
82 
83 public:
84  XnStatus Set(const XnChar* key)
85  {
86  return Base::Set(key, NULL);
87  }
88 };
89 
90 #endif // _XN_STRINGS_HASH_T_H_