Disable assertions in default behaviour
authordeba
Tue, 18 Jul 2006 12:10:52 +0000
changeset 2150cce8ac91c08c
parent 2149 b437bdee6fd0
child 2151 38ec4a930c05
Disable assertions in default behaviour
Documentation changed
lemon/error.h
     1.1 --- a/lemon/error.h	Tue Jul 18 11:11:54 2006 +0000
     1.2 +++ b/lemon/error.h	Tue Jul 18 12:10:52 2006 +0000
     1.3 @@ -517,10 +517,11 @@
     1.4    }
     1.5  
     1.6    template <>
     1.7 -  inline void assert_fail<const char *>(const char *file, int line, const char *func,
     1.8 -				 const char *message, 
     1.9 -				 const char *assertion,
    1.10 -				 bool do_abort)
    1.11 +  inline void assert_fail<const char *>(const char *file, int line, 
    1.12 +                                        const char *func,
    1.13 +                                        const char *message, 
    1.14 +                                        const char *assertion,
    1.15 +                                        bool do_abort)
    1.16    {
    1.17      using namespace std;
    1.18      cerr << file << ":" << line << ": ";
    1.19 @@ -579,8 +580,12 @@
    1.20  #undef LEMON_ASSERT
    1.21  #undef LEMON_FIXME
    1.22  
    1.23 -#ifndef LEMON_ASSERT_ABORT
    1.24 -#  define LEMON_ASSERT_ABORT 1
    1.25 +#ifdef LEMON_ENABLE_ASSERTS
    1.26 +#  define LEMON_ASSERT_ABORT
    1.27 +#endif
    1.28 +
    1.29 +#ifndef LEMON_ASSERT_DO_ABORT
    1.30 +#  define LEMON_ASSERT_DO_ABORT 1
    1.31  #endif
    1.32  
    1.33  #ifndef LEMON_ASSERT_HANDLER
    1.34 @@ -588,45 +593,69 @@
    1.35  #    define LEMON_ASSERT_HANDLER ::lemon::assert_fail_exception
    1.36  #  elif defined LEMON_ASSERT_FAILURE
    1.37  #    define LEMON_ASSERT_HANDLER ::lemon::assert_fail_failure
    1.38 +#  elif defined LEMON_ASSERT_ABORT
    1.39 +#    define LEMON_ASSERT_HANDLER ::lemon::assert_fail
    1.40  #  else
    1.41 -#    define LEMON_ASSERT_HANDLER ::lemon::assert_fail
    1.42 +#    define LEMON_DISABLE_ASSERTS
    1.43  #  endif
    1.44  #endif
    1.45  
    1.46 -#if defined(NDEBUG) || defined(LEMON_DISABLE_ASSERTS)
    1.47 +#ifdef DOXYGEN
    1.48  
    1.49 -#  define LEMON_ASSERT(exp, msg)  (static_cast<void> (0))
    1.50 -
    1.51 -#else
    1.52 -
    1.53 -/**
    1.54 - * \brief Macro for assertions with customizable message
    1.55 - *
    1.56 - * Macro for assertions with customizable message.
    1.57 - *
    1.58 - * The behaviour can be customized with LEMON_ASSERT_HANDLER,
    1.59 - * LEMON_ASSERT_EXCEPTION and LEMON_ASSERT_ABORT defines. Asserts can be
    1.60 - * disabled by defining either NDEBUG or LEMON_DISABLE_ASSERTS macros.
    1.61 - *
    1.62 - * \todo We should provide some way to reset to the default behaviour,
    1.63 - * shouldn't we?
    1.64 - *
    1.65 - * \todo This whole 'assert' business should be placed in a separate
    1.66 - * include file. The boost assert is not guarded by header sentries
    1.67 - * which may help to change the behaviour of the assertions in 
    1.68 - * the files.
    1.69 - *
    1.70 - * \todo __PRETTY_FUNCTION__ should be replaced by something
    1.71 - * compiler-independent, like BOOST_CURRENT_FUNCTION
    1.72 - */
    1.73 +/// \brief Macro for assertions with customizable message
    1.74 +///
    1.75 +/// Macro for assertions with customizable message.
    1.76 +///
    1.77 +/// The assertions are disabled in the default behaviour. You can
    1.78 +/// enable the assertions with the LEMON_ENABLE_ASSERTS macro what
    1.79 +/// provides a log on the standard error about the assertion and aborts
    1.80 +/// the program.  If the LEMON_ASSERT_DO_ABORT macro is setted to false
    1.81 +/// then the just the log message can be seen on the standard error but
    1.82 +/// the program is not stopped. With the LEMON_ASSERT_FAILURE and
    1.83 +/// LEMON_ASSERT_EXCEPTION macros you can set other behaviour to the
    1.84 +/// assertions. The LEMON_ASSERT_FAILURE will always throw an \c
    1.85 +/// AssertionFailedError exception with the \c msg error message. The
    1.86 +/// \c LEMON_ASSERT_EXCEPTION can throw a user defined exception.
    1.87 +///
    1.88 +/// The LEMON_ASSERT macro should be called with the \c exp parameter
    1.89 +/// which should be an expression convertible to bool. If the given
    1.90 +/// parameter is false the assertion is raised and one of the assertion
    1.91 +/// behaviour will be activated. The \c msg should be either a const
    1.92 +/// char* message or an exception. When the \c msg is an exception the
    1.93 +/// \ref "Exception::what" what() function is called to retrieve and
    1.94 +/// display the error message.
    1.95 +///
    1.96 +///
    1.97 +/// \todo We should provide some way to reset to the default behaviour,
    1.98 +/// shouldn't we?
    1.99 +///
   1.100 +/// \todo This whole 'assert' business should be placed in a separate
   1.101 +/// include file. The boost assert is not guarded by header sentries
   1.102 +/// which may help to change the behaviour of the assertions in 
   1.103 +/// the files.
   1.104 +///
   1.105 +/// \todo __PRETTY_FUNCTION__ should be replaced by something
   1.106 +/// compiler-independent, like BOOST_CURRENT_FUNCTION
   1.107  
   1.108  #  define LEMON_ASSERT(exp, msg)                 \
   1.109       (static_cast<void> (!!(exp) ? 0 : (         \
   1.110         LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
   1.111                              __PRETTY_FUNCTION__, \
   1.112 -			    msg, #exp, LEMON_ASSERT_ABORT), 0)))
   1.113 +                            msg, #exp, LEMON_ASSERT_DO_ABORT), 0)))
   1.114  
   1.115 -#endif // NDEBUG || LEMON_DISABLE_ASSERTS
   1.116 +#else 
   1.117 +#  if defined LEMON_DISABLE_ASSERTS
   1.118 +
   1.119 +#    define LEMON_ASSERT(exp, msg)  (static_cast<void> (0))
   1.120 +
   1.121 +#  else
   1.122 +#    define LEMON_ASSERT(exp, msg)                 \
   1.123 +       (static_cast<void> (!!(exp) ? 0 : (         \
   1.124 +         LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
   1.125 +                              __PRETTY_FUNCTION__, \
   1.126 +                              msg, #exp, LEMON_ASSERT_DO_ABORT), 0)))
   1.127 +#  endif
   1.128 +#endif
   1.129  
   1.130  /**
   1.131   * \brief Macro for mark not yet implemented features.