lemon/assert.h
changeset 112 d2ee5e7f00ef
parent 108 889d0c289d19
child 118 407c08a0eae9
     1.1 --- a/lemon/assert.h	Tue Mar 25 16:36:44 2008 +0100
     1.2 +++ b/lemon/assert.h	Thu Mar 27 13:26:16 2008 +0100
     1.3 @@ -115,13 +115,7 @@
     1.4  				const std::exception& exception,
     1.5  				const char *assertion)
     1.6    {
     1.7 -    std::cerr << file << ":" << line << ": ";
     1.8 -    if (function)
     1.9 -      std::cerr << function << ": ";
    1.10 -    std::cerr << exception.what();
    1.11 -    if (assertion)
    1.12 -      std::cerr << " (assertion '" << assertion << "' failed)";
    1.13 -    std::cerr << std::endl;
    1.14 +    assert_fail_log(file, line, function, exception, assertion);
    1.15      std::abort();
    1.16    }
    1.17  
    1.18 @@ -129,13 +123,7 @@
    1.19  				const char *function, const char* message,
    1.20  				const char *assertion)
    1.21    {
    1.22 -    std::cerr << file << ":" << line << ": ";
    1.23 -    if (function)
    1.24 -      std::cerr << function << ": ";
    1.25 -    std::cerr << message;
    1.26 -    if (assertion)
    1.27 -      std::cerr << " (assertion '" << assertion << "' failed)";
    1.28 -    std::cerr << std::endl;
    1.29 +    assert_fail_log(file, line, function, message, assertion);
    1.30      std::abort();
    1.31    }
    1.32  
    1.33 @@ -144,7 +132,8 @@
    1.34  				const std::string& message,
    1.35  				const char *assertion)
    1.36    {
    1.37 -    assert_fail_abort(file, line, function, message.c_str(), assertion);
    1.38 +    assert_fail_log(file, line, function, message.c_str(), assertion);
    1.39 +    std::abort();
    1.40    }
    1.41  
    1.42    inline void assert_fail_error(const char *file, int line, 
    1.43 @@ -168,7 +157,7 @@
    1.44  				  const std::string& message,
    1.45  				  const char *assertion)
    1.46    {
    1.47 -    assert_fail_error(file, line, function, message.c_str(), assertion);
    1.48 +    throw AssertionFailedError(file, line, function, message.c_str(), assertion);
    1.49    }
    1.50  
    1.51    template <typename Exception>
    1.52 @@ -192,7 +181,7 @@
    1.53  				    const std::string& message,
    1.54  				    const char *assertion)
    1.55    {
    1.56 -    assert_fail_exception(file, line, function, message.c_str(), assertion);
    1.57 +    throw AssertionFailedError(file, line, function, message.c_str(), assertion);
    1.58    }
    1.59  
    1.60  /// @}
    1.61 @@ -208,7 +197,7 @@
    1.62    (defined(LEMON_ASSERT_ERROR) ? 1 : 0) +		\
    1.63    (defined(LEMON_ASSERT_EXCEPTION) ? 1 : 0) +		\
    1.64    (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1
    1.65 -#error "Lemon assertion system is not set properly"
    1.66 +#error "LEMON assertion system is not set properly"
    1.67  #endif
    1.68  
    1.69  #if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) +		\
    1.70 @@ -216,9 +205,9 @@
    1.71       (defined(LEMON_ASSERT_ERROR) ? 1 : 0) +		\
    1.72       (defined(LEMON_ASSERT_EXCEPTION) ? 1 : 0) +	\
    1.73       (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 ||	\
    1.74 -     defined(LEMON_ENABLE_ASSERT)) &&			\
    1.75 +     defined(LEMON_ENABLE_ASSERTS)) &&			\
    1.76    defined(LEMON_DISABLE_ASSERTS)
    1.77 -#error "Lemon assertion system is not set properly"
    1.78 +#error "LEMON assertion system is not set properly"
    1.79  #endif
    1.80  
    1.81  
    1.82 @@ -256,18 +245,18 @@
    1.83  
    1.84  /// \ingroup exceptions
    1.85  ///
    1.86 -/// \brief Macro for assertions with customizable message
    1.87 +/// \brief Macro for assertion with customizable message
    1.88  ///
    1.89 -/// Macro for assertions with customizable message.  
    1.90 -/// \param exp An expression convertible to bool. If the expression is
    1.91 -/// false, then an assertion is raised. The concrete behaviour depends
    1.92 -/// on the settings of the assertion system.
    1.93 -/// \param msg A \e const \e char*, a \e const std::string& or a \e
    1.94 -/// const \e std::exception& parameter. The variable can be used to
    1.95 -/// provide information about the circumstances of failed assertion.
    1.96 +/// Macro for assertion with customizable message.  
    1.97 +/// \param exp An expression that must be convertible to \c bool.
    1.98 +/// If it is \c false, then an assertion is raised. The concrete
    1.99 +/// behaviour depends on the settings of the assertion system.
   1.100 +/// \param msg A <tt>const char*</tt>, a <tt>const std::string&</tt> or
   1.101 +/// a <tt>const std::exception&</tt> parameter, which can be used to
   1.102 +/// provide information about the circumstances of the failed assertion.
   1.103  ///
   1.104 -/// The assertions are disabled in the default behaviour. You can
   1.105 -/// enable the assertions with the following code:
   1.106 +/// The assertions are disabled in the default behaviour.
   1.107 +/// You can enable them with the following code:
   1.108  /// \code
   1.109  /// #define LEMON_ENABLE_ASSERTS
   1.110  /// \endcode
   1.111 @@ -277,39 +266,38 @@
   1.112  /// make CXXFLAGS='-DLEMON_ENABLE_ASSERTS'
   1.113  /// \endcode
   1.114  /// 
   1.115 -/// The %lemon assertion system has a wide range of customization
   1.116 -/// properties. As default behaviour the failed assertion prints a
   1.117 -/// short log message to the standard ouput and aborts the execution.
   1.118 +/// The LEMON assertion system has a wide range of customization
   1.119 +/// properties. As a default behaviour the failed assertion prints a
   1.120 +/// short log message to the standard error and aborts the execution.
   1.121  ///
   1.122  /// The following modes can be used in the assertion system: 
   1.123  ///
   1.124 -/// - \e LEMON_ASSERT_LOG The failed assert print a short convenient
   1.125 -///   error message to the standard error and continues the
   1.126 -///   execution.
   1.127 -/// - \e LEMON_ASSERT_ABORT This mode is similar to the \e
   1.128 -///   LEMON_ASSERT_LOG, but it aborts the program. It is the default
   1.129 -///   operation mode when the asserts are enabled with \e
   1.130 -///   LEMON_ENABLE_ASSERTS.
   1.131 -/// - \e LEMON_ASSERT_ERROR The assert throws an \ref
   1.132 -///   lemon::AssertionFailedError "AssertionFailedError". If the \c
   1.133 -///   msg parameter is an exception, then the result of the \ref
   1.134 -///   lemon::Exception::what() "what()" member function is passed as
   1.135 -///   error message.
   1.136 -/// - \e LEMON_ASSERT_EXCEPTION If the specified \c msg is an
   1.137 -///   exception then it raised directly (solving that the exception
   1.138 +/// - \c LEMON_ASSERT_LOG The failed assertion prints a short log
   1.139 +///   message to the standard error and continues the execution.
   1.140 +/// - \c LEMON_ASSERT_ABORT This mode is similar to the
   1.141 +///   \c LEMON_ASSERT_LOG, but it aborts the program. It is the default
   1.142 +///   behaviour mode when the assertions are enabled with
   1.143 +///   \c LEMON_ENABLE_ASSERTS.
   1.144 +/// - \c LEMON_ASSERT_ERROR The assertion throws an
   1.145 +///   \ref lemon::AssertionFailedError "AssertionFailedError".
   1.146 +///   If the \c msg parameter is an exception, then the result of the
   1.147 +///   \ref lemon::Exception::what() "what()" member function is passed
   1.148 +///   as error message.
   1.149 +/// - \c LEMON_ASSERT_EXCEPTION If the specified \c msg is an
   1.150 +///   exception, then it raised directly (solving that the exception
   1.151  ///   can not be thrown polymorphically), otherwise an \ref
   1.152  ///   lemon::AssertionFailedError "AssertionFailedError" is thrown with
   1.153 -///   the given parameter.
   1.154 -/// - \e LEMON_ASSERT_CUSTOM The user can define an own assertion
   1.155 -///   handler functions. Three overloaded functions should be defined
   1.156 -///   with the following parameter lists:
   1.157 +///   the given parameters.
   1.158 +/// - \c LEMON_ASSERT_CUSTOM The user can define own assertion handler
   1.159 +///   functions. Three overloaded functions should be defined with the
   1.160 +///   following parameter lists:
   1.161  ///   \code
   1.162 -///     void custom_assert_handler(const char* file, int line, 
   1.163 -///                                const char* function, const char* message, const char* expression);
   1.164 -///     void custom_assert_handler(const char* file, int line, 
   1.165 -///                                const char* function, const std::string& message, const char* expression);
   1.166 -///     void custom_assert_handler(const char* file, int line, 
   1.167 -///                                const char* function, const std::exception& message, const char* expression);
   1.168 +///     void custom_assert_handler(const char* file, int line, const char* function,
   1.169 +///                                const char* message, const char* assertion);
   1.170 +///     void custom_assert_handler(const char* file, int line, const char* function,
   1.171 +///                                const std::string& message, const char* assertion);
   1.172 +///     void custom_assert_handler(const char* file, int line, const char* function,
   1.173 +///                                const std::exception& message, const char* assertion);
   1.174  ///   \endcode
   1.175  ///   The name of the functions should be defined as the \c
   1.176  ///   LEMON_CUSTOM_ASSERT_HANDLER macro name. 
   1.177 @@ -317,12 +305,12 @@
   1.178  ///     #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler
   1.179  ///   \endcode
   1.180  ///   Whenever an assertion is occured, one of the custom assertion
   1.181 -///   handler is called with appropiate parameters.
   1.182 +///   handlers is called with appropiate parameters.
   1.183  ///
   1.184 -/// The assertion mode can be changed within one compilation unit, if
   1.185 -/// the macros are redefined with other settings and the
   1.186 -/// lemon/assert.h file is reincluded then the behaviour is changed
   1.187 -/// appropiately to the new settings.
   1.188 +/// The assertion mode can also be changed within one compilation unit.
   1.189 +/// If the macros are redefined with other settings and the
   1.190 +/// \ref lemon/assert.h "assert.h" file is reincluded, then the
   1.191 +/// behaviour is changed appropiately to the new settings.
   1.192  #  define LEMON_ASSERT(exp, msg)					\
   1.193    (static_cast<void> (!!(exp) ? 0 : (					\
   1.194      LEMON_ASSERT_HANDLER(__FILE__, __LINE__,				\
   1.195 @@ -346,7 +334,7 @@
   1.196  #else
   1.197  
   1.198  #  ifndef LEMON_ASSERT_HANDLER
   1.199 -#    define LEMON_ASSERT(exp, msg)  (static_cast<void> (0))
   1.200 +#    define LEMON_ASSERT(exp, msg)  (static_cast<void>(0))
   1.201  #    define LEMON_FIXME(msg) (static_cast<void>(0))
   1.202  #  else
   1.203  #    define LEMON_ASSERT(exp, msg)                 \