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{
14public:
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
30template<class TValue>
32{
33public:
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
58template<class TValue>
59class XnStringsHashT : public XnHashT<const XnChar*, TValue, XnStringsHashKeyManager, XnStringsNodeAllocator<TValue> >
60{
62
63public:
65
67 {
68 *this = other;
69 }
70
72 {
73 Base::operator=(other);
74 // no other members
75 return *this;
76 }
77};
78
79class XnStringsSet : public XnStringsHashT<void*>
80{
82
83public:
84 XnStatus Set(const XnChar* key)
85 {
86 return Base::Set(key, NULL);
87 }
88};
89
90#endif // _XN_STRINGS_HASH_T_H_
XnUInt8 XnHashCode
Definition XnHashT.h:13
#define XN_DELETE(p)
Definition XnOS.h:336
#define XN_NEW(type,...)
Definition XnOS.h:326
XN_C_API void XN_C_DECL xnOSFree(const void *pMemBlock)
XN_C_API XnChar *XN_C_DECL xnOSStrDup(const XnChar *strSource)
XN_C_API XnStatus XN_C_DECL xnOSStrCRC32(const XnChar *cpString, XnUInt32 *nCRC32)
XnUInt32 XnStatus
Definition XnStatus.h:34
Definition XnHashT.h:58
XnStatus Set(const TKey &key, const TValue &value)
Definition XnHashT.h:362
Definition XnStringsHashT.h:13
static XnInt32 Compare(const XnChar *const &key1, const XnChar *const &key2)
Definition XnStringsHashT.h:24
static XnHashCode Hash(const XnChar *const &key)
Definition XnStringsHashT.h:15
Definition XnStringsHashT.h:60
XnStringsHashT & operator=(const XnStringsHashT &other)
Definition XnStringsHashT.h:71
XnStringsHashT()
Definition XnStringsHashT.h:64
XnStringsHashT(const XnStringsHashT &other)
Definition XnStringsHashT.h:66
Definition XnStringsHashT.h:32
static void Deallocate(TLinkedNode *pNode)
Definition XnStringsHashT.h:48
XnLinkedNodeT< TPair > TLinkedNode
Definition XnStringsHashT.h:35
XnKeyValuePair< const XnChar *, TValue > TPair
Definition XnStringsHashT.h:34
static TLinkedNode * Allocate(TPair const &pair)
Definition XnStringsHashT.h:37
Definition XnStringsHashT.h:80
XnStatus Set(const XnChar *key)
Definition XnStringsHashT.h:84
Definition XnHashT.h:20
TValue const & Value() const
Definition XnHashT.h:30
TKey const & Key() const
Definition XnHashT.h:29
Definition XnListT.h:22
T value
Definition XnListT.h:28