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_
XnHashT
Definition: XnHashT.h:57
xnOSStrDup
XN_C_API XnChar *XN_C_DECL xnOSStrDup(const XnChar *strSource)
XnStringsHashT::operator=
XnStringsHashT & operator=(const XnStringsHashT &other)
Definition: XnStringsHashT.h:71
XnStringsHashKeyManager::Hash
static XnHashCode Hash(const XnChar *const &key)
Definition: XnStringsHashT.h:15
XnStringsHashKeyManager::Compare
static XnInt32 Compare(const XnChar *const &key1, const XnChar *const &key2)
Definition: XnStringsHashT.h:24
XnStatus
XnUInt32 XnStatus
Definition: XnStatus.h:33
XnKeyValuePair::Value
TValue const & Value() const
Definition: XnHashT.h:30
xnOSFree
XN_C_API void XN_C_DECL xnOSFree(const void *pMemBlock)
XnKeyValuePair
Definition: XnHashT.h:19
XnStringsHashT::XnStringsHashT
XnStringsHashT(const XnStringsHashT &other)
Definition: XnStringsHashT.h:66
XnLinkedNodeT< TPair >
XnHashT< const XnChar *, void *, XnStringsHashKeyManager, XnStringsNodeAllocator< void * > >::Set
XnStatus Set(const const XnChar * &key, const void * &value)
Definition: XnHashT.h:362
XN_NEW
#define XN_NEW(type,...)
Definition: XnOS.h:325
XnStringsHashT
Definition: XnStringsHashT.h:59
XnLinkedNodeT::value
T value
Definition: XnListT.h:28
XnStringsNodeAllocator::Allocate
static TLinkedNode * Allocate(TPair const &pair)
Definition: XnStringsHashT.h:37
XnHashT< const XnChar *, TValue, XnStringsHashKeyManager, XnStringsNodeAllocator< TValue > >::operator=
XnHashT & operator=(const XnHashT &other)
Definition: XnHashT.h:297
XnStringsNodeAllocator::Deallocate
static void Deallocate(TLinkedNode *pNode)
Definition: XnStringsHashT.h:48
XnStringsHashT::XnStringsHashT
XnStringsHashT()
Definition: XnStringsHashT.h:64
XnStringsNodeAllocator::TLinkedNode
XnLinkedNodeT< TPair > TLinkedNode
Definition: XnStringsHashT.h:35
XnHashT.h
xnOSStrCRC32
XN_C_API XnStatus XN_C_DECL xnOSStrCRC32(const XnChar *cpString, XnUInt32 *nCRC32)
XnStringsSet::Set
XnStatus Set(const XnChar *key)
Definition: XnStringsHashT.h:84
XnStringsNodeAllocator::TPair
XnKeyValuePair< const XnChar *, TValue > TPair
Definition: XnStringsHashT.h:34
XnHashCode
XnUInt8 XnHashCode
Definition: XnHashT.h:13
XnStringsSet
Definition: XnStringsHashT.h:79
XnStringsHashKeyManager
Definition: XnStringsHashT.h:12
XN_DELETE
#define XN_DELETE(p)
Definition: XnOS.h:335
XnKeyValuePair::Key
TKey const & Key() const
Definition: XnHashT.h:29
XnStringsNodeAllocator
Definition: XnStringsHashT.h:31