- #endif /* !WXDEBUG */
-#endif /* __WXDEBUG__ */
-
-/* ---------------------------------------------------------------------------- */
-/* Debugging macros */
-/* */
-/* All debugging macros rely on ASSERT() which in turn calls user-defined */
-/* OnAssert() function. To keep things simple, it's called even when the */
-/* expression is TRUE (i.e. everything is ok) and by default does nothing: just */
-/* returns the same value back. But if you redefine it to do something more sexy */
-/* (popping up a message box in your favourite GUI, sending you e-mail or */
-/* whatever) it will affect all ASSERTs, FAILs and CHECKs in your code. */
-/* */
-/* Warning: if you don't like advice on programming style, don't read */
-/* further! ;-) */
-/* */
-/* Extensive use of these macros is recommended! Remember that ASSERTs are */
-/* disabled in final build (without __WXDEBUG__ defined), so they add strictly */
-/* nothing to your program's code. On the other hand, CHECK macros do stay */
-/* even in release builds, but in general are not much of a burden, while */
-/* a judicious use of them might increase your program's stability. */
-/* ---------------------------------------------------------------------------- */
-
-/* Macros which are completely disabled in 'release' mode */
-/* */
-/* NB: these functions are implemented in src/common/appcmn.cpp */
-#if defined(__cplusplus) && defined(__WXDEBUG__)
- /*
- this function may be redefined to do something non trivial and is called
- whenever one of debugging macros fails (i.e. condition is false in an
- assertion)
-
- parameters:
- szFile and nLine - file name and line number of the ASSERT
- szMsg - optional message explaining the reason
- */
- extern void WXDLLIMPEXP_BASE wxOnAssert(const wxChar *szFile,
- int nLine,
- const wxChar *szCond,
- const wxChar *szMsg = NULL);
-
- /* call this function to break into the debugger unconditionally (assuming */
- /* the program is running under debugger, of course) */
- extern void WXDLLIMPEXP_BASE wxTrap();
-
- /* helper function used to implement wxASSERT and wxASSERT_MSG */
- /* */
- /* note using "int" and not "bool" for cond to avoid VC++ warnings about */
- /* implicit conversions when doing "wxAssert( pointer )" and also use of */
- /* "!!cond" below to ensure that everything is converted to int */
- extern void WXDLLIMPEXP_BASE wxAssert(int cond,
- const wxChar *szFile,
- int nLine,
- const wxChar *szCond,
- const wxChar *szMsg = NULL) ;
-
- /* generic assert macro */
- #define wxASSERT(cond) wxAssert(!!(cond), __TFILE__, __LINE__, _T(#cond))
-
- /* assert with additional message explaining it's cause */
- #define wxASSERT_MSG(cond, msg) \
- wxAssert(!!(cond), __TFILE__, __LINE__, _T(#cond), msg)
-
- /* an assert helper used to avoid warning when testing constant expressions, */
- /* i.e. wxASSERT( sizeof(int) == 4 ) can generate a compiler warning about */
- /* expression being always true, but not using */
- /* wxASSERT( wxAssertIsEqual(sizeof(int), 4) ) */
- /* */
- /* NB: this is made obsolete by wxCOMPILE_TIME_ASSERT() and shouldn't be */
- /* used any longer */
- extern bool WXDLLIMPEXP_BASE wxAssertIsEqual(int x, int y);
+ #endif // !WXDEBUG
+#endif // __WXDEBUG__
+
+// ----------------------------------------------------------------------------
+// Handling assertion failures
+// ----------------------------------------------------------------------------
+
+/*
+ Type for the function called in case of assert failure, see
+ wxSetAssertHandler().
+ */
+typedef void (*wxAssertHandler_t)(const wxString& file,
+ int line,
+ const wxString& func,
+ const wxString& cond,
+ const wxString& msg);
+
+#if wxDEBUG_LEVEL
+
+// the global assert handler function, if it is NULL asserts don't check their
+// conditions
+extern WXDLLIMPEXP_DATA_BASE(wxAssertHandler_t) wxTheAssertHandler;
+
+/*
+ Sets the function to be called in case of assertion failure.
+
+ The default assert handler forwards to wxApp::OnAssertFailure() whose
+ default behaviour is, in turn, to show the standard assertion failure
+ dialog if a wxApp object exists or shows the same dialog itself directly
+ otherwise.
+
+ While usually it is enough -- and more convenient -- to just override
+ OnAssertFailure(), to handle all assertion failures, including those
+ occurring even before wxApp object creation or after its destruction you
+ need to provide your assertion handler function.
+
+ This function also provides a simple way to disable all asserts: simply
+ pass NULL pointer to it. Doing this will result in not even evaluating
+ assert conditions at all, avoiding almost all run-time cost of asserts.
+
+ Notice that this function is not MT-safe, so you should call it before
+ starting any other threads.
+
+ The return value of this function is the previous assertion handler. It can
+ be called after any pre-processing by your handler and can also be restored
+ later if you uninstall your handler.
+ */
+inline wxAssertHandler_t wxSetAssertHandler(wxAssertHandler_t handler)
+{
+ const wxAssertHandler_t old = wxTheAssertHandler;
+ wxTheAssertHandler = handler;
+ return old;
+}
+
+/*
+ Reset the default assert handler.
+
+ This may be used to enable asserts, which are disabled by default in this
+ case, for programs built in release build (NDEBUG defined).
+ */
+extern void WXDLLIMPEXP_BASE wxSetDefaultAssertHandler();
+
+#else // !wxDEBUG_LEVEL
+
+// provide empty stubs in case assertions are completely disabled
+//
+// NB: can't use WXUNUSED() here as we're included from wx/defs.h before it is
+// defined
+inline wxAssertHandler_t wxSetAssertHandler(wxAssertHandler_t /* handler */)
+{
+ return NULL;
+}
+
+inline void wxSetDefaultAssertHandler() { }
+
+#endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL
+
+// simply a synonym for wxSetAssertHandler(NULL)
+inline void wxDisableAsserts() { wxSetAssertHandler(NULL); }
+
+/*
+ A macro which disables asserts for applications compiled in release build.
+
+ By default, IMPLEMENT_APP (or rather IMPLEMENT_WXWIN_MAIN) disable the
+ asserts in the applications compiled in the release build by calling this.
+ It does nothing if NDEBUG is not defined.
+ */
+#ifdef NDEBUG
+ #define wxDISABLE_ASSERTS_IN_RELEASE_BUILD() wxDisableAsserts()