[Lemon-commits] Alpar Juttner: Merge
Lemon HG
hg at lemon.cs.elte.hu
Sat Apr 12 21:41:53 CEST 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/ae7785fe8431
changeset: 124:ae7785fe8431
user: Alpar Juttner <alpar [at] cs.elte.hu>
date: Sat Apr 12 20:38:51 2008 +0100
description:
Merge
diffstat:
9 files changed, 961 insertions(+), 370 deletions(-)
lemon/Makefile.am | 2
lemon/assert.h | 300 ++++++++----------------
lemon/bits/utility.h | 4
lemon/counter.h | 181 +++++++++++++++
lemon/time_measure.h | 541 +++++++++++++++++++++++++++++++++++++++++++++
test/Makefile.am | 4
test/counter_test.cc | 66 +++++
test/error_test.cc | 170 --------------
test/time_measure_test.cc | 63 +++++
diffs (truncated from 1573 to 300 lines):
diff -r 8899d1891a3c -r ae7785fe8431 lemon/Makefile.am
--- a/lemon/Makefile.am Tue Apr 08 22:51:26 2008 +0200
+++ b/lemon/Makefile.am Sat Apr 12 20:38:51 2008 +0100
@@ -20,6 +20,7 @@
lemon/assert.h \
lemon/bfs.h \
lemon/bin_heap.h \
+ lemon/counter.h \
lemon/dfs.h \
lemon/dijkstra.h \
lemon/dim2.h \
@@ -32,6 +33,7 @@
lemon/path.h \
lemon/random.h \
lemon/smart_graph.h \
+ lemon/time_measure.h \
lemon/tolerance.h \
lemon/unionfind.h
diff -r 8899d1891a3c -r ae7785fe8431 lemon/assert.h
--- a/lemon/assert.h Tue Apr 08 22:51:26 2008 +0200
+++ b/lemon/assert.h Sat Apr 12 20:38:51 2008 +0100
@@ -27,71 +27,6 @@
namespace lemon {
- /// @{
-
- ///\e
- class AssertionFailedError : public LogicError {
- protected:
- const char *_assertion;
- const char *_file;
- int _line;
- const char *_function;
- const char *_message;
-
- mutable ExceptionMember<std::string> _message_holder;
- public:
- ///\e
- AssertionFailedError(const char *file, int line, const char *function,
- const char *msg, const char *assertion = 0) :
- _assertion(assertion), _file(file), _line(line),
- _function(function), _message(msg) {}
-
- ///\e
- const char* assertion() const { return _assertion; }
- ///\e
- const char* message() const { return _message; }
- ///\e
- const char* file() const { return _file; }
- ///\e
- const char* function() const { return _function; }
- ///\e
- int line() const { return _line; }
-
-
- virtual const char* what() const throw() {
- try {
- std::ostringstream ostr;
- ostr << _file << ":" << _line << ": ";
- if (_function)
- ostr << _function << ": ";
- ostr << _message;
- if (_assertion)
- ostr << " (assertion '" << _assertion << "' failed)";
- _message_holder.set(ostr.str());
- return ostr.str().c_str();
- }
- catch(...) {}
- if( _message_holder.valid() ) return _message_holder.get().c_str();
- return "lemon::AssertionFailedError";
- }
- virtual ~AssertionFailedError() throw() {}
- };
-
-
- inline void assert_fail_log(const char *file, int line,
- const char *function,
- const std::exception& exception,
- const char *assertion)
- {
- std::cerr << file << ":" << line << ": ";
- if (function)
- std::cerr << function << ": ";
- std::cerr << exception.what();
- if (assertion)
- std::cerr << " (assertion '" << assertion << "' failed)";
- std::cerr << std::endl;
- }
-
inline void assert_fail_log(const char *file, int line, const char *function,
const char *message, const char *assertion)
{
@@ -104,21 +39,6 @@
std::cerr << std::endl;
}
- inline void assert_fail_log(const char *file, int line, const char *function,
- const std::string& message, const char *assertion)
- {
- assert_fail_log(file, line, function, message.c_str(), assertion);
- }
-
- inline void assert_fail_abort(const char *file, int line,
- const char *function,
- const std::exception& exception,
- const char *assertion)
- {
- assert_fail_log(file, line, function, exception, assertion);
- std::abort();
- }
-
inline void assert_fail_abort(const char *file, int line,
const char *function, const char* message,
const char *assertion)
@@ -127,86 +47,37 @@
std::abort();
}
- inline void assert_fail_abort(const char *file, int line,
- const char *function,
- const std::string& message,
- const char *assertion)
- {
- assert_fail_log(file, line, function, message.c_str(), assertion);
- std::abort();
+ namespace _assert_bits {
+
+
+ inline const char* cstringify(const std::string& str) {
+ return str.c_str();
+ }
+
+ inline const char* cstringify(const char* str) {
+ return str;
+ }
}
+}
- inline void assert_fail_error(const char *file, int line,
- const char *function,
- const std::exception& exception,
- const char *assertion)
- {
- throw AssertionFailedError(file, line, function,
- exception.what(), assertion);
- }
-
- inline void assert_fail_error(const char *file, int line,
- const char *function, const char *message,
- const char *assertion)
- {
- throw AssertionFailedError(file, line, function, message, assertion);
- }
-
- inline void assert_fail_error(const char *file, int line,
- const char *function,
- const std::string& message,
- const char *assertion)
- {
- throw AssertionFailedError(file, line, function, message.c_str(), assertion);
- }
-
- template <typename Exception>
- inline void assert_fail_exception(const char *, int, const char *,
- const Exception& exception,
- const char *, const std::exception* =
- static_cast<const Exception*>(0))
- {
- throw exception;
- }
-
- inline void assert_fail_exception(const char *file, int line,
- const char *function, const char *message,
- const char *assertion)
- {
- throw AssertionFailedError(file, line, function, message, assertion);
- }
-
- inline void assert_fail_exception(const char *file, int line,
- const char *function,
- const std::string& message,
- const char *assertion)
- {
- throw AssertionFailedError(file, line, function, message.c_str(), assertion);
- }
-
-/// @}
-
-}
#endif // LEMON_ASSERT_H
#undef LEMON_ASSERT
#undef LEMON_FIXME
+#undef LEMON_DEBUG
#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) + \
(defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \
- (defined(LEMON_ASSERT_ERROR) ? 1 : 0) + \
- (defined(LEMON_ASSERT_EXCEPTION) ? 1 : 0) + \
(defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1
#error "LEMON assertion system is not set properly"
#endif
#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) + \
(defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \
- (defined(LEMON_ASSERT_ERROR) ? 1 : 0) + \
- (defined(LEMON_ASSERT_EXCEPTION) ? 1 : 0) + \
(defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 || \
defined(LEMON_ENABLE_ASSERTS)) && \
- defined(LEMON_DISABLE_ASSERTS)
+ (defined(LEMON_DISABLE_ASSERTS) || \
+ defined(NDEBUG))
#error "LEMON assertion system is not set properly"
#endif
@@ -217,25 +88,19 @@
#elif defined LEMON_ASSERT_ABORT
# undef LEMON_ASSERT_HANDLER
# define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
-#elif defined LEMON_ASSERT_ERROR
-# undef LEMON_ASSERT_HANDLER
-# define LEMON_ASSERT_HANDLER ::lemon::assert_fail_error
-#elif defined LEMON_ASSERT_EXCEPTION
-# undef LEMON_ASSERT_HANDLER
-# define LEMON_ASSERT_HANDLER ::lemon::assert_fail_exception
#elif defined LEMON_ASSERT_CUSTOM
# undef LEMON_ASSERT_HANDLER
# ifndef LEMON_CUSTOM_ASSERT_HANDLER
# error "LEMON_CUSTOM_ASSERT_HANDLER is not set"
# endif
# define LEMON_ASSERT_HANDLER LEMON_CUSTOM_ASSERT_HANDLER
-#elif defined LEMON_ENABLE_ASSERTS
+#elif defined LEMON_DISABLE_ASSERTS
# undef LEMON_ASSERT_HANDLER
+#elif defined NDEBUG
+# undef LEMON_ASSERT_HANDLER
+#else
# define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
-#else
-# undef LEMON_ASSERT_HANDLER
#endif
-
#ifndef LEMON_FUNCTION_NAME
# define LEMON_FUNCTION_NAME (__PRETTY_FUNCTION__)
@@ -247,24 +112,24 @@
///
/// \brief Macro for assertion with customizable message
///
-/// Macro for assertion with customizable message.
-/// \param exp An expression that must be convertible to \c bool.
-/// If it is \c false, then an assertion is raised. The concrete
-/// behaviour depends on the settings of the assertion system.
-/// \param msg A <tt>const char*</tt>, a <tt>const std::string&</tt> or
-/// a <tt>const std::exception&</tt> parameter, which can be used to
-/// provide information about the circumstances of the failed assertion.
+/// Macro for assertion with customizable message. \param exp An
+/// expression that must be convertible to \c bool. If it is \c
+/// false, then an assertion is raised. The concrete behaviour depends
+/// on the settings of the assertion system. \param msg A <tt>const
+/// char*</tt> parameter, which can be used to provide information
+/// about the circumstances of the failed assertion.
///
-/// The assertions are disabled in the default behaviour.
-/// You can enable them with the following code:
+/// The assertions are enabled in the default behaviour.
+/// You can disable them with the following code:
/// \code
-/// #define LEMON_ENABLE_ASSERTS
+/// #define LEMON_DISABLE_ASSERTS
/// \endcode
/// or with compilation parameters:
/// \code
-/// g++ -DLEMON_ENABLE_ASSERTS
-/// make CXXFLAGS='-DLEMON_ENABLE_ASSERTS'
+/// g++ -DLEMON_DISABLE_ASSERTS
+/// make CXXFLAGS='-DLEMON_DISABLE_ASSERTS'
/// \endcode
+/// The checking is also disabled when the standard macro \c NDEBUG is defined.
///
/// The LEMON assertion system has a wide range of customization
/// properties. As a default behaviour the failed assertion prints a
@@ -274,38 +139,22 @@
///
/// - \c LEMON_ASSERT_LOG The failed assertion prints a short log
/// message to the standard error and continues the execution.
-/// - \c LEMON_ASSERT_ABORT This mode is similar to the
-/// \c LEMON_ASSERT_LOG, but it aborts the program. It is the default
-/// behaviour mode when the assertions are enabled with
-/// \c LEMON_ENABLE_ASSERTS.
-/// - \c LEMON_ASSERT_ERROR The assertion throws an
-/// \ref lemon::AssertionFailedError "AssertionFailedError".
-/// If the \c msg parameter is an exception, then the result of the
-/// \ref lemon::Exception::what() "what()" member function is passed
-/// as error message.
-/// - \c LEMON_ASSERT_EXCEPTION If the specified \c msg is an
-/// exception, then it raised directly (solving that the exception
-/// can not be thrown polymorphically), otherwise an \ref
More information about the Lemon-commits
mailing list