- #endif /* !WXDEBUG */
-#endif /* __WXDEBUG__ */
-
-#ifndef __WXFUNCTION__
- /* TODO: add more compilers supporting __FUNCTION__ */
- #if defined(__DMC__)
- /*
- __FUNCTION__ happens to be not defined within class members
- http://www.digitalmars.com/drn-bin/wwwnews?c%2B%2B.beta/485
- */
- #define __WXFUNCTION__ (NULL)
- #elif defined(__GNUC__) || \
- (defined(_MSC_VER) && _MSC_VER >= 1300) || \
- defined(__FUNCTION__)
- #define __WXFUNCTION__ __FUNCTION__
- #else
- /* still define __WXFUNCTION__ to avoid #ifdefs elsewhere */
- #define __WXFUNCTION__ (NULL)
- #endif
-#endif /* __WXFUNCTION__ already defined */
-
-/* ---------------------------------------------------------------------------- */
-/* Debugging macros */
-/* */
-/* All debugging macros rely on ASSERT() which in turn calls the 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 is called whenever one of debugging macros fails (i.e.
- condition is false in an assertion). To customize its behaviour, override
- wxApp::OnAssert().
-
- Parameters:
- szFile and nLine - file name and line number of the ASSERT
- szFunc - function name of the ASSERT, may be NULL (NB: ASCII)
- szCond - text form of the condition which failed
- szMsg - optional message explaining the reason
- */
- extern void WXDLLIMPEXP_BASE wxOnAssert(const wxChar *szFile,
- int nLine,
- const char *szFunc,
- 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();
-
- /* generic assert macro */
- #define wxASSERT(cond) wxASSERT_MSG(cond, NULL)
-
-
- /* assert with additional message explaining its cause */
-
- /* compilers can give a warning (such as "possible unwanted ;") when using */
- /* the default definition of wxASSERT_MSG so we provide an alternative */
- #if defined(__MWERKS__)
- #define wxASSERT_MSG(cond, msg) \
- if ( cond ) \
- {} \
- else \
- wxOnAssert(__TFILE__, __LINE__, __WXFUNCTION__, _T(#cond), msg)
- #else
- #define wxASSERT_MSG(cond, msg) \
- if ( cond ) \
- ; \
- else \
- wxOnAssert(__TFILE__, __LINE__, __WXFUNCTION__, _T(#cond), msg)
- #endif
-
- /* special form of assert: always triggers it (in debug mode) */
- #define wxFAIL wxFAIL_MSG(NULL)
-
- /* FAIL with some message */
- #define wxFAIL_MSG(msg) wxFAIL_COND_MSG("wxAssertFailure", msg)
-
- /* FAIL with some message and a condition */
- #define wxFAIL_COND_MSG(cond, msg) \
- wxOnAssert(__TFILE__, __LINE__, __WXFUNCTION__, _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 should no */
- /* longer be used. */
- 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()