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