OpenNI 1.5.4
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Include
XnStringsHash.h
Go to the documentation of this file.
1
/****************************************************************************
2
* *
3
* OpenNI 1.x Alpha *
4
* Copyright (C) 2011 PrimeSense Ltd. *
5
* *
6
* This file is part of OpenNI. *
7
* *
8
* OpenNI is free software: you can redistribute it and/or modify *
9
* it under the terms of the GNU Lesser General Public License as published *
10
* by the Free Software Foundation, either version 3 of the License, or *
11
* (at your option) any later version. *
12
* *
13
* OpenNI is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
* GNU Lesser General Public License for more details. *
17
* *
18
* You should have received a copy of the GNU Lesser General Public License *
19
* along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
20
* *
21
****************************************************************************/
22
#ifndef _XN_STRINGS_HASH_H
23
#define _XN_STRINGS_HASH_H
24
25
//---------------------------------------------------------------------------
26
// Includes
27
//---------------------------------------------------------------------------
28
#include "
XnHash.h
"
29
#include <
XnOS.h
>
30
31
//---------------------------------------------------------------------------
32
// Types
33
//---------------------------------------------------------------------------
34
class
XnStringsKeyManager
35
{
36
public
:
37
static
XnHashValue
Hash
(
const
XnChar*
const
& key)
38
{
39
XnUInt32 nCRC = 0;
40
xnOSStrCRC32
(key, &nCRC);
41
42
// convert from UINT32 to XnHashValue
43
return
nCRC % (1 << (
sizeof
(
XnHashValue
)*8));
44
}
45
46
static
XnInt32
Compare
(
const
XnChar*
const
& key1,
const
XnChar*
const
& key2)
47
{
48
return
strcmp(key1, key2);
49
}
50
};
51
52
class
XnStringsKeyTranslator
53
{
54
public
:
55
static
XnValue
CreateValueCopy
(
const
XnChar*
const
& orig)
56
{
57
// we should copy string, so we can keep the key
58
XnUInt32 nLen =
xnOSStrLen
(orig) + 1;
// with null termination
59
XnChar* pcKey = (XnChar*)
xnOSMalloc
(nLen);
60
xnOSStrCopy
(pcKey, orig, nLen);
61
return
(pcKey);
62
}
63
64
static
void
FreeValue
(
XnValue
& Value)
65
{
66
XnChar* pcKey = (XnChar*)Value;
67
xnOSFree
(pcKey);
68
}
69
70
static
XnValue
GetAsValue
(
const
XnChar*
const
& orig)
71
{
72
return
(
XnValue
)orig;
73
}
74
75
static
const
XnChar*
const
&
GetFromValue
(
const
XnValue
& Value)
76
{
77
return
(
const
XnChar*
const
&)Value;
78
}
79
80
static
const
XnChar*&
GetFromValue
(
XnValue
& Value)
81
{
82
return
(
const
XnChar*&)Value;
83
}
84
};
85
90
#define XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR_DECL(decl, ValueType, ClassName, ValueTranslator) \
91
XN_DECLARE_HASH_DECL(decl, const XnChar*, ValueType, ClassName, XnStringsKeyTranslator, ValueTranslator, XnStringsKeyManager) \
92
93
97
#define XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR(ValueType, ClassName, ValueTranslator) \
98
XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR_DECL(, ValueType, ClassName, ValueTranslator)
99
104
#define XN_DECLARE_STRINGS_HASH_DECL(decl, ValueType, ClassName) \
105
XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(decl, ValueType, XN_DEFAULT_TRANSLATOR_NAME(ClassName)) \
106
XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR_DECL(decl, ValueType, ClassName, XN_DEFAULT_TRANSLATOR_NAME(ClassName)) \
107
108
112
#define XN_DECLARE_STRINGS_HASH(ValueType, ClassName) \
113
XN_DECLARE_STRINGS_HASH_DECL(, ValueType, ClassName)
114
115
XN_DECLARE_STRINGS_HASH
(
XnValue
, XnStringsHash)
116
117
118
#endif //_XN_STRINGS_HASH_H
Generated on Fri Dec 28 2012 12:04:02 for OpenNI 1.5.4 by
1.8.1.2