]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/debug.h
Add wxRTTI for the wxFileSystemWatcherEvent class
[wxWidgets.git] / interface / wx / debug.h
CommitLineData
23324ae1 1/////////////////////////////////////////////////////////////////////////////
7d9550df 2// Name: wx/debug.h
e54c96f1 3// Purpose: interface of global functions
7c913512
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
7c913512
FM
7/////////////////////////////////////////////////////////////////////////////
8
b21126db 9/** @addtogroup group_funcmacro_debug */
9579c1d7 10//@{
23324ae1 11
975dc691
VZ
12/**
13 Exits the program immediately.
14
15 This is a simple wrapper for the standard abort() function which is not
16 available under all platforms (currently only Windows CE doesn't provide
17 it).
18
19 @since 2.9.4
20 */
21void wxAbort();
22
657a8a35
VZ
23/**
24 @def wxDEBUG_LEVEL
25
26 Preprocessor symbol defining the level of debug support available.
27
7d9550df
VZ
28 This symbol is defined to 1 by default meaning that asserts are compiled in
29 (although they may be disabled by a call to wxDisableAsserts()). You may
30 predefine it as 0 prior to including any wxWidgets headers to omit the
31 calls to wxASSERT() and related macros entirely in your own code and you
32 may also predefine it as 0 when building wxWidgets to also avoid including
33 any asserts in wxWidgets itself.
34
35 Alternatively, you may predefine it as 2 to include wxASSERT_LEVEL_2() and
36 similar macros which are used for asserts which have non-trivial run-time
37 costs and so are disabled by default.
38
39 @since 2.9.1
657a8a35
VZ
40
41 @header{wx/debug.h}
42 */
43#define wxDEBUG_LEVEL
44
7d9550df
VZ
45/**
46 @def __WXDEBUG__
47
48 Compatibility macro indicating presence of debug support.
49
50 This symbol is defined if wxDEBUG_LEVEL is greater than 0 and undefined
51 otherwise.
52
53 @header{wx/debug.h}
54 */
55#define __WXDEBUG__
56
657a8a35
VZ
57/**
58 Type for the function called in case of assert failure.
59
60 @see wxSetAssertHandler()
61 */
62typedef void (*wxAssertHandler_t)(const wxString& file,
63 int line,
64 const wxString& func,
65 const wxString& cond,
66 const wxString& msg);
67
23324ae1 68/**
9579c1d7
BP
69 Assert macro. An error message will be generated if the condition is @false in
70 debug mode, but nothing will be done in the release build.
9f1ce8bf 71
9579c1d7
BP
72 Please note that the condition in wxASSERT() should have no side effects
73 because it will not be executed in release mode at all.
7c913512 74
9f1ce8bf
FM
75 This macro should be used to catch (in debug builds) logical errors done
76 by the programmer.
77
9579c1d7 78 @see wxASSERT_MSG(), wxCOMPILE_TIME_ASSERT()
23324ae1 79
9579c1d7 80 @header{wx/debug.h}
23324ae1 81*/
9579c1d7 82#define wxASSERT( condition )
23324ae1 83
657a8a35
VZ
84/**
85 Assert macro for expensive run-time checks.
86
87 This macro does nothing unless wxDEBUG_LEVEL is 2 or more and is meant to
88 be used for the assertions with noticeable performance impact and which,
89 hence, should be disabled during run-time.
90
91 If wxDEBUG_LEVEL is 2 or more, it becomes the same as wxASSERT().
92
93 @header{wx/debug.h}
94 */
95#define wxASSERT_LEVEL_2( condition )
96
97/**
98 Assert macro with a custom message for expensive run-time checks.
99
100 If wxDEBUG_LEVEL is 2 or more, this is the same as wxASSERT_MSG(),
101 otherwise it doesn't do anything at all.
102
103 @see wxASSERT_LEVEL_2()
104
105 @header{wx/debug.h}
106 */
107#define wxASSERT_LEVEL_2_MSG( condition, msg)
108
109
23324ae1 110/**
76e9224e
FM
111 This macro results in a @ref wxCOMPILE_TIME_ASSERT "compile time assertion failure"
112 if the size of the given @c type is less than @c size bits.
9579c1d7 113
9f1ce8bf
FM
114 This macro should be used to catch (in debug builds) logical errors done
115 by the programmer.
116
23324ae1 117 You may use it like this, for example:
4cc4bfaf 118
23324ae1
FM
119 @code
120 // we rely on the int being able to hold values up to 2^32
9579c1d7 121 wxASSERT_MIN_BITSIZE(int, 32);
7c913512 122
9579c1d7
BP
123 // can't work with the platforms using UTF-8 for wchar_t
124 wxASSERT_MIN_BITSIZE(wchar_t, 16);
23324ae1 125 @endcode
9579c1d7
BP
126
127 @header{wx/debug.h}
23324ae1 128*/
9579c1d7 129#define wxASSERT_MIN_BITSIZE( type, size )
23324ae1
FM
130
131/**
76e9224e
FM
132 Assert macro with message.
133 An error message will be generated if the condition is @false.
7c913512 134
9f1ce8bf
FM
135 This macro should be used to catch (in debug builds) logical errors done
136 by the programmer.
137
e54c96f1 138 @see wxASSERT(), wxCOMPILE_TIME_ASSERT()
23324ae1 139
9579c1d7 140 @header{wx/debug.h}
23324ae1 141*/
9579c1d7 142#define wxASSERT_MSG( condition, message )
23324ae1
FM
143
144/**
9579c1d7 145 Checks that the condition is @true, returns with the given return value if
76e9224e 146 not (stops execution in debug mode). This check is done even in release mode.
7c913512 147
9f1ce8bf
FM
148 This macro should be used to catch (both in debug and release builds) logical
149 errors done by the programmer.
150
9579c1d7 151 @header{wx/debug.h}
23324ae1 152*/
9579c1d7 153#define wxCHECK( condition, retValue )
23324ae1
FM
154
155/**
9579c1d7 156 Checks that the condition is @true, returns with the given return value if
76e9224e 157 not (stops execution in debug mode). This check is done even in release mode.
9579c1d7
BP
158
159 This macro may be only used in non-void functions, see also wxCHECK_RET().
160
9f1ce8bf
FM
161 This macro should be used to catch (both in debug and release builds) logical
162 errors done by the programmer.
163
9579c1d7 164 @header{wx/debug.h}
23324ae1 165*/
9579c1d7 166#define wxCHECK_MSG( condition, retValue, message )
23324ae1
FM
167
168/**
9579c1d7
BP
169 Checks that the condition is @true, and returns if not (stops execution
170 with the given error message in debug mode). This check is done even in
171 release mode.
172
173 This macro should be used in void functions instead of wxCHECK_MSG().
174
9f1ce8bf
FM
175 This macro should be used to catch (both in debug and release builds) logical
176 errors done by the programmer.
177
9579c1d7 178 @header{wx/debug.h}
23324ae1 179*/
9579c1d7 180#define wxCHECK_RET( condition, message )
23324ae1
FM
181
182/**
9579c1d7
BP
183 Checks that the condition is @true, and if not, it will wxFAIL() and
184 execute the given @c operation if it is not. This is a generalisation of
185 wxCHECK() and may be used when something else than just returning from the
186 function must be done when the @c condition is @false. This check is done
187 even in release mode.
188
9f1ce8bf
FM
189 This macro should be used to catch (both in debug and release builds) logical
190 errors done by the programmer.
191
9579c1d7 192 @header{wx/debug.h}
23324ae1 193*/
9579c1d7 194#define wxCHECK2(condition, operation)
23324ae1
FM
195
196/**
9579c1d7
BP
197 This is the same as wxCHECK2(), but wxFAIL_MSG() with the specified
198 @c message is called instead of wxFAIL() if the @c condition is @false.
199
9f1ce8bf
FM
200 This macro should be used to catch (both in debug and release builds) logical
201 errors done by the programmer.
202
9579c1d7 203 @header{wx/debug.h}
23324ae1 204*/
9579c1d7 205#define wxCHECK2_MSG( condition, operation, message )
23324ae1
FM
206
207/**
9579c1d7
BP
208 Using wxCOMPILE_TIME_ASSERT() results in a compilation error if the
209 specified @c condition is @false. The compiler error message should include
210 the @c message identifier - please note that it must be a valid C++
211 identifier and not a string unlike in the other cases.
212
23324ae1
FM
213 This macro is mostly useful for testing the expressions involving the
214 @c sizeof operator as they can't be tested by the preprocessor but it is
215 sometimes desirable to test them at the compile time.
9579c1d7
BP
216
217 Note that this macro internally declares a struct whose name it tries to
218 make unique by using the @c __LINE__ in it but it may still not work if you
23324ae1
FM
219 use it on the same line in two different source files. In this case you may
220 either change the line in which either of them appears on or use the
e54c96f1 221 wxCOMPILE_TIME_ASSERT2() macro.
9579c1d7
BP
222
223 Also note that Microsoft Visual C++ has a bug which results in compiler
224 errors if you use this macro with 'Program Database For Edit And Continue'
225 (@c /ZI) option, so you shouldn't use it ('Program Database' (@c /Zi) is ok
226 though) for the code making use of this macro.
7c913512 227
9f1ce8bf
FM
228 This macro should be used to catch misconfigurations at compile-time.
229
e54c96f1 230 @see wxASSERT_MSG(), wxASSERT_MIN_BITSIZE()
9579c1d7
BP
231
232 @header{wx/debug.h}
233*/
234#define wxCOMPILE_TIME_ASSERT( condition, message )
235
236/**
237 This macro is identical to wxCOMPILE_TIME_ASSERT() except that it allows
238 you to specify a unique @c name for the struct internally defined by this
239 macro to avoid getting the compilation errors described for
240 wxCOMPILE_TIME_ASSERT().
241
9f1ce8bf
FM
242 This macro should be used to catch misconfigurations at compile-time.
243
9579c1d7
BP
244 @header{wx/debug.h}
245*/
246#define wxCOMPILE_TIME_ASSERT2(condition, message, name)
247
657a8a35
VZ
248/**
249 Disable the condition checks in the assertions.
250
251 This is the same as calling wxSetAssertHandler() with @NULL handler.
7d9550df
VZ
252
253 @since 2.9.0
254
255 @header{wx/debug.h}
657a8a35
VZ
256 */
257void wxDisableAsserts();
258
7d9550df
VZ
259/**
260 @def wxDISABLE_ASSERTS_IN_RELEASE_BUILD
261
262 Use this macro to disable asserts in release build when not using
e4431849 263 wxIMPLEMENT_APP().
7d9550df
VZ
264
265 By default, assert message boxes are suppressed in release build by
e4431849 266 wxIMPLEMENT_APP() which uses this macro. If you don't use wxIMPLEMENT_APP()
7d9550df
VZ
267 because your application initializes wxWidgets directly (e.g. calls
268 wxEntry() or wxEntryStart() itself) but still want to suppress assert
269 notifications in release build you need to use this macro directly.
270
271 @see wxDISABLE_DEBUG_SUPPORT()
272
273 @since 2.9.1
274
275 @header{wx/debug.h}
276 */
277#define wxDISABLE_ASSERTS_IN_RELEASE_BUILD() wxDisableAsserts()
278
9579c1d7 279/**
9f1ce8bf
FM
280 Will always generate an assert error if this code is reached (in debug mode).
281 Note that you don't have to (and cannot) use brackets when invoking this
282 macro:
283
284 @code
285 if (...some condition...) {
286 wxFAIL;
287 }
288 @endcode
289
290 This macro should be used to catch (in debug builds) logical errors done
291 by the programmer.
9579c1d7
BP
292
293 @see wxFAIL_MSG()
294
295 @header{wx/debug.h}
296*/
9f1ce8bf 297#define wxFAIL
9579c1d7
BP
298
299/**
300 Will always generate an assert error with specified message if this code is
301 reached (in debug mode).
302
001f1f56 303 This macro is useful for marking "unreachable" code areas, for example it
9579c1d7
BP
304 may be used in the "default:" branch of a switch statement if all possible
305 cases are processed above.
306
9f1ce8bf
FM
307 This macro should be used to catch (in debug builds) logical errors done
308 by the programmer.
309
9579c1d7
BP
310 @see wxFAIL()
311
312 @header{wx/debug.h}
313*/
314#define wxFAIL_MSG( message )
315
316/**
317 Returns @true if the program is running under debugger, @false otherwise.
318
319 Please note that this function is currently only implemented for Win32 and
2415cf67 320 always returns @false elsewhere.
9579c1d7
BP
321
322 @header{wx/debug.h}
23324ae1 323*/
9579c1d7
BP
324bool wxIsDebuggerRunning();
325
326/**
657a8a35
VZ
327 Sets the function to be called in case of assertion failure.
328
329 The default assert handler forwards to wxApp::OnAssertFailure() whose
330 default behaviour is, in turn, to show the standard assertion failure
331 dialog if a wxApp object exists or shows the same dialog itself directly
332 otherwise.
333
334 While usually it is enough -- and more convenient -- to just override
335 OnAssertFailure(), to handle all assertion failures, including those
336 occurring even before wxApp object creation of after its destruction you
337 need to provide your assertion handler function.
338
339 This function also provides a simple way to disable all asserts: simply
340 pass @NULL pointer to it. Doing this will result in not even evaluating
341 assert conditions at all, avoiding almost all run-time cost of asserts.
9579c1d7 342
657a8a35
VZ
343 Notice that this function is not MT-safe, so you should call it before
344 starting any other threads.
345
346 The return value of this function is the previous assertion handler. It can
347 be called after any pre-processing by your handler and can also be restored
348 later if you uninstall your handler.
349
350 @param handler
351 The function to call in case of assertion failure or @NULL.
352 @return
353 The previous assert handler which is not @NULL by default but could be
354 @NULL if it had been previously set to this value using this function.
9579c1d7 355
7d9550df
VZ
356 @since 2.9.0
357
9579c1d7 358 @header{wx/debug.h}
657a8a35
VZ
359 */
360wxAssertHandler_t wxSetAssertHandler(wxAssertHandler_t handler);
9579c1d7 361
7d9550df
VZ
362/**
363 Reset the assert handler to default function which shows a message box when
364 an assert happens.
365
366 This can be useful for the applications compiled in release build (with @c
367 NDEBUG defined) for which the asserts are by default disabled: if you wish
368 to enable them even in this case you need to call this function.
369
370 @since 2.9.1
371
372 @header{wx/debug.h}
373 */
374void wxSetDefaultAssertHandler();
375
9579c1d7 376/**
156c7057
VZ
377 Generate a debugger exception meaning that the control is passed to the
378 debugger if one is attached to the process.
379
380 Otherwise the program just terminates abnormally.
381
382 If @c wxDEBUG_LEVEL is 0 (which is not the default) this function does
383 nothing.
9579c1d7
BP
384
385 @header{wx/debug.h}
386*/
387void wxTrap();
388
389//@}
23324ae1 390