]> git.saurik.com Git - wxWidgets.git/blame - include/wx/debug.h
wxT() for a Spanish(?) debug message
[wxWidgets.git] / include / wx / debug.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
e90c1d2a 2// Name: wx/debug.h
c801d85f
KB
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>
e90c1d2a 9// Licence: wxWindows license
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_DEBUG_H_
13#define _WX_DEBUG_H_
c801d85f
KB
14
15#include <assert.h>
16
9e3d3318
OK
17#include "wx/wxchar.h"
18
c801d85f 19// ----------------------------------------------------------------------------
e90c1d2a
VZ
20/**
21 @name Debugging macros
c801d85f
KB
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
e90c1d2a 27 (popping up a message box in your favourite GUI, sending you e-mail or
c801d85f
KB
28 whatever) it will affect all ASSERTs, FAILs and CHECKs in your code.
29 <BR>
30 <BR>
e90c1d2a 31 <b>Warning</b>: if you don't like advices on programming style, don't read
c801d85f
KB
32 further! ;-)
33 <BR>
34 <BR>
35 Extensive use of these macros is recommended! Remember that ASSERTs are
ea57084d 36 disabled in final (without __WXDEBUG__ defined) build, so they add strictly
c801d85f
KB
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/** @name Macros which are completely disabled in 'release' mode */
47//@{
b2aef89b 48#ifdef __WXDEBUG__
c801d85f
KB
49 /**
50 this function may be redefined to do something non trivial and is called
51 whenever one of debugging macros fails (i.e. condition is false in an
52 assertion)
53 @param szFile and nLine - file name and line number of the ASSERT
54 szMsg - optional message explaining the reason
55 */
9e3d3318 56 void WXDLLEXPORT wxOnAssert(const wxChar *szFile, int nLine, const wxChar *szMsg = (const wxChar *) NULL);
c801d85f
KB
57
58 /// generic assert macro
9e3d3318 59 #define wxASSERT(cond) if ( !(cond) ) wxOnAssert(__TFILE__, __LINE__)
3b1de9c2
JS
60
61#if 0 // defined(__BORLANDC__) && defined(__WIN16__)
62 // Too much text, so make wxASSERT_MSG the same as wxASSERT,
63 // thus removing the text from the program.
9e3d3318 64 #define wxASSERT_MSG(x, m) if ( !(x) ) wxOnAssert(__TFILE__, __LINE__)
3b1de9c2
JS
65#else
66 /// assert with additional message explaining it's cause
9e3d3318 67 #define wxASSERT_MSG(x, m) if ( !(x) ) wxOnAssert(__TFILE__, __LINE__, m)
3b1de9c2
JS
68#endif
69
c801d85f
KB
70#else
71 // nothing to do in release modes (hopefully at this moment there are
72 // no more bugs ;-)
73 #define wxASSERT(cond)
74 #define wxASSERT_MSG(x, m)
ea57084d 75#endif //__WXDEBUG__
c801d85f
KB
76
77 /// special form of assert: always triggers it (in debug mode)
8cb50e4b 78#define wxFAIL wxASSERT(wxFalse)
3b1de9c2
JS
79
80#if 0 // defined(__BORLANDC__) && defined(__WIN16__)
81 // Too much text, so make wxFAIL_MSG the same as wxFAIL,
82 // thus removing the text from the program.
83#define wxFAIL_MSG(msg) wxASSERT(wxFalse)
84#else
c801d85f 85 /// FAIL with some message
8cb50e4b 86#define wxFAIL_MSG(msg) wxASSERT_MSG(wxFalse, msg)
3b1de9c2 87#endif
c801d85f
KB
88//@}
89
90// NB: these macros work also in release mode!
91
e90c1d2a 92/**
c801d85f
KB
93 These macros must be used only in invalid situation: for example, an
94 invalid parameter (NULL pointer) is passed to a function. Instead of
95 dereferencing it and causing core dump the function might try using
96 CHECK( p != NULL ) or CHECK( p != NULL, return LogError("p is NULL!!") )
97
e90c1d2a 98 @name Macros which remain even in 'release' mode
c801d85f
KB
99*/
100//@{
101 /// check that expression is true, "return" if not (also FAILs in debug mode)
1db08b2b
VZ
102#define wxCHECK(x, rc) if (!(x)) {wxFAIL; return rc; }
103 /// as wxCHECK but with a message explaining why we fail
104#define wxCHECK_MSG(x, rc, msg) if (!(x)) {wxFAIL_MSG(msg); return rc; }
c801d85f 105 /// check that expression is true, perform op if not
1db08b2b
VZ
106#define wxCHECK2(x, op) if (!(x)) {wxFAIL; op; }
107 /// as wxCHECK2 but with a message explaining why we fail
108#define wxCHECK2_MSG(x, op, msg) if (!(x)) {wxFAIL_MSG(msg); op; }
109 /// special form of wxCHECK2: as wxCHECK, but for use in void functions
110 // NB: there is only one form (with msg parameter) and it's intentional:
111 // there is no other way to tell the caller what exactly went wrong
112 // from the void function (of course, the function shouldn't be void
113 // to begin with...)
114#define wxCHECK_RET(x, msg) if (!(x)) {wxFAIL_MSG(msg); return; }
c801d85f
KB
115//@}
116
117//@}
118
34138703 119#endif // _WX_DEBUG_H_