]> git.saurik.com Git - wxWidgets.git/commitdiff
new wxASSERT implementation using wxAssert() helper function
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 13 Jun 2002 19:37:43 +0000 (19:37 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 13 Jun 2002 19:37:43 +0000 (19:37 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15827 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/app.tex
docs/latex/wx/function.tex
include/wx/app.h
include/wx/debug.h
src/common/appcmn.cpp

index f9e4e4b40f7c221aecff0c03a494d520189fef8f..aa4c3338fd712472e4c7a10489bcb6e11fea78b0 100644 (file)
@@ -34,6 +34,10 @@ wxBase:
   a function returning a pointer would stop compiling now (but this change
   is not supposed to have any effects on valid code)
 
+- another minor change: wxApp::OnAssert() has a new "cond" argument, you
+  must modify YourApp::OnAssert() signature if you were using it to override
+  the default assert handling.
+
 All (GUI):
 
 ! the event type constants are not constants any more but are dynamically
index fb6340665d6dff8161cf6ddb2034d300895f489d..f082563254c3b16856c4946f061177ecf115c08c 100644 (file)
@@ -238,7 +238,7 @@ Returns 0 under X, and the wParam of the WM\_QUIT message under Windows.
 
 \membersection{wxApp::OnAssert}\label{wxapponassert}
 
-\func{void}{OnAssert}{\param{const wxChar }{*file}, \param{int }{line}, \param{const wxChar }{*msg}}
+\func{void}{OnAssert}{\param{const wxChar }{*file}, \param{int }{line}, \param{const wxChar }{*cond}, \param{const wxChar }{*msg}}
 
 This function is called when an assert failure occurs, i.e. the condition
 specified in \helpref{wxASSERT}{wxassert} macro evaluated to {\tt FALSE}.
@@ -254,6 +254,8 @@ the user to stop the program, continue or ignore all subsequent asserts.
 
 \docparam{line}{the line number in this file where the assert occured}
 
+\docparam{cond}{the condition of the failed assert in string form}
+
 \docparam{msg}{the message specified as argument to 
 \helpref{wxASSERT\_MSG}{wxassertmsg} or \helpref{wxFAIL\_MSG}{wxfailmsg}, will
 be {\tt NULL} if just \helpref{wxASSERT}{wxassert} or \helpref{wxFAIL}{wxfail} 
index 5527dddcf25127b5cedbffe2e66cc5b333e96c82..188d6394a82ec223e1c7090a0ef05040f89e5c33 100644 (file)
@@ -3435,7 +3435,7 @@ compilation error messages if the condition they check fail.
 
 \membersection{::wxOnAssert}\label{wxonassert}
 
-\func{void}{wxOnAssert}{\param{const char *}{fileName}, \param{int}{ lineNumber}, \param{const char *}{msg = NULL}}
+\func{void}{wxOnAssert}{\param{const char *}{fileName}, \param{int}{ lineNumber}, \param{const char *}{cond}, \param{const char *}{msg = NULL}}
 
 This function is called whenever one of debugging macros fails (i.e. condition
 is false in an assertion). It is only defined in the debug mode, in release
index 8a355c415149036d2f2ed19c4954e379871a327b..fc770fe7f55f31be13c90342cb8c5fe8da0a8218 100644 (file)
@@ -330,8 +330,14 @@ public:
     // this function is called when an assert failure occurs, the base class
     // version does the normal processing (i.e. shows the usual assert failure
     // dialog box)
+    //
+    // the arguments are the place where the assert occured, the text of the
+    // assert itself and the user-specified message
 #ifdef __WXDEBUG__
-    virtual void OnAssert(const wxChar *file, int line, const wxChar *msg);
+    virtual void OnAssert(const wxChar *file,
+                          int line,
+                          const wxChar *cond,
+                          const wxChar *msg);
 #endif // __WXDEBUG__
 
     // check that the wxBuildOptions object (constructed in the application
index 436a05ab29b1785872c5c4d91d542a82a6b2515c..ee32d3a0eb57c01fa604d114526f259cb3906cbb 100644 (file)
   */
   extern void WXDLLEXPORT wxOnAssert(const wxChar *szFile,
                                      int nLine,
+                                     const wxChar *szCond,
                                      const wxChar *szMsg = NULL);
 
   // call this function to break into the debugger uncodnitionally (assuming
   // the program is running under debugger, of course)
   extern void WXDLLEXPORT wxTrap();
 
-  /*
-    notice the usage of else at the end of wxASSERT macro: this ensures that
-    the following code
-
-        if ( ... )
-            wxASSERT(...);
-        else
-            ...
-
-    works like expected: if there were no "else", the one in the code above
-    would be matched with a wrong "if"
-  */
+  // 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
+  inline void WXDLLEXPORT wxAssert(int cond,
+                                   const wxChar *szFile,
+                                   int nLine,
+                                   const wxChar *szCond,
+                                   const wxChar *szMsg = NULL)
+  {
+      if ( !cond )
+          wxOnAssert(szFile, nLine, szCond, szMsg);
+  }
 
   // generic assert macro
-  #define wxASSERT(cond) if ( !(cond) ) wxOnAssert(__TFILE__, __LINE__); else
+  #define wxASSERT(cond) wxAssert(!!(cond), __TFILE__, __LINE__, _T(#cond))
 
   // assert with additional message explaining it's cause
   #define wxASSERT_MSG(cond, msg) \
-                    if ( !(cond) ) wxOnAssert(__TFILE__, __LINE__, msg); else
+    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 WXDLLEXPORT wxAssertIsEqual(int x, int y);
 #else
   #define wxTrap()
index 3e0ecff92977985e9598e089c19217f31f80a29b..665e19c19a6d91ae52db5cc70facd489e49043b0 100644 (file)
@@ -424,23 +424,22 @@ void wxTrap()
 
 // show the assert modal dialog
 static
-void ShowAssertDialog(const wxChar *szFile, int nLine, const wxChar *szMsg)
+void ShowAssertDialog(const wxChar *szFile,
+                      int nLine,
+                      const wxChar *szCond,
+                      const wxChar *szMsg)
 {
     // this variable can be set to true to suppress "assert failure" messages
     static bool s_bNoAsserts = FALSE;
 
     wxChar szBuf[4096];
 
-    // make life easier for people using VC++ IDE: clicking on the message
-    // will take us immediately to the place of the failed assert
+    // make life easier for people using VC++ IDE by using this format: like
+    // this, clicking on the message will take us immediately to the place of
+    // the failed assert
     wxSnprintf(szBuf, WXSIZEOF(szBuf),
-#ifdef __VISUALC__
-               wxT("%s(%d): assert failed"),
-#else  // !VC++
-    // make the error message more clear for all the others
-               wxT("Assert failed in file %s at line %d"),
-#endif // VC/!VC
-               szFile, nLine);
+               wxT("%s(%d): assert \"%s\" failed"),
+               szFile, nLine, szCond);
 
     if ( szMsg != NULL )
     {
@@ -501,7 +500,10 @@ void ShowAssertDialog(const wxChar *szFile, int nLine, const wxChar *szMsg)
 }
 
 // this function is called when an assert fails
-void wxOnAssert(const wxChar *szFile, int nLine, const wxChar *szMsg)
+void wxOnAssert(const wxChar *szFile,
+                int nLine,
+                const wxChar *szCond,
+                const wxChar *szMsg)
 {
     // FIXME MT-unsafe
     static bool s_bInAssert = FALSE;
@@ -522,20 +524,23 @@ void wxOnAssert(const wxChar *szFile, int nLine, const wxChar *szMsg)
     {
         // by default, show the assert dialog box - we can't customize this
         // behaviour
-        ShowAssertDialog(szFile, nLine, szMsg);
+        ShowAssertDialog(szFile, nLine, szCond, szMsg);
     }
     else
     {
         // let the app process it as it wants
-        wxTheApp->OnAssert(szFile, nLine, szMsg);
+        wxTheApp->OnAssert(szFile, nLine, szCond, szMsg);
     }
 
     s_bInAssert = FALSE;
 }
 
-void wxAppBase::OnAssert(const wxChar *file, int line, const wxChar *msg)
+void wxAppBase::OnAssert(const wxChar *file,
+                         int line,
+                         const wxChar *cond,
+                         const wxChar *msg)
 {
-    ShowAssertDialog(file, line, msg);
+    ShowAssertDialog(file, line, cond, msg);
 }
 
 #endif  //WXDEBUG