OpenNI 1.5.4
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
XnGeneralBuffer.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_GENERAL_BUFFER_H__
23
#define __XN_GENERAL_BUFFER_H__
24
25
//---------------------------------------------------------------------------
26
// Includes
27
//---------------------------------------------------------------------------
28
#include "
XnPlatform.h
"
29
#include "
XnOS.h
"
30
#include "
XnStatusCodes.h
"
31
32
//---------------------------------------------------------------------------
33
// Types
34
//---------------------------------------------------------------------------
35
36
/* Describes a general buffer. */
37
typedef
struct
XnGeneralBuffer
38
{
39
/* A pointer to the actual data. */
40
void
*
pData
;
41
/* The size of the data in bytes. */
42
XnUInt32
nDataSize
;
43
}
XnGeneralBuffer
;
44
45
//---------------------------------------------------------------------------
46
// Exported Functions
47
//---------------------------------------------------------------------------
48
52
inline
XnGeneralBuffer
XnGeneralBufferPack
(
void
* pData, XnUInt32 nDataSize)
53
{
54
XnGeneralBuffer
result;
55
result.
pData
= pData;
56
result.
nDataSize
= nDataSize;
57
return
result;
58
}
59
63
inline
XnStatus
XnGeneralBufferCopy
(
XnGeneralBuffer
* pDest,
const
XnGeneralBuffer
* pSrc)
64
{
65
XN_VALIDATE_INPUT_PTR
(pDest);
66
XN_VALIDATE_INPUT_PTR
(pSrc);
67
68
if
(pSrc->
nDataSize
> pDest->
nDataSize
)
69
return
XN_STATUS_OUTPUT_BUFFER_OVERFLOW;
70
71
xnOSMemCopy
(pDest->
pData
, pSrc->
pData
, pSrc->
nDataSize
);
72
pDest->
nDataSize
= pSrc->
nDataSize
;
73
return
XN_STATUS_OK
;
74
}
75
76
inline
XnStatus
XnGeneralBufferAlloc
(
XnGeneralBuffer
* pDest, XnUInt32 nSize)
77
{
78
XN_VALIDATE_INPUT_PTR
(pDest);
79
80
void
* pData;
81
pData =
xnOSMalloc
(nSize);
82
XN_VALIDATE_ALLOC_PTR
(pData);
83
84
pDest->
pData
= pData;
85
pDest->
nDataSize
= nSize;
86
return
XN_STATUS_OK
;
87
}
88
89
inline
XnStatus
XnGeneralBufferRealloc
(
XnGeneralBuffer
* pDest, XnUInt32 nSize)
90
{
91
XN_VALIDATE_INPUT_PTR
(pDest);
92
93
void
* pData;
94
pData =
xnOSRealloc
(pDest, nSize);
95
XN_VALIDATE_ALLOC_PTR
(pData);
96
97
pDest->
pData
= pData;
98
pDest->
nDataSize
= nSize;
99
return
XN_STATUS_OK
;
100
}
101
102
inline
void
XnGeneralBufferFree
(
XnGeneralBuffer
* pDest)
103
{
104
XN_FREE_AND_NULL
(pDest->
pData
);
105
pDest->
nDataSize
= 0;
106
}
107
108
//---------------------------------------------------------------------------
109
// Helper Macros
110
//---------------------------------------------------------------------------
111
#define XN_PACK_GENERAL_BUFFER(x) XnGeneralBufferPack(&x, sizeof(x))
112
113
#define XN_VALIDATE_GENERAL_BUFFER_TYPE(gb, t) \
114
if ((gb).nDataSize != sizeof(t)) \
115
{ \
116
return XN_STATUS_INVALID_BUFFER_SIZE; \
117
}
118
119
#endif //__XN_GENERAL_BUFFER_H__
Include
XnGeneralBuffer.h
Generated on Mon Oct 28 2013 23:21:07 for OpenNI 1.5.4 by
1.8.4