Make a bunch of JBig2 classes independent of CJBig2_Object.
[pdfium.git] / core / src / fxcodec / jbig2 / JBig2_Object.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "JBig2_Object.h"
8 #include "JBig2_Module.h"
9 void* CJBig2_Object::operator new(size_t size,
10                                   CJBig2_Module* pModule,
11                                   const FX_CHAR* filename,
12                                   int line) {
13   CJBig2_Object* p;
14   p = (CJBig2_Object*)pModule->JBig2_Malloc((FX_DWORD)size);
15   p->m_pModule = pModule;
16   return p;
17 }
18 void CJBig2_Object::operator delete(void* p,
19                                     CJBig2_Module* pModule,
20                                     const FX_CHAR* filename,
21                                     int line) {
22   pModule->JBig2_Free(p);
23 }
24 void* CJBig2_Object::operator new(size_t size, CJBig2_Module* pModule) {
25   CJBig2_Object* p;
26   p = (CJBig2_Object*)pModule->JBig2_Malloc((FX_DWORD)size);
27   p->m_pModule = pModule;
28   return p;
29 }
30 void CJBig2_Object::operator delete(void* p) {
31   if (p) {
32     ((CJBig2_Object*)p)->m_pModule->JBig2_Free(p);
33   }
34 }
35 void CJBig2_Object::operator delete(void* p, CJBig2_Module* pModule) {
36   pModule->JBig2_Free(p);
37 }
38 void* CJBig2_Object::operator new[](size_t size,
39                                     CJBig2_Module* pModule,
40                                     size_t unit_size,
41                                     const FX_CHAR* filename,
42                                     int line) {
43   void* p;
44   uint8_t *pCur, *pEnd;
45   p = (uint8_t*)pModule->JBig2_Malloc((FX_DWORD)size);
46   pCur = (uint8_t*)p;
47   pEnd = pCur + size;
48   for (; pCur < pEnd; pCur += unit_size) {
49     ((CJBig2_Object*)pCur)->m_pModule = pModule;
50   }
51   return p;
52 }
53 void CJBig2_Object::operator delete[](void* p,
54                                       CJBig2_Module* pModule,
55                                       size_t unit_size,
56                                       const FX_CHAR* filename,
57                                       int line) {
58   pModule->JBig2_Free(p);
59 }
60 void* CJBig2_Object::operator new[](size_t size,
61                                     CJBig2_Module* pModule,
62                                     size_t unit_size) {
63   void* p;
64   uint8_t *pCur, *pEnd;
65   p = (uint8_t*)pModule->JBig2_Malloc((FX_DWORD)size);
66   pCur = (uint8_t*)p;
67   pEnd = pCur + size;
68   for (; pCur < pEnd; pCur += unit_size) {
69     ((CJBig2_Object*)pCur)->m_pModule = pModule;
70   }
71   return p;
72 }
73 void CJBig2_Object::operator delete[](void* p) {
74   if (p) {
75     ((CJBig2_Object*)p)->m_pModule->JBig2_Free(p);
76   }
77 }
78 void CJBig2_Object::operator delete[](void* p,
79                                       CJBig2_Module* pModule,
80                                       size_t unit_size) {
81   pModule->JBig2_Free(p);
82 }