CFx SDK Documentation  2023 SP0
OdHeap.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 
25 #ifndef _OD_HEAPOPERATORS_INCLUDED_
26 #define _OD_HEAPOPERATORS_INCLUDED_
27 
28 #include "OdAlloc.h"
29 #include <new>
30 
31 #ifdef __BCPLUSPLUS__ // borland compiler does not support "placement delete"
32 
36 #define ODRX_HEAP_OPERATORS() \
37 void* operator new(size_t s) { return ::odrxAlloc(s); }\
38 void operator delete(void* p) { ::odrxFree(p); }\
39 void* operator new[](size_t s) { return ::odrxAlloc(s); }\
40 void operator delete[](void* p) { ::odrxFree(p); }\
41 void *operator new(size_t, void* p) { return p; }\
42 void *operator new[](size_t, void* p) { return p; }
43 
44 #elif defined(_MSC_VER) // MSVC ignores exception specs (and gives warning)
45 
49 #define ODRX_HEAP_OPERATORS() \
50 void* operator new(size_t s)\
51 {\
52  void* p = ::odrxAlloc(s);\
53  if ( !p ) throw std::bad_alloc();\
54  return p;\
55 }\
56 void operator delete(void* p) { ::odrxFree(p); }\
57 void* operator new[](size_t s)\
58 {\
59  void* p = ::odrxAlloc(s);\
60  if ( !p ) throw std::bad_alloc();\
61  return p;\
62 }\
63 void operator delete[](void* p) { ::odrxFree(p); }\
64 void *operator new(size_t, void* p) { return p; }\
65 void operator delete( void*, void* ) {}\
66 void *operator new[](size_t, void* p) { return p; }\
67 void operator delete[]( void*, void* ) {}
68 
69 #else
70 
74 #define ODRX_HEAP_OPERATORS() \
75 void* operator new(size_t s) \
76 {\
77  void* p = ::odrxAlloc(s);\
78  if ( !p ) throw std::bad_alloc();\
79  return p;\
80 }\
81 void operator delete(void* p) { ::odrxFree(p); }\
82 void* operator new[](size_t s) \
83 {\
84  void* p = ::odrxAlloc(s);\
85  if ( !p ) throw std::bad_alloc();\
86  return p;\
87 }\
88 void operator delete[](void* p) { ::odrxFree(p); }\
89 void *operator new(size_t, void* p) throw() { return p; }\
90 void operator delete( void*, void* ) {}\
91 void *operator new[](size_t, void* p) throw() { return p; }\
92 void operator delete[]( void*, void* ) {}
93 
94 #endif
95 
96 #if !defined(_MSC_VER) || (_MSC_VER < 1900)
97 
101 #define ODRX_NO_HEAP_OPERATORS() \
102 void* operator new(size_t ) throw() { ODA_FAIL(); return 0; }\
103 void operator delete(void* ) { ODA_FAIL(); throw OdError(eNotApplicable); }\
104 void* operator new[](size_t ) throw() { ODA_FAIL(); return 0; }\
105 void operator delete[](void* ) { ODA_FAIL(); throw OdError(eNotApplicable); }
106 
107 #else // defined(_MSC_VER) && (_MSC_VER >= 1900)
108 
113 #define ODRX_NO_HEAP_OPERATORS() \
114 static void _throwOdError_eNotApplicable() { ODA_FAIL(); throw OdError(eNotApplicable); }\
115 void* operator new(size_t ) throw() { ODA_FAIL(); return 0; }\
116 void operator delete(void* ) { _throwOdError_eNotApplicable(); }\
117 void* operator new[](size_t ) throw() { ODA_FAIL(); return 0; }\
118 void operator delete[](void* ) { _throwOdError_eNotApplicable(); }
119 
120 #endif // defined(_MSC_VER) && (_MSC_VER >= 1900)
121 
122 #ifdef OD_REDEFINE_HEAP_OPERATORS
123 
127 #define ODRX_USING_HEAP_OPERATORS(T) \
128 void* operator new(size_t s) throw() { return T::operator new(s); }\
129 void operator delete(void* p) { T::operator delete(p); }\
130 void* operator new[](size_t s) throw() { return T::operator new(s); }\
131 void operator delete[](void* p) { T::operator delete(p); }
132 
133 #else
134 
138 #define ODRX_USING_HEAP_OPERATORS(T) \
139 using T::operator new;\
140 using T::operator delete;\
141 using T::operator new[];\
142 using T::operator delete[]
143 
144 #endif
145 
146 
147 #endif // _OD_HEAPOPERATORS_INCLUDED_