# HG changeset patch # User deba # Date 1153224652 0 # Node ID cce8ac91c08c6092e5de0930952464efe5955a9e # Parent b437bdee6fd0c7ef75328d137a2347986c1f0af2 Disable assertions in default behaviour Documentation changed diff -r b437bdee6fd0 -r cce8ac91c08c lemon/error.h --- a/lemon/error.h Tue Jul 18 11:11:54 2006 +0000 +++ b/lemon/error.h Tue Jul 18 12:10:52 2006 +0000 @@ -517,10 +517,11 @@ } template <> - inline void assert_fail(const char *file, int line, const char *func, - const char *message, - const char *assertion, - bool do_abort) + inline void assert_fail(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 +# elif defined LEMON_ASSERT_ABORT +# define LEMON_ASSERT_HANDLER ::lemon::assert_fail # else -# define LEMON_ASSERT_HANDLER ::lemon::assert_fail +# define LEMON_DISABLE_ASSERTS # endif #endif -#if defined(NDEBUG) || defined(LEMON_DISABLE_ASSERTS) +#ifdef DOXYGEN -# define LEMON_ASSERT(exp, msg) (static_cast (0)) - -#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 (!!(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 (0)) + +# else +# define LEMON_ASSERT(exp, msg) \ + (static_cast (!!(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.