20 #ifndef _FBXSDK_CORE_ARCH_ALLOC_H_
21 #define _FBXSDK_CORE_ARCH_ALLOC_H_
25 #if defined(_DEBUG) && defined(FBXSDK_ENV_WIN)
29 #if defined(FBXSDK_ENV_MAC)
30 #include <malloc/malloc.h>
37 #if defined(FBXSDK_CPU_32) && !defined(FBXSDK_ENV_IOS)
38 #define FBXSDK_MEMORY_ALIGNMENT ((size_t)8U)
40 #define FBXSDK_MEMORY_ALIGNMENT ((size_t)16U)
43 #define FBXSDK_MEMORY_COPY(dst, src, size) {memcpy(dst,src,size);}
45 typedef void* (*FbxMallocProc)(size_t);
46 typedef void* (*FbxCallocProc)(size_t, size_t);
47 typedef void* (*FbxReallocProc)(
void*, size_t);
101 #ifndef DOXYGEN_SHOULD_SKIP_THIS
103 FBXSDK_DLL void* FbxCalloc(
size_t pCount,
size_t pSize);
104 FBXSDK_DLL void* FbxRealloc(
void* pData,
size_t pSize);
106 FBXSDK_DLL char* FbxStrDup(
const char* pString);
107 FBXSDK_DLL wchar_t* FbxStrDupWC(
const wchar_t* pString);
111 FBXSDK_DLL void* FbxMallocDebug(
size_t pSize,
int pBlock,
const char* pFile,
int pLine);
112 FBXSDK_DLL void* FbxCallocDebug(
size_t pCount,
size_t pSize,
int pBlock,
const char* pFile,
int pLine);
113 FBXSDK_DLL void* FbxReallocDebug(
void* pData,
size_t pSize,
int pBlock,
const char* pFile,
int pLine);
114 FBXSDK_DLL void FbxFreeDebug(
void* pData,
int pBlock);
117 #if defined(FBXSDK_ALLOC_DEBUG)
118 #define FbxMalloc(s) FbxMallocDebug(s, _NORMAL_BLOCK, __FILE__, __LINE__)
119 #define FbxCalloc(c, s) FbxCallocDebug(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
120 #define FbxRealloc(p, s) FbxReallocDebug(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
121 #define FbxFree(p) FbxFreeDebug(p, _NORMAL_BLOCK)
141 template<
typename T>
void FbxDelete(T* p);
142 template<
typename T>
void FbxDelete(
const T* p);
190 template<
class Type,
class Policy=FbxDeletionPolicyDefault<Type> >
class FbxAutoPtr
200 inline Type*
Get()
const {
return mPtr; }
206 inline operator Type* ()
const {
return mPtr; }
215 inline operator bool ()
const {
return mPtr != 0; }
220 FBX_ASSERT(pPtr == 0 || pPtr != mPtr);
227 Type* TmpPtr = pOther.mPtr;
243 #ifndef DOXYGEN_SHOULD_SKIP_THIS
288 int DecRef() { count--;
if (count < 0) count = 0;
return count; }
294 template<
class Type,
class Policy=FbxDeletionPolicyDefault<Type> >
class FbxSharedPtr
321 if (pSPtr.mPtr != 0 && mRef != 0)
336 FBX_ASSERT(mRef !=
NULL);
349 inline Type*
Get()
const {
return mPtr; }
355 inline operator Type* ()
const {
return mPtr; }
364 inline operator bool ()
const {
return mPtr != 0; }
370 #ifndef DOXYGEN_SHOULD_SKIP_THIS
376 FBX_ASSERT(mPtr != 0);
377 if (mRef->DecRef() == 0)
379 Policy::DeleteIt(&mPtr);
void Reset(Type *pPtr=0)
Reset the scoped pointer by swapping with another pointer.
FbxAutoPtr mimics the auto_ptr class template implementation available in the C++ Standard Library...
FbxSharedDestroyPtr(Type *pPtr=0)
Construct from a pointer.
FBX SDK environment definition.
FbxSharedPtr(Type *pPtr)
Construct from a pointer.
void FbxSetFreeHandler(FbxFreeProc pHandler)
Set the global memory freeing function used internally by the FBX SDK.
Type * Get() const
Retrieve the pointer it holds.
FbxReallocProc FbxGetDefaultReallocHandler()
Get the default global memory re-allocation function used internally by the FBX SDK.
Deletion policy for pointer template classes that uses the FbxFree() function.
FbxReallocProc FbxGetReallocHandler()
Get the global memory re-allocation function used internally by the FBX SDK.
FbxSharedPtr class describes an object that stores a pointer to a single allocated object of type Typ...
FbxCallocProc FbxGetDefaultCallocHandler()
Get the default global zero'd memory allocation function used internally by the FBX SDK...
FbxSharedPtr(const FbxSharedPtr &pSPtr)
Copy constructor.
FbxMallocProc FbxGetMallocHandler()
Get the global memory allocation function used internally by the FBX SDK.
~FbxSharedPtr()
Destructor.
Type * operator->() const
Member access operator.
static void DeleteIt(Type **pPtr)
Destruction policy implementation.
FbxAutoDeletePtr(Type *pPtr=0)
Construct from a pointer.
Deletion policy for pointer template classes that uses the Destroy() function.
FbxAutoDestroyPtr(Type *pPtr=0)
Construct from a pointer.
void FbxDelete(T *p)
Deletion policy for pointer template classes that uses the FbxDelete() function.
Type * Get() const
Retrieve the pointer it holds.
FbxSharedDeletePtr(Type *pPtr=0)
Construct from a pointer.
void *(* FbxReallocProc)(void *, size_t)
Function pointer signature used to replace "calloc".
FbxCallocProc FbxGetCallocHandler()
Get the global zero'd memory allocation function used internally by the FBX SDK.
static void DeleteIt(Type **pPtr)
Destruction policy implementation.
FbxFreeProc FbxGetDefaultFreeHandler()
Get the default global memory freeing function used internally by the FBX SDK.
void *(* FbxMallocProc)(size_t)
static void DeleteIt(Type **pPtr)
Destruction policy implementation.
void *(* FbxCallocProc)(size_t, size_t)
Function pointer signature used to replace "malloc".
bool operator!() const
Logical not operator.
Scoped pointer for FbxNew allocations, which call FbxDelete() to deallocate.
void FbxSetMallocHandler(FbxMallocProc pHandler)
Function pointer signature used to replace "free".
FbxFreeProc FbxGetFreeHandler()
Get the global memory freeing function used internally by the FBX SDK.
Type & operator*() const
Dereference operator.
void FbxSetReallocHandler(FbxReallocProc pHandler)
Set the global memory re-allocation function used internally by the FBX SDK.
Scoped pointer for FbxMalloc allocations, which call FbxFree() to deallocate.
void FbxSetCallocHandler(FbxCallocProc pHandler)
Set the global zero'd memory allocation function used internally by the FBX SDK.
Scoped pointer for FbxObject derived classes, which call Destroy() to deallocate. ...
Type & operator*() const
Dereference operator.
bool operator!() const
Logical not operator.
Deletion policy for pointer template classes that uses the delete operator.
Scoped pointer for FbxNew allocations, which call FbxDelete() to deallocate.
FbxAutoFreePtr(Type *pPtr=0)
Construct from a pointer.
FbxMallocProc FbxGetDefaultMallocHandler()
Get the default global memory allocation function used internally by the FBX SDK. ...
void(* FbxFreeProc)(void *)
Function pointer signature used to replace "realloc".
Scoped pointer for FbxMalloc allocations, which call FbxFree() to deallocate.
Type * operator->() const
Member access operator.
FbxAutoPtr(Type *pPtr=0)
Construct from a pointer.
FbxSharedPtr & operator=(const FbxSharedPtr &pSPtr)
Scoped pointer for FbxObject derived classes, which call Destroy() to deallocate. ...
void Swap(FbxAutoPtr &pOther)
Swap with another pointer.
FbxSharedFreePtr(Type *pPtr=0)
Construct from a pointer.
static void DeleteIt(Type **mPtr)
Destruction policy implementation.
Type * Release()
Release the pointer, so that it won't perform deletion in its destruction.