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