]>
Commit | Line | Data |
---|---|---|
23324ae1 | 1 | ///////////////////////////////////////////////////////////////////////////// |
7c913512 | 2 | // Name: debug.h |
e54c96f1 | 3 | // Purpose: interface of global functions |
7c913512 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9579c1d7 BP |
9 | /** @ingroup group_funcmacro_debug */ |
10 | //@{ | |
23324ae1 FM |
11 | |
12 | /** | |
9579c1d7 BP |
13 | Assert macro. An error message will be generated if the condition is @false in |
14 | debug mode, but nothing will be done in the release build. | |
15 | Please note that the condition in wxASSERT() should have no side effects | |
16 | because it will not be executed in release mode at all. | |
7c913512 | 17 | |
9579c1d7 | 18 | @see wxASSERT_MSG(), wxCOMPILE_TIME_ASSERT() |
23324ae1 | 19 | |
9579c1d7 | 20 | @header{wx/debug.h} |
23324ae1 | 21 | */ |
9579c1d7 | 22 | #define wxASSERT( condition ) |
23324ae1 FM |
23 | |
24 | /** | |
76e9224e FM |
25 | This macro results in a @ref wxCOMPILE_TIME_ASSERT "compile time assertion failure" |
26 | if the size of the given @c type is less than @c size bits. | |
9579c1d7 | 27 | |
23324ae1 | 28 | You may use it like this, for example: |
4cc4bfaf | 29 | |
23324ae1 FM |
30 | @code |
31 | // we rely on the int being able to hold values up to 2^32 | |
9579c1d7 | 32 | wxASSERT_MIN_BITSIZE(int, 32); |
7c913512 | 33 | |
9579c1d7 BP |
34 | // can't work with the platforms using UTF-8 for wchar_t |
35 | wxASSERT_MIN_BITSIZE(wchar_t, 16); | |
23324ae1 | 36 | @endcode |
9579c1d7 BP |
37 | |
38 | @header{wx/debug.h} | |
23324ae1 | 39 | */ |
9579c1d7 | 40 | #define wxASSERT_MIN_BITSIZE( type, size ) |
23324ae1 FM |
41 | |
42 | /** | |
76e9224e FM |
43 | Assert macro with message. |
44 | An error message will be generated if the condition is @false. | |
7c913512 | 45 | |
e54c96f1 | 46 | @see wxASSERT(), wxCOMPILE_TIME_ASSERT() |
23324ae1 | 47 | |
9579c1d7 | 48 | @header{wx/debug.h} |
23324ae1 | 49 | */ |
9579c1d7 | 50 | #define wxASSERT_MSG( condition, message ) |
23324ae1 FM |
51 | |
52 | /** | |
9579c1d7 | 53 | Checks that the condition is @true, returns with the given return value if |
76e9224e | 54 | not (stops execution in debug mode). This check is done even in release mode. |
7c913512 | 55 | |
9579c1d7 | 56 | @header{wx/debug.h} |
23324ae1 | 57 | */ |
9579c1d7 | 58 | #define wxCHECK( condition, retValue ) |
23324ae1 FM |
59 | |
60 | /** | |
9579c1d7 | 61 | Checks that the condition is @true, returns with the given return value if |
76e9224e | 62 | not (stops execution in debug mode). This check is done even in release mode. |
9579c1d7 BP |
63 | |
64 | This macro may be only used in non-void functions, see also wxCHECK_RET(). | |
65 | ||
66 | @header{wx/debug.h} | |
23324ae1 | 67 | */ |
9579c1d7 | 68 | #define wxCHECK_MSG( condition, retValue, message ) |
23324ae1 FM |
69 | |
70 | /** | |
9579c1d7 BP |
71 | Checks that the condition is @true, and returns if not (stops execution |
72 | with the given error message in debug mode). This check is done even in | |
73 | release mode. | |
74 | ||
75 | This macro should be used in void functions instead of wxCHECK_MSG(). | |
76 | ||
77 | @header{wx/debug.h} | |
23324ae1 | 78 | */ |
9579c1d7 | 79 | #define wxCHECK_RET( condition, message ) |
23324ae1 FM |
80 | |
81 | /** | |
9579c1d7 BP |
82 | Checks that the condition is @true, and if not, it will wxFAIL() and |
83 | execute the given @c operation if it is not. This is a generalisation of | |
84 | wxCHECK() and may be used when something else than just returning from the | |
85 | function must be done when the @c condition is @false. This check is done | |
86 | even in release mode. | |
87 | ||
88 | @header{wx/debug.h} | |
23324ae1 | 89 | */ |
9579c1d7 | 90 | #define wxCHECK2(condition, operation) |
23324ae1 FM |
91 | |
92 | /** | |
9579c1d7 BP |
93 | This is the same as wxCHECK2(), but wxFAIL_MSG() with the specified |
94 | @c message is called instead of wxFAIL() if the @c condition is @false. | |
95 | ||
96 | @header{wx/debug.h} | |
23324ae1 | 97 | */ |
9579c1d7 | 98 | #define wxCHECK2_MSG( condition, operation, message ) |
23324ae1 FM |
99 | |
100 | /** | |
9579c1d7 BP |
101 | Using wxCOMPILE_TIME_ASSERT() results in a compilation error if the |
102 | specified @c condition is @false. The compiler error message should include | |
103 | the @c message identifier - please note that it must be a valid C++ | |
104 | identifier and not a string unlike in the other cases. | |
105 | ||
23324ae1 FM |
106 | This macro is mostly useful for testing the expressions involving the |
107 | @c sizeof operator as they can't be tested by the preprocessor but it is | |
108 | sometimes desirable to test them at the compile time. | |
9579c1d7 BP |
109 | |
110 | Note that this macro internally declares a struct whose name it tries to | |
111 | make unique by using the @c __LINE__ in it but it may still not work if you | |
23324ae1 FM |
112 | use it on the same line in two different source files. In this case you may |
113 | either change the line in which either of them appears on or use the | |
e54c96f1 | 114 | wxCOMPILE_TIME_ASSERT2() macro. |
9579c1d7 BP |
115 | |
116 | Also note that Microsoft Visual C++ has a bug which results in compiler | |
117 | errors if you use this macro with 'Program Database For Edit And Continue' | |
118 | (@c /ZI) option, so you shouldn't use it ('Program Database' (@c /Zi) is ok | |
119 | though) for the code making use of this macro. | |
7c913512 | 120 | |
e54c96f1 | 121 | @see wxASSERT_MSG(), wxASSERT_MIN_BITSIZE() |
9579c1d7 BP |
122 | |
123 | @header{wx/debug.h} | |
124 | */ | |
125 | #define wxCOMPILE_TIME_ASSERT( condition, message ) | |
126 | ||
127 | /** | |
128 | This macro is identical to wxCOMPILE_TIME_ASSERT() except that it allows | |
129 | you to specify a unique @c name for the struct internally defined by this | |
130 | macro to avoid getting the compilation errors described for | |
131 | wxCOMPILE_TIME_ASSERT(). | |
132 | ||
133 | @header{wx/debug.h} | |
134 | */ | |
135 | #define wxCOMPILE_TIME_ASSERT2(condition, message, name) | |
136 | ||
137 | /** | |
138 | Will always generate an assert error if this code is reached (in debug | |
139 | mode). | |
140 | ||
141 | @see wxFAIL_MSG() | |
142 | ||
143 | @header{wx/debug.h} | |
144 | */ | |
145 | #define wxFAIL() | |
146 | ||
147 | /** | |
148 | Will always generate an assert error with specified message if this code is | |
149 | reached (in debug mode). | |
150 | ||
151 | This macro is useful for marking unreachable" code areas, for example it | |
152 | may be used in the "default:" branch of a switch statement if all possible | |
153 | cases are processed above. | |
154 | ||
155 | @see wxFAIL() | |
156 | ||
157 | @header{wx/debug.h} | |
158 | */ | |
159 | #define wxFAIL_MSG( message ) | |
160 | ||
161 | /** | |
162 | Returns @true if the program is running under debugger, @false otherwise. | |
163 | ||
164 | Please note that this function is currently only implemented for Win32 and | |
165 | Mac builds using CodeWarrior and always returns @false elsewhere. | |
166 | ||
167 | @header{wx/debug.h} | |
23324ae1 | 168 | */ |
9579c1d7 BP |
169 | bool wxIsDebuggerRunning(); |
170 | ||
171 | /** | |
172 | This function is called whenever one of debugging macros fails (i.e. | |
173 | condition is @false in an assertion). It is only defined in the debug mode, | |
174 | in release builds the wxCHECK() failures don't result in anything. | |
175 | ||
176 | To override the default behaviour in the debug builds which is to show the | |
177 | user a dialog asking whether he wants to abort the program, continue or | |
178 | continue ignoring any subsequent assert failures, you may override | |
179 | wxApp::OnAssertFailure() which is called by this function if the global | |
180 | application object exists. | |
181 | ||
182 | @header{wx/debug.h} | |
183 | */ | |
184 | void wxOnAssert( const char* fileName, | |
185 | int lineNumber, | |
186 | const char* function, | |
187 | const char* condition, | |
188 | const char* message = NULL ); | |
189 | ||
190 | /** | |
191 | In debug mode (when @c __WXDEBUG__ is defined) this function generates a | |
192 | debugger exception meaning that the control is passed to the debugger if | |
193 | one is attached to the process. Otherwise the program just terminates | |
194 | abnormally. In release mode this function does nothing. | |
195 | ||
196 | @header{wx/debug.h} | |
197 | */ | |
198 | void wxTrap(); | |
199 | ||
200 | //@} | |
23324ae1 | 201 | |
7fa7088e BP |
202 | |
203 | ||
204 | /** @ingroup group_funcmacro_misc */ | |
205 | //@{ | |
206 | ||
207 | /** | |
208 | This macro expands to the name of the current function if the compiler | |
209 | supports any of @c __FUNCTION__, @c __func__ or equivalent variables or | |
210 | macros or to @NULL if none of them is available. | |
211 | ||
212 | @header{wx/debug.h} | |
213 | */ | |
214 | #define __WXFUNCTION__ | |
215 | ||
216 | //@} | |
217 |