CFx SDK Documentation  2023 SP0
DebugStuff.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 
26 
27 #ifndef __DEBUG_STUFF__INCLUDED
28 #define __DEBUG_STUFF__INCLUDED
29 
30 
31 #if defined(_DEBUG) || !defined(NDEBUG)
32 #define ODA_DIAGNOSTICS
33 #endif // _DEBUG
34 
35 #ifdef ODA_DIAGNOSTICS
36 
37 #include "OdaDefs.h"
38 #include "RootExport.h"
39 
40 void FIRSTDLL_EXPORT OdAssert(const char* expresssion, const char* filename, int nLineNo);
41 void FIRSTDLL_EXPORT OdAssert(const char* group,
42  const char* expresssion, const char* fileName, int nLineNo);
43 void FIRSTDLL_EXPORT OdTrace(const OdChar* szFormat, ...);
44 #if defined(_MSC_VER) && _MSC_VER >= 1300
45 void FIRSTDLL_EXPORT OdTrace(const __wchar_t* lpszFormat, ...);
46 #endif
47 
48 inline void oda_noop(void) {}
49 #define ODA_ASSERT(exp) ((!(exp)) ? OdAssert(#exp, __FILE__, __LINE__) : oda_noop())
50 #define ODA_VERIFY(exp) ODA_ASSERT(exp)
51 #define ODA_ASSERT_ONCE(exp)\
52 { static bool was_here = false;\
53  if (!was_here && !(exp))\
54  { was_here = true;\
55  OdAssert(#exp, __FILE__, __LINE__);\
56  }\
57 }
58 #define ODA_VERIFY_ONCE(exp)\
59 { static bool was_here = false;\
60  if (!(exp) && !was_here)\
61  { was_here = true;\
62  OdAssert(#exp, __FILE__, __LINE__);\
63  }\
64 }
65 #define ODA_FAIL() OdAssert("Invalid Execution.", __FILE__, __LINE__)
66 #define ODA_FAIL_ONCE()\
67 { static bool was_here = false;\
68  if (!was_here)\
69  { was_here = true;\
70  OdAssert("Invalid Execution.", __FILE__, __LINE__);\
71  }\
72 }
73 
74 #define ODA_FAIL_M(message) (void)( (OdAssert(message, __FILE__, __LINE__), 0) )
75 #define ODA_FAIL_M_ONCE(message)\
76 { static bool was_here = false;\
77  if (!was_here)\
78  { was_here = true;\
79  OdAssert(message, __FILE__, __LINE__);\
80  }\
81 }
82 
83 
84 #define ODA_ASSERT_X(grp, exp) (void)( (exp) || (OdAssert((const char*)#grp, (const char*)#exp, __FILE__, __LINE__), 0) )
85 #define ODA_VERIFY_X(grp, exp) ODA_ASSERT_X(grp, exp)
86 #define ODA_ASSERT_ONCE_X(grp, exp)\
87 { static bool was_here = false;\
88  if (!was_here && !(exp))\
89  { was_here = true;\
90  OdAssert(#grp, #exp, __FILE__, __LINE__);\
91  }\
92 }
93 #define ODA_FAIL_X(grp) OdAssert(#grp, "Invalid Execution.", __FILE__, __LINE__)
94 #define ODA_FAIL_ONCE_X(grp)\
95 { static bool was_here = false;\
96  if (!was_here)\
97  { was_here = true;\
98  OdAssert(#grp, "Invalid Execution.", __FILE__, __LINE__);\
99  }\
100 }
101 #define ODA_ASSERT_VAR(code) code // to declare variables for assert conditions only
102 #define ToOdInt8 (val) (ODA_ASSERT(( (OdInt8)val) == val), (OdInt8) val)
103 #define ToOdUInt8 (val) (ODA_ASSERT(( (OdUInt8)val) == val), (OdUInt8) val)
104 #define ToOdInt16 (val) (ODA_ASSERT((( OdInt16)val) == val), (OdInt16) val)
105 #define ToOdUInt16(val) (ODA_ASSERT(((OdUInt16)val) == val), (OdUInt16)val)
106 #define ToOdInt32 (val) (ODA_ASSERT(( (OdInt32)val) == val), (OdInt32) val)
107 #define ToOdUInt32(val) (ODA_ASSERT(((OdUInt32)val) == val), (OdUInt32)val)
108 
109 #else // ODA_DIAGNOSTICS
110 
111 #define ODA_ASSERT(condition)
112 #define ODA_VERIFY(condition) (void)(condition)
113 #define ODA_ASSERT_ONCE(condition)
114 #define ODA_VERIFY_ONCE(condition) (void)(condition)
115 #define ODA_FAIL()
116 #define ODA_FAIL_ONCE()
117 #define ODA_FAIL_M(message)
118 #define ODA_FAIL_M_ONCE(message)
119 
120 #define ODA_ASSERT_X(grp, exp)
121 #define ODA_VERIFY_X(grp, exp) (void)(exp)
122 #define ODA_ASSERT_ONCE_X(grp, exp)
123 #define ODA_FAIL_X(grp)
124 #define ODA_FAIL_ONCE_X(grp)
125 #define ODA_ASSERT_VAR(code)
126 
127 #define ToOdInt8 (val) ((OdInt8) val)
128 #define ToOdUInt8 (val) ((OdUInt8) val)
129 #define ToOdInt16 (val) ((OdInt16) val)
130 #define ToOdUInt16(val) ((OdUInt16)val)
131 #define ToOdInt32 (val) ((OdInt32) val)
132 #define ToOdUInt32(val) ((OdUInt32)val)
133 
134 #define ODA_NON_TRACING
135 
136 #endif // ODA_DIAGNOSTICS
137 
138 #ifndef ODA_NON_TRACING
139  #define ODA_TRACE OdTrace
140  #define ODA_TRACE0(szFormat) OdTrace(OD_T(szFormat))
141  #define ODA_TRACE1(szFormat, param1) OdTrace(OD_T(szFormat), param1)
142  #define ODA_TRACE2(szFormat, param1, param2) OdTrace(OD_T(szFormat), param1, param2)
143  #define ODA_TRACE3(szFormat, param1, param2, param3) OdTrace(OD_T(szFormat), param1, param2, param3)
144 #else // ODA_NON_TRACING
145  #define ODA_TRACE
146  #define ODA_TRACE0(szFormat)
147  #define ODA_TRACE1(szFormat, param1)
148  #define ODA_TRACE2(szFormat, param1, param2)
149  #define ODA_TRACE3(szFormat, param1, param2, param3)
150 #endif // ODA_NON_TRACING
151 
152 // Use this macro to perform compilation time check.
153 // For example: ODA_ASSUME(sizeof(double) == 8)
154 #ifdef __GNUC__
155  #define ODA_ASSUME(expr) extern char __attribute((unused)) OdaAssumeArray[expr];
156 #else
157  #define ODA_ASSUME(expr) extern char OdaAssumeArray[expr];
158 #endif
159 
160 #if defined(_MSC_VER)
161 
162 #pragma warning (push)
163 #pragma warning ( disable : 4100 ) // Unreferenced formal parameter
164 #pragma warning ( disable : 4512 ) //assignment operator could not be generated
165 
166 #include <memory>
167 
168 // Memory allocation
169 #if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC) && (_MSC_VER >= 1200) && !defined(_ARM_)
170 #include <malloc.h>
171 #include <crtdbg.h>
172 #include "OdError.h"
173 
174 inline void* operator new(size_t nSize, const char* /*LPCSTR*/ lpszFileName, int nLine)
175 {
176  void* pRes = _malloc_dbg(nSize, _NORMAL_BLOCK, lpszFileName, nLine);
177  if(!pRes) throw OdError(eOutOfMemory);
178  return pRes;
179 }
180 
181 inline void operator delete(void * pMem, const char* /*LPCSTR lpszFileName*/, int /*nLine*/)
182 {
183  _free_dbg(pMem, _NORMAL_BLOCK);
184 }
185 
186 #ifndef DEBUG_NEW
187 #define DEBUG_NEW new(__FILE__, __LINE__)
188 #endif
189 
190 #else //#ifdef _CRTDBG_MAP_ALLOC
191 
192 //inline void* operator new(size_t nSize) { return Oda::mem_alloc(nSize); }
193 //inline void operator delete(void* pMem) { Oda::mem_free(pMem); }
194 
195 #endif //_CRTDBG_MAP_ALLOC
196 #pragma warning (pop)
197 
198 #include <new.h>
199 
200 #endif // _MSC_VER
201 
202 // Cause Compiler to print a message to output console with File and Line# for
203 // Double-Click response
204 // Ex:
205 // #pragma MARKMESSAGE("Warning! Implementation is incorrect!")
206 #ifndef MARKMESSAGE
207  #if defined(_MSC_VER)
208  #pragma warning (disable:4081)
209  #endif
210  #if defined(_MSC_VER) && defined(_DEBUG)
211  #define _schSTR(x) #x
212  #define _schSTR2(x) _schSTR(x)
213  #define MARKMESSAGE(desc) message(__FILE__ "(" _schSTR2(__LINE__) "): " #desc)
214  #else
215  #if defined(__sun) && !defined(__GNUC__)
216  #define MARKMESSAGE(desc) dummy_pragma
217  #else
218  #define MARKMESSAGE(desc)
219  #endif
220  #endif
221 #endif // MARKMESSAGE
222 
223 #if defined(OD_DIAGNOSTICS) && defined(_MSC_VER) && defined(_DEBUG) && (_MSC_VER < 1400)
224 #pragma function(memcpy)
225 inline void * memcpy(void * dest, const void * src, size_t size)
226 { // Memory blocks must not overlap
227  ODA_ASSERT(((char*)dest > (char*)src && (char*)dest >= ((char*)src + size)) ||
228  ((char*)dest < (char*)src && ((char*)dest + size) <= (char*)src) ||
229  dest == src );
230  return memmove(dest, src, size);
231 }
232 #endif // _MSC_VER
233 
234 //FELIX_CHANGE_BEGIN
235 #if defined(WIN32) || defined(_WIN32_WCE) || defined(__MWERKS__)
236  #include <math.h>
237 #endif
238 
239 #include <complex>
240 //FELIX_CHANGE_END
241 
242 // _MSC_VER default behaviour is 'If both parameters of atan2 are 0, the function returns 0'
243 // Other compilers (e.g. BB6) can throw exception.
244 #if defined(__BORLANDC__) || defined(__BCPLUSPLUS__)
245 #include <math.h>
246  inline double OD_ATAN2(double y, double x)
247  {
248  if (x == 0. && y == 0.)
249  return 0.;
250  return atan2(y,x);
251  }
252 
253 #elif defined(_DEBUG) && defined(_MSC_VER) && defined(ODA_LINT)
254  FIRSTDLL_EXPORT double OD_ATAN2(double y, double x);
255  #define atan2(x, y) Do_not_use_atan2_directly__Use__OD_ATAN2_instead
256 
257 #else
258  #define OD_ATAN2(y,x) (atan2(y,x)) // Safe for MSVC and hope for others. CoreRegression test should show.
259 #endif
260 
261 
262 #if defined(ODA_LINT) && defined(_DEBUG)
263  FIRSTDLL_EXPORT double OD_ASIN(double a);
264  #define asin(a) Do_not_use_asin_directly__Use__OD_ASIN_instead
265 
266  FIRSTDLL_EXPORT double OD_ACOS(double a);
267  #define acos(a) Do_not_use_acos_directly__Use__OD_ACOS_instead
268 #else
269 #define OD_ASIN(a) asin(a)
270 #define OD_ACOS(a) acos(a)
271 #endif
272 
273 #ifdef _MSC_VER
274 #define OD_WARNING_PUSH warning(push)
275 #define OD_WARNING_DISABLE(number) warning(disable : number)
276 #define OD_WARNING_POP warning(pop)
277 #define OD_WARNING_SUPPRESS(number) warning(suppress : number)
278 #else
279  #if defined(__sun) && !defined(__GNUC__)
280  #define OD_WARNING_PUSH dummy_pragma
281  #define OD_WARNING_DISABLE(number) dummy_pragma
282  #define OD_WARNING_POP dummy_pragma
283  #define OD_WARNING_SUPPRESS(number) dummy_pragma
284  #else
285  #define OD_WARNING_PUSH
286  #define OD_WARNING_DISABLE(number)
287  #define OD_WARNING_POP
288  #define OD_WARNING_SUPPRESS(number)
289  #endif
290 #endif
291 
292 #endif // __DEBUG_STUFF__INCLUDED
293 
294 
void FIRSTDLL_EXPORT OdAssert(const char *expresssion, const char *filename, int nLineNo)
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
#define OD_ATAN2(y, x)
Definition: DebugStuff.h:258
#define OD_ACOS(a)
Definition: DebugStuff.h:270
void oda_noop(void)
Definition: DebugStuff.h:48
#define OD_ASIN(a)
Definition: DebugStuff.h:269
void FIRSTDLL_EXPORT OdTrace(const OdChar *szFormat,...)
wchar_t OdChar
#define FIRSTDLL_EXPORT
Definition: RootExport.h:39
GLsizeiptr size
Definition: gles2_ext.h:182
GLfloat x
Definition: gles2_ext.h:314
GLfloat GLfloat y
Definition: gles2_ext.h:316