[Lemon-commits] [lemon_svn] deba: r2864 - hugo/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 21:50:52 CET 2006


Author: deba
Date: Tue Jul 18 14:10:52 2006
New Revision: 2864

Modified:
   hugo/trunk/lemon/error.h

Log:
Disable assertions in default behaviour
Documentation changed




Modified: hugo/trunk/lemon/error.h
==============================================================================
--- hugo/trunk/lemon/error.h	(original)
+++ hugo/trunk/lemon/error.h	Tue Jul 18 14:10:52 2006
@@ -517,10 +517,11 @@
   }
 
   template <>
-  inline void assert_fail<const char *>(const char *file, int line, const char *func,
-				 const char *message, 
-				 const char *assertion,
-				 bool do_abort)
+  inline void assert_fail<const char *>(const char *file, int line, 
+                                        const char *func,
+                                        const char *message, 
+                                        const char *assertion,
+                                        bool do_abort)
   {
     using namespace std;
     cerr << file << ":" << line << ": ";
@@ -579,8 +580,12 @@
 #undef LEMON_ASSERT
 #undef LEMON_FIXME
 
-#ifndef LEMON_ASSERT_ABORT
-#  define LEMON_ASSERT_ABORT 1
+#ifdef LEMON_ENABLE_ASSERTS
+#  define LEMON_ASSERT_ABORT
+#endif
+
+#ifndef LEMON_ASSERT_DO_ABORT
+#  define LEMON_ASSERT_DO_ABORT 1
 #endif
 
 #ifndef LEMON_ASSERT_HANDLER
@@ -588,45 +593,69 @@
 #    define LEMON_ASSERT_HANDLER ::lemon::assert_fail_exception
 #  elif defined LEMON_ASSERT_FAILURE
 #    define LEMON_ASSERT_HANDLER ::lemon::assert_fail_failure
-#  else
+#  elif defined LEMON_ASSERT_ABORT
 #    define LEMON_ASSERT_HANDLER ::lemon::assert_fail
+#  else
+#    define LEMON_DISABLE_ASSERTS
 #  endif
 #endif
 
-#if defined(NDEBUG) || defined(LEMON_DISABLE_ASSERTS)
-
-#  define LEMON_ASSERT(exp, msg)  (static_cast<void> (0))
+#ifdef DOXYGEN
 
-#else
-
-/**
- * \brief Macro for assertions with customizable message
- *
- * Macro for assertions with customizable message.
- *
- * The behaviour can be customized with LEMON_ASSERT_HANDLER,
- * LEMON_ASSERT_EXCEPTION and LEMON_ASSERT_ABORT defines. Asserts can be
- * disabled by defining either NDEBUG or LEMON_DISABLE_ASSERTS macros.
- *
- * \todo We should provide some way to reset to the default behaviour,
- * shouldn't we?
- *
- * \todo This whole 'assert' business should be placed in a separate
- * include file. The boost assert is not guarded by header sentries
- * which may help to change the behaviour of the assertions in 
- * the files.
- *
- * \todo __PRETTY_FUNCTION__ should be replaced by something
- * compiler-independent, like BOOST_CURRENT_FUNCTION
- */
+/// \brief Macro for assertions with customizable message
+///
+/// Macro for assertions with customizable message.
+///
+/// The assertions are disabled in the default behaviour. You can
+/// enable the assertions with the LEMON_ENABLE_ASSERTS macro what
+/// provides a log on the standard error about the assertion and aborts
+/// the program.  If the LEMON_ASSERT_DO_ABORT macro is setted to false
+/// then the just the log message can be seen on the standard error but
+/// the program is not stopped. With the LEMON_ASSERT_FAILURE and
+/// LEMON_ASSERT_EXCEPTION macros you can set other behaviour to the
+/// assertions. The LEMON_ASSERT_FAILURE will always throw an \c
+/// AssertionFailedError exception with the \c msg error message. The
+/// \c LEMON_ASSERT_EXCEPTION can throw a user defined exception.
+///
+/// The LEMON_ASSERT macro should be called with the \c exp parameter
+/// which should be an expression convertible to bool. If the given
+/// parameter is false the assertion is raised and one of the assertion
+/// behaviour will be activated. The \c msg should be either a const
+/// char* message or an exception. When the \c msg is an exception the
+/// \ref "Exception::what" what() function is called to retrieve and
+/// display the error message.
+///
+///
+/// \todo We should provide some way to reset to the default behaviour,
+/// shouldn't we?
+///
+/// \todo This whole 'assert' business should be placed in a separate
+/// include file. The boost assert is not guarded by header sentries
+/// which may help to change the behaviour of the assertions in 
+/// the files.
+///
+/// \todo __PRETTY_FUNCTION__ should be replaced by something
+/// compiler-independent, like BOOST_CURRENT_FUNCTION
 
 #  define LEMON_ASSERT(exp, msg)                 \
      (static_cast<void> (!!(exp) ? 0 : (         \
        LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
                             __PRETTY_FUNCTION__, \
-			    msg, #exp, LEMON_ASSERT_ABORT), 0)))
+                            msg, #exp, LEMON_ASSERT_DO_ABORT), 0)))
 
-#endif // NDEBUG || LEMON_DISABLE_ASSERTS
+#else 
+#  if defined LEMON_DISABLE_ASSERTS
+
+#    define LEMON_ASSERT(exp, msg)  (static_cast<void> (0))
+
+#  else
+#    define LEMON_ASSERT(exp, msg)                 \
+       (static_cast<void> (!!(exp) ? 0 : (         \
+         LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
+                              __PRETTY_FUNCTION__, \
+                              msg, #exp, LEMON_ASSERT_DO_ABORT), 0)))
+#  endif
+#endif
 
 /**
  * \brief Macro for mark not yet implemented features.



More information about the Lemon-commits mailing list