OpenNI 1.5.4
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. */
37typedef struct XnGeneralBuffer
38{
39 /* A pointer to the actual data. */
40 void* pData;
41 /* The size of the data in bytes. */
42 XnUInt32 nDataSize;
44
45//---------------------------------------------------------------------------
46// Exported Functions
47//---------------------------------------------------------------------------
48
52inline XnGeneralBuffer XnGeneralBufferPack(void* pData, XnUInt32 nDataSize)
53{
54 XnGeneralBuffer result;
55 result.pData = pData;
56 result.nDataSize = nDataSize;
57 return result;
58}
59
64{
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
76inline XnStatus XnGeneralBufferAlloc(XnGeneralBuffer* pDest, XnUInt32 nSize)
77{
79
80 void* pData;
81 pData = xnOSMalloc(nSize);
83
84 pDest->pData = pData;
85 pDest->nDataSize = nSize;
86 return XN_STATUS_OK;
87}
88
89inline XnStatus XnGeneralBufferRealloc(XnGeneralBuffer* pDest, XnUInt32 nSize)
90{
92
93 void* pData;
94 pData = xnOSRealloc(pDest, nSize);
96
97 pDest->pData = pData;
98 pDest->nDataSize = nSize;
99 return XN_STATUS_OK;
100}
101
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__
XnGeneralBuffer XnGeneralBufferPack(void *pData, XnUInt32 nDataSize)
Definition XnGeneralBuffer.h:52
XnStatus XnGeneralBufferAlloc(XnGeneralBuffer *pDest, XnUInt32 nSize)
Definition XnGeneralBuffer.h:76
void XnGeneralBufferFree(XnGeneralBuffer *pDest)
Definition XnGeneralBuffer.h:102
XnStatus XnGeneralBufferRealloc(XnGeneralBuffer *pDest, XnUInt32 nSize)
Definition XnGeneralBuffer.h:89
XnStatus XnGeneralBufferCopy(XnGeneralBuffer *pDest, const XnGeneralBuffer *pSrc)
Definition XnGeneralBuffer.h:63
#define XN_VALIDATE_ALLOC_PTR(x)
Definition XnOS.h:128
#define XN_VALIDATE_INPUT_PTR(x)
Definition XnOS.h:123
#define XN_FREE_AND_NULL(x)
Definition XnOS.h:151
XN_C_API void *XN_C_DECL xnOSMalloc(const XnSizeT nAllocSize)
XN_C_API void *XN_C_DECL xnOSRealloc(void *pMemory, const XnSizeT nAllocSize)
XN_C_API void XN_C_DECL xnOSMemCopy(void *pDest, const void *pSource, XnSizeT nCount)
XnUInt32 XnStatus
Definition XnStatus.h:34
#define XN_STATUS_OK
Definition XnStatus.h:37
Definition XnGeneralBuffer.h:38
XnUInt32 nDataSize
Definition XnGeneralBuffer.h:42
void * pData
Definition XnGeneralBuffer.h:40