Tizen 2.1 base
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / Ice / IceAllocator.h
1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 /**
3  *      Contains an allocator base class.
4  *      \file           IceAllocator.h
5  *      \author         Pierre Terdiman
6  *      \date           December, 19, 2003
7  */
8 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9
10 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11 // Include Guard
12 #ifndef ICEALLOCATOR_H
13 #define ICEALLOCATOR_H
14
15         enum MemoryType
16         {
17                 MEMORY_PERSISTENT,
18                 MEMORY_TEMP,
19         };
20
21         class ICECORE_API Allocator
22         {
23                 public:
24                 virtual void*   malloc(size_t size, MemoryType type)                                                                                                                                    = 0;
25                 virtual void*   mallocDebug(size_t size, const char* filename, udword line, const char* class_name, MemoryType type)    = 0;
26                 virtual void*   realloc(void* memory, size_t size)                                                                                                                                              = 0;
27                 virtual void*   shrink(void* memory, size_t size)                                                                                                                                               = 0;
28                 virtual void    free(void* memory)                                                                                                                                                                              = 0;
29         };
30
31         FUNCTION ICECORE_API Allocator* GetAllocator();
32         FUNCTION ICECORE_API bool               SetAllocator(Allocator& allocator);
33         FUNCTION ICECORE_API void               DumpMemory();
34
35         class ICECORE_API Allocateable
36         {
37                 public:
38 #ifdef DONT_TRACK_MEMORY_LEAKS
39                 inline_ void*   operator new            (size_t size, MemoryType type)                                                                                                                  { return GetAllocator()->malloc(size, type);                                                                    }
40                 inline_ void*   operator new            (size_t size, const char * filename, int line, const char* class_name, MemoryType type) { return GetAllocator()->mallocDebug(size, filename, line, class_name, type);   }
41                 inline_ void*   operator new[]          (size_t size, MemoryType type)                                                                                                                  { return GetAllocator()->malloc(size, type);                                                                    }
42                 inline_ void*   operator new[]          (size_t size, const char * filename, int line, const char* class_name, MemoryType type) { return GetAllocator()->mallocDebug(size, filename, line, class_name, type);   }
43                 inline_ void    operator delete         (void* p)                                                                                                                                                               { GetAllocator()->free(p);      }
44                 inline_ void    operator delete         (void* p, MemoryType)                                                                                                                                   { GetAllocator()->free(p);      }
45                 inline_ void    operator delete         (void* p, const char*, int, const char*, MemoryType)                                                                    { GetAllocator()->free(p);      }
46                 inline_ void    operator delete[]       (void* p)                                                                                                                                                               { GetAllocator()->free(p);      }
47                 inline_ void    operator delete[]       (void* p, MemoryType)                                                                                                                                   { GetAllocator()->free(p);      }
48                 inline_ void    operator delete[]       (void* p, const char*, int, const char*, MemoryType)                                                                    { GetAllocator()->free(p);      }
49 #endif
50         };
51
52 #endif // ICEALLOCATOR_H