OpenNI 1.5.4
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Include
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
//---------------------------------------------------------------------------
12
class
XnStringsHashKeyManager
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>
31
class
XnStringsNodeAllocator
32
{
33
public
:
34
typedef
XnKeyValuePair<const XnChar*, TValue>
TPair
;
35
typedef
XnLinkedNodeT<TPair>
TLinkedNode
;
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
{
61
typedef
XnHashT<const XnChar*, TValue, XnStringsHashKeyManager, XnStringsNodeAllocator<TValue>
>
Base
;
62
63
public
:
64
XnStringsHashT
() :
Base
() {}
65
66
XnStringsHashT
(
const
XnStringsHashT
& other) :
Base
()
67
{
68
*
this
= other;
69
}
70
71
XnStringsHashT
&
operator=
(
const
XnStringsHashT
& other)
72
{
73
Base::operator=
(other);
74
// no other members
75
return
*
this
;
76
}
77
};
78
79
class
XnStringsSet
:
public
XnStringsHashT
<void*>
80
{
81
typedef
XnStringsHashT<void*>
Base
;
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_
Generated on Thu Dec 20 2012 21:24:27 for OpenNI 1.5.4 by
1.8.1.2