OpenNI 1.5.7
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) 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_H
22
#define _XN_STRINGS_HASH_H
23
24
//---------------------------------------------------------------------------
25
// Includes
26
//---------------------------------------------------------------------------
27
#include "
XnHash.h
"
28
#include <
XnOS.h
>
29
30
//---------------------------------------------------------------------------
31
// Types
32
//---------------------------------------------------------------------------
33
class
XnStringsKeyManager
34
{
35
public
:
36
static
XnHashValue
Hash
(
const
XnChar*
const
& key)
37
{
38
XnUInt32 nCRC = 0;
39
xnOSStrCRC32
(key, &nCRC);
40
41
// convert from UINT32 to XnHashValue
42
return
nCRC % (1 << (
sizeof
(
XnHashValue
)*8));
43
}
44
45
static
XnInt32
Compare
(
const
XnChar*
const
& key1,
const
XnChar*
const
& key2)
46
{
47
return
strcmp(key1, key2);
48
}
49
};
50
51
class
XnStringsKeyTranslator
52
{
53
public
:
54
static
XnValue
CreateValueCopy
(
const
XnChar*
const
& orig)
55
{
56
// we should copy string, so we can keep the key
57
XnUInt32 nLen =
xnOSStrLen
(orig) + 1;
// with null termination
58
XnChar* pcKey = (XnChar*)
xnOSMalloc
(nLen);
59
xnOSStrCopy
(pcKey, orig, nLen);
60
return
(pcKey);
61
}
62
63
static
void
FreeValue
(
XnValue
& Value)
64
{
65
XnChar* pcKey = (XnChar*)Value;
66
xnOSFree
(pcKey);
67
}
68
69
static
XnValue
GetAsValue
(
const
XnChar*
const
& orig)
70
{
71
return
(
XnValue
)orig;
72
}
73
74
static
const
XnChar*
const
&
GetFromValue
(
const
XnValue
& Value)
75
{
76
return
(
const
XnChar*
const
&)Value;
77
}
78
79
static
const
XnChar*&
GetFromValue
(
XnValue
& Value)
80
{
81
return
(
const
XnChar*&)Value;
82
}
83
};
84
89
#define XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR_DECL(decl, ValueType, ClassName, ValueTranslator) \
90
XN_DECLARE_HASH_DECL(decl, const XnChar*, ValueType, ClassName, XnStringsKeyTranslator, ValueTranslator, XnStringsKeyManager) \
91
92
96
#define XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR(ValueType, ClassName, ValueTranslator) \
97
XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR_DECL(, ValueType, ClassName, ValueTranslator)
98
103
#define XN_DECLARE_STRINGS_HASH_DECL(decl, ValueType, ClassName) \
104
XN_DECLARE_DEFAULT_VALUE_TRANSLATOR_DECL(decl, ValueType, XN_DEFAULT_TRANSLATOR_NAME(ClassName)) \
105
XN_DECLARE_STRINGS_HASH_WITH_TRANSLATOR_DECL(decl, ValueType, ClassName, XN_DEFAULT_TRANSLATOR_NAME(ClassName)) \
106
107
111
#define XN_DECLARE_STRINGS_HASH(ValueType, ClassName) \
112
XN_DECLARE_STRINGS_HASH_DECL(, ValueType, ClassName)
113
114
XN_DECLARE_STRINGS_HASH
(
XnValue
, XnStringsHash)
115
116
117
#endif //_XN_STRINGS_HASH_H
Generated on Tue Nov 12 2013 13:40:20 for OpenNI 1.5.7 by
1.8.3.1