Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fgas / include / fx_mem.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef _FX_MEMORY\r
8 #define _FX_MEMORY\r
9 class IFX_MEMAllocator;\r
10 class CFX_Target;\r
11 enum FX_ALLOCTYPE {\r
12     FX_ALLOCTYPE_Default                =  0,\r
13     FX_ALLOCTYPE_Static                         ,\r
14     FX_ALLOCTYPE_Fixed                          ,\r
15     FX_ALLOCTYPE_Dynamic                        ,\r
16 };\r
17 class IFX_MEMAllocator\r
18 {\r
19 public:\r
20     virtual void                        Release() = 0;\r
21     virtual void*                       Alloc(size_t size) = 0;\r
22     virtual void                        Free(void *pBlock) = 0;\r
23     virtual size_t                      GetBlockSize() const = 0;\r
24     virtual size_t                      GetDefChunkSize() const = 0;\r
25     virtual size_t                      SetDefChunkSize(size_t size) = 0;\r
26     virtual size_t                      GetCurrentDataSize() const = 0;\r
27 };\r
28 IFX_MEMAllocator*       FX_CreateAllocator(FX_ALLOCTYPE eType, size_t chunkSize, size_t blockSize);\r
29 class CFX_Target\r
30 {\r
31 public:\r
32     void*       operator new(size_t size)\r
33     {\r
34         return FX_Alloc(FX_BYTE, size);\r
35     }\r
36     void        operator delete(void *p)\r
37     {\r
38         FX_Free(p);\r
39     }\r
40     void*       operator new(size_t size, IFX_MEMAllocator *pAllocator)\r
41     {\r
42         return pAllocator->Alloc(size);\r
43     }\r
44     void        operator delete(void *p, IFX_MEMAllocator *pAllocator)\r
45     {\r
46         pAllocator->Free(p);\r
47     }\r
48     void*       operator new(size_t size, void *place)\r
49     {\r
50         return place;\r
51     }\r
52     void        operator delete(void *p, void *place)   {}\r
53 };\r
54 #define FXTARGET_New                                                                                    new\r
55 #define FXTARGET_NewWith(__allocator__)                                                 new(__allocator__)\r
56 #define FXTARGET_Delete                                                                                 delete\r
57 #define FXTARGET_DeleteWith(__class__, __allocator__, pointer)  {(pointer)->~__class__(); (pointer)->operator delete((pointer), (__allocator__));}\r
58 #endif\r