OpenNI 1.5.7
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Include
XnStringsHashT.h
Go to the documentation of this file.
1
/*****************************************************************************
2
* *
3
* OpenNI 1.x Alpha *
4
* Copyright (C) 2012 PrimeSense Ltd. *
5
* *
6
* This file is part of OpenNI. *
7
* *
8
* Licensed under the Apache License, Version 2.0 (the "License"); *
9
* you may not use this file except in compliance with the License. *
10
* You may obtain a copy of the License at *
11
* *
12
* http://www.apache.org/licenses/LICENSE-2.0 *
13
* *
14
* Unless required by applicable law or agreed to in writing, software *
15
* distributed under the License is distributed on an "AS IS" BASIS, *
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17
* See the License for the specific language governing permissions and *
18
* limitations under the License. *
19
* *
20
*****************************************************************************/
21
#ifndef _XN_STRINGS_HASH_T_H_
22
#define _XN_STRINGS_HASH_T_H_
23
24
//---------------------------------------------------------------------------
25
// Includes
26
//---------------------------------------------------------------------------
27
#include "
XnHashT.h
"
28
29
//---------------------------------------------------------------------------
30
// Code
31
//---------------------------------------------------------------------------
32
class
XnStringsHashKeyManager
33
{
34
public
:
35
static
XnHashCode
Hash
(
const
XnChar*
const
& key)
36
{
37
XnUInt32 nCRC = 0;
38
xnOSStrCRC32
(key, &nCRC);
39
40
// convert from UINT32 to XnHashValue
41
return
nCRC % (1 << (
sizeof
(
XnHashCode
)*8));
42
}
43
44
static
XnInt32
Compare
(
const
XnChar*
const
& key1,
const
XnChar*
const
& key2)
45
{
46
return
strcmp(key1, key2);
47
}
48
};
49
50
template
<
class
TValue>
51
class
XnStringsNodeAllocator
52
{
53
public
:
54
typedef
XnKeyValuePair<const XnChar*, TValue>
TPair
;
55
typedef
XnLinkedNodeT<TPair>
TLinkedNode
;
56
57
static
TLinkedNode
*
Allocate
(
TPair
const
& pair)
58
{
59
XnChar* pKeyCopy =
xnOSStrDup
(pair.
Key
());
60
if
(pKeyCopy == NULL)
61
{
62
return
NULL;
63
}
64
65
return
XN_NEW
(
TLinkedNode
,
TPair
(pKeyCopy, pair.
Value
()));
66
}
67
68
static
void
Deallocate
(
TLinkedNode
* pNode)
69
{
70
XN_ASSERT(pNode != NULL);
71
XN_ASSERT(pNode->
value
.
Key
() != NULL);
72
73
xnOSFree
(pNode->
value
.
Key
());
74
XN_DELETE
(pNode);
75
}
76
};
77
78
template
<
class
TValue>
79
class
XnStringsHashT
:
public
XnHashT
<const XnChar*, TValue, XnStringsHashKeyManager, XnStringsNodeAllocator<TValue> >
80
{
81
typedef
XnHashT<const XnChar*, TValue, XnStringsHashKeyManager, XnStringsNodeAllocator<TValue>
>
Base
;
82
83
public
:
84
XnStringsHashT
() :
Base
() {}
85
86
XnStringsHashT
(
const
XnStringsHashT
& other) :
Base
()
87
{
88
*
this
= other;
89
}
90
91
XnStringsHashT
&
operator=
(
const
XnStringsHashT
& other)
92
{
93
Base::operator=
(other);
94
// no other members
95
return
*
this
;
96
}
97
};
98
99
class
XnStringsSet
:
public
XnStringsHashT
<void*>
100
{
101
typedef
XnStringsHashT<void*>
Base
;
102
103
public
:
104
XnStatus
Set
(
const
XnChar* key)
105
{
106
return
Base::Set
(key, NULL);
107
}
108
};
109
110
#endif // _XN_STRINGS_HASH_T_H_
Generated on Tue Nov 12 2013 13:40:20 for OpenNI 1.5.7 by
1.8.3.1