XnGeneralBuffer.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 *                                                                            *
00003 *  OpenNI 1.0 Alpha                                                          *
00004 *  Copyright (C) 2010 PrimeSense Ltd.                                        *
00005 *                                                                            *
00006 *  This file is part of OpenNI.                                              *
00007 *                                                                            *
00008 *  OpenNI is free software: you can redistribute it and/or modify            *
00009 *  it under the terms of the GNU Lesser General Public License as published  *
00010 *  by the Free Software Foundation, either version 3 of the License, or      *
00011 *  (at your option) any later version.                                       *
00012 *                                                                            *
00013 *  OpenNI is distributed in the hope that it will be useful,                 *
00014 *  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00015 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the              *
00016 *  GNU Lesser General Public License for more details.                       *
00017 *                                                                            *
00018 *  You should have received a copy of the GNU Lesser General Public License  *
00019 *  along with OpenNI. If not, see <http://www.gnu.org/licenses/>.            *
00020 *                                                                            *
00021 *****************************************************************************/
00022 
00023 
00024 
00025 #ifndef __XN_GENERAL_BUFFER_H__
00026 #define __XN_GENERAL_BUFFER_H__
00027 
00028 //---------------------------------------------------------------------------
00029 // Includes
00030 //---------------------------------------------------------------------------
00031 #include "XnPlatform.h"
00032 #include "XnOS.h"
00033 #include "XnStatusCodes.h"
00034 
00035 //---------------------------------------------------------------------------
00036 // Types
00037 //---------------------------------------------------------------------------
00038 
00039 /* Describes a general buffer. */
00040 typedef struct XnGeneralBuffer
00041 {
00042         /* A pointer to the actual data. */
00043         void* pData;
00044         /* The size of the data in bytes. */
00045         XnUInt32 nDataSize;
00046 } XnGeneralBuffer;
00047 
00048 //---------------------------------------------------------------------------
00049 // Exported Functions
00050 //---------------------------------------------------------------------------
00051 
00055 inline XnGeneralBuffer XnGeneralBufferPack(void* pData, XnUInt32 nDataSize)
00056 {
00057         XnGeneralBuffer result;
00058         result.pData = pData;
00059         result.nDataSize = nDataSize;
00060         return result;
00061 }
00062 
00066 inline XnStatus XnGeneralBufferCopy(XnGeneralBuffer* pDest, const XnGeneralBuffer* pSrc)
00067 {
00068         XN_VALIDATE_INPUT_PTR(pDest);
00069         XN_VALIDATE_INPUT_PTR(pSrc);
00070 
00071         if (pSrc->nDataSize > pDest->nDataSize)
00072                 return XN_STATUS_OUTPUT_BUFFER_OVERFLOW;
00073 
00074         xnOSMemCopy(pDest->pData, pSrc->pData, pSrc->nDataSize);
00075         pDest->nDataSize = pSrc->nDataSize;
00076         return XN_STATUS_OK;
00077 }
00078 
00079 inline XnStatus XnGeneralBufferAlloc(XnGeneralBuffer* pDest, XnUInt32 nSize)
00080 {
00081         XN_VALIDATE_INPUT_PTR(pDest);
00082 
00083         void* pData;
00084         pData = xnOSMalloc(nSize);
00085         XN_VALIDATE_ALLOC_PTR(pData);
00086 
00087         pDest->pData = pData;
00088         pDest->nDataSize = nSize;
00089         return XN_STATUS_OK;
00090 }
00091 
00092 inline XnStatus XnGeneralBufferRealloc(XnGeneralBuffer* pDest, XnUInt32 nSize)
00093 {
00094         XN_VALIDATE_INPUT_PTR(pDest);
00095 
00096         void* pData;
00097         pData = xnOSRealloc(pDest, nSize);
00098         XN_VALIDATE_ALLOC_PTR(pData);
00099 
00100         pDest->pData = pData;
00101         pDest->nDataSize = nSize;
00102         return XN_STATUS_OK;
00103 }
00104 
00105 inline void XnGeneralBufferFree(XnGeneralBuffer* pDest)
00106 {
00107         xnOSFree(pDest->pData);
00108         pDest->nDataSize = 0;
00109 }
00110 
00111 //---------------------------------------------------------------------------
00112 // Helper Macros
00113 //---------------------------------------------------------------------------
00114 #define XN_PACK_GENERAL_BUFFER(x)               XnGeneralBufferPack(&x, sizeof(x))
00115 
00116 #define XN_VALIDATE_GENERAL_BUFFER_TYPE(gb, t)  \
00117         if ((gb).nDataSize != sizeof(t))                        \
00118         {                                                                                       \
00119                 return XN_STATUS_INVALID_BUFFER_SIZE;   \
00120         }
00121 
00122 #endif //__XN_GENERAL_BUFFER_H__


nao_openni
Author(s): Bener SUAY
autogenerated on Mon Jan 6 2014 11:27:51