]> git.saurik.com Git - wxWidgets.git/blob - include/wx/debug.h
wxZipFSHandler does not report non-local zip archives as openable anymore
[wxWidgets.git] / include / wx / debug.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/debug.h
3 // Purpose: Misc debug functions and macros
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DEBUG_H_
13 #define _WX_DEBUG_H_
14
15 #include <assert.h>
16
17 #include "wx/wxchar.h"
18
19 // ----------------------------------------------------------------------------
20 /**
21 @name Debugging macros
22
23 All debugging macros rely on ASSERT() which in turn calls user-defined
24 OnAssert() function. To keep things simple, it's called even when the
25 expression is TRUE (i.e. everything is ok) and by default does nothing: just
26 returns the same value back. But if you redefine it to do something more sexy
27 (popping up a message box in your favourite GUI, sending you e-mail or
28 whatever) it will affect all ASSERTs, FAILs and CHECKs in your code.
29 <BR>
30 <BR>
31 <b>Warning</b>: if you don't like advices on programming style, don't read
32 further! ;-)
33 <BR>
34 <BR>
35 Extensive use of these macros is recommended! Remember that ASSERTs are
36 disabled in final (without __WXDEBUG__ defined) build, so they add strictly
37 nothing to your program's code. On the other hand, CHECK macros do stay
38 even in release builds, but in general are not much of a burden, while
39 a judicious use of them might increase your program's stability.
40
41 @memo Debugging macros (replacement for standard assert()) and more.
42 */
43 // ----------------------------------------------------------------------------
44 //@{
45
46 // Use of these suppresses compiler warnings about testing constant expression
47 WXDLLEXPORT_DATA(extern const bool) wxTrue;
48 WXDLLEXPORT_DATA(extern const bool) wxFalse;
49
50 /** @name Macros which are completely disabled in 'release' mode */
51 //@{
52 #ifdef __WXDEBUG__
53 /**
54 this function may be redefined to do something non trivial and is called
55 whenever one of debugging macros fails (i.e. condition is false in an
56 assertion)
57 @param szFile and nLine - file name and line number of the ASSERT
58 szMsg - optional message explaining the reason
59 */
60 void WXDLLEXPORT wxOnAssert(const wxChar *szFile, int nLine, const wxChar *szMsg = (const wxChar *) NULL);
61
62 /// generic assert macro
63 #define wxASSERT(cond) if ( !(cond) ) wxOnAssert(__TFILE__, __LINE__)
64
65 /// assert with additional message explaining it's cause
66 #define wxASSERT_MSG(x, m) if ( !(x) ) wxOnAssert(__TFILE__, __LINE__, m)
67 #else
68 // nothing to do in release modes (hopefully at this moment there are
69 // no more bugs ;-)
70 #define wxASSERT(cond)
71 #define wxASSERT_MSG(x, m)
72 #endif //__WXDEBUG__
73
74 /// special form of assert: always triggers it (in debug mode)
75 #define wxFAIL wxASSERT(wxFalse)
76
77 /// FAIL with some message
78 #define wxFAIL_MSG(msg) wxASSERT_MSG(wxFalse, msg)
79 //@}
80
81 // NB: these macros work also in release mode!
82
83 /**
84 These macros must be used only in invalid situation: for example, an
85 invalid parameter (NULL pointer) is passed to a function. Instead of
86 dereferencing it and causing core dump the function might try using
87 CHECK( p != NULL ) or CHECK( p != NULL, return LogError("p is NULL!!") )
88
89 @name Macros which remain even in 'release' mode
90 */
91 //@{
92 /// check that expression is true, "return" if not (also FAILs in debug mode)
93 #define wxCHECK(x, rc) if (!(x)) {wxFAIL; return rc; }
94 /// as wxCHECK but with a message explaining why we fail
95 #define wxCHECK_MSG(x, rc, msg) if (!(x)) {wxFAIL_MSG(msg); return rc; }
96 /// check that expression is true, perform op if not
97 #define wxCHECK2(x, op) if (!(x)) {wxFAIL; op; }
98 /// as wxCHECK2 but with a message explaining why we fail
99 #define wxCHECK2_MSG(x, op, msg) if (!(x)) {wxFAIL_MSG(msg); op; }
100 /// special form of wxCHECK2: as wxCHECK, but for use in void functions
101 // NB: there is only one form (with msg parameter) and it's intentional:
102 // there is no other way to tell the caller what exactly went wrong
103 // from the void function (of course, the function shouldn't be void
104 // to begin with...)
105 #define wxCHECK_RET(x, msg) if (!(x)) {wxFAIL_MSG(msg); return; }
106 //@}
107
108 //@}
109
110 #endif // _WX_DEBUG_H_