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