CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
DebugStuff.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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-2022 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#pragma warning (push)
186#pragma warning ( disable : 4100 ) // Unreferenced formal parameter
187#pragma warning ( disable : 4512 ) //assignment operator could not be generated
188
189#include <memory>
190
191// Memory allocation
192#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC) && (_MSC_VER >= 1200) && !defined(_ARM_)
193#include <malloc.h>
194#include <crtdbg.h>
195#include "OdError.h"
196
197inline void* operator new(size_t nSize, const char* /*LPCSTR*/ lpszFileName, int nLine)
198{
199 void* pRes = _malloc_dbg(nSize, _NORMAL_BLOCK, lpszFileName, nLine);
200 if(!pRes) throw OdError(eOutOfMemory);
201 return pRes;
202}
203
204inline void operator delete(void * pMem, const char* /*LPCSTR lpszFileName*/, int /*nLine*/)
205{
206 _free_dbg(pMem, _NORMAL_BLOCK);
207}
208
209#ifndef DEBUG_NEW
210#define DEBUG_NEW new(__FILE__, __LINE__)
211#endif
212
213#else //#ifdef _CRTDBG_MAP_ALLOC
214
215//inline void* operator new(size_t nSize) { return Oda::mem_alloc(nSize); }
216//inline void operator delete(void* pMem) { Oda::mem_free(pMem); }
217
218#endif //_CRTDBG_MAP_ALLOC
219#pragma warning (pop)
220
221#include <new.h>
222
223#endif // _MSC_VER
224
225// Cause Compiler to print a message to output console with File and Line# for
226// Double-Click response
227// Ex:
228// #pragma MARKMESSAGE("Warning! Implementation is incorrect!")
229#ifndef MARKMESSAGE
230 #if defined(_MSC_VER)
231 #pragma warning (disable:4081)
232 #endif
233 #if defined(_MSC_VER) && defined(_DEBUG)
234 #define _schSTR(x) #x
235 #define _schSTR2(x) _schSTR(x)
236 #define MARKMESSAGE(desc) message(__FILE__ "(" _schSTR2(__LINE__) "): " #desc)
237 #else
238 #if defined(__sun) && !defined(__GNUC__)
239 #define MARKMESSAGE(desc) dummy_pragma
240 #else
241 #define MARKMESSAGE(desc)
242 #endif
243 #endif
244#endif // MARKMESSAGE
245
246#if defined(OD_DIAGNOSTICS) && defined(_MSC_VER) && defined(_DEBUG) && (_MSC_VER < 1400)
247#pragma function(memcpy)
248inline void * memcpy(void * dest, const void * src, size_t size)
249{ // Memory blocks must not overlap
250 ODA_ASSERT(((char*)dest > (char*)src && (char*)dest >= ((char*)src + size)) ||
251 ((char*)dest < (char*)src && ((char*)dest + size) <= (char*)src) ||
252 dest == src );
253 return memmove(dest, src, size);
254}
255#endif // _MSC_VER
256
257//FELIX_CHANGE_BEGIN
258#if defined(WIN32) || defined(_WIN32_WCE) || defined(__MWERKS__)
259 #include <math.h>
260#endif
261
262#include <complex>
263//FELIX_CHANGE_END
264
265// _MSC_VER default behaviour is 'If both parameters of atan2 are 0, the function returns 0'
266// Other compilers (e.g. BB6) can throw exception.
267#if defined(__BORLANDC__) || defined(__BCPLUSPLUS__)
268#include <math.h>
269 inline double OD_ATAN2(double y, double x)
270 {
271 if (x == 0. && y == 0.)
272 return 0.;
273 return atan2(y,x);
274 }
275
276#elif defined(_DEBUG) && defined(ODA_LINT) && (!defined(_MSC_VER) || (defined(_MSC_VER) && (_MSC_VER < 1920)))
277 FIRSTDLL_EXPORT double OD_ATAN2(double y, double x);
278 #define atan2(x, y) Do_not_use_atan2_directly__Use__OD_ATAN2_instead
279
280#else
281 #define OD_ATAN2(y,x) (atan2(y,x)) // Safe for MSVC and hope for others. CoreRegression test should show.
282#endif
283
284
285#if defined(ODA_LINT) && defined(_DEBUG) && (_MSC_VER < 1920)
286 FIRSTDLL_EXPORT double OD_ASIN(double a);
287 #define asin(a) Do_not_use_asin_directly__Use__OD_ASIN_instead
288
289 FIRSTDLL_EXPORT double OD_ACOS(double a);
290 #define acos(a) Do_not_use_acos_directly__Use__OD_ACOS_instead
291#else
292#define OD_ASIN(a) asin(a)
293#define OD_ACOS(a) acos(a)
294#endif
295
296#ifdef _MSC_VER
297#define OD_WARNING_PUSH warning(push)
298#define OD_WARNING_DISABLE(number) warning(disable : number)
299#define OD_WARNING_POP warning(pop)
300#define OD_WARNING_SUPPRESS(number) warning(suppress : number)
301#else
302 #if defined(__sun) && !defined(__GNUC__)
303 #define OD_WARNING_PUSH dummy_pragma
304 #define OD_WARNING_DISABLE(number) dummy_pragma
305 #define OD_WARNING_POP dummy_pragma
306 #define OD_WARNING_SUPPRESS(number) dummy_pragma
307 #else
308 #define OD_WARNING_PUSH
309 #define OD_WARNING_DISABLE(number)
310 #define OD_WARNING_POP
311 #define OD_WARNING_SUPPRESS(number)
312 #endif
313#endif
314
315#endif // __DEBUG_STUFF__INCLUDED
316
317
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:281
#define OD_ACOS(a)
Definition: DebugStuff.h:293
void oda_noop(void)
Definition: DebugStuff.h:48
#define OD_ASIN(a)
Definition: DebugStuff.h:292
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