577 #endif // LEMON_ERROR_H |
578 #endif // LEMON_ERROR_H |
578 |
579 |
579 #undef LEMON_ASSERT |
580 #undef LEMON_ASSERT |
580 #undef LEMON_FIXME |
581 #undef LEMON_FIXME |
581 |
582 |
582 #ifndef LEMON_ASSERT_ABORT |
583 #ifdef LEMON_ENABLE_ASSERTS |
583 # define LEMON_ASSERT_ABORT 1 |
584 # define LEMON_ASSERT_ABORT |
|
585 #endif |
|
586 |
|
587 #ifndef LEMON_ASSERT_DO_ABORT |
|
588 # define LEMON_ASSERT_DO_ABORT 1 |
584 #endif |
589 #endif |
585 |
590 |
586 #ifndef LEMON_ASSERT_HANDLER |
591 #ifndef LEMON_ASSERT_HANDLER |
587 # if defined LEMON_ASSERT_EXCEPTION |
592 # if defined LEMON_ASSERT_EXCEPTION |
588 # define LEMON_ASSERT_HANDLER ::lemon::assert_fail_exception |
593 # define LEMON_ASSERT_HANDLER ::lemon::assert_fail_exception |
589 # elif defined LEMON_ASSERT_FAILURE |
594 # elif defined LEMON_ASSERT_FAILURE |
590 # define LEMON_ASSERT_HANDLER ::lemon::assert_fail_failure |
595 # define LEMON_ASSERT_HANDLER ::lemon::assert_fail_failure |
|
596 # elif defined LEMON_ASSERT_ABORT |
|
597 # define LEMON_ASSERT_HANDLER ::lemon::assert_fail |
591 # else |
598 # else |
592 # define LEMON_ASSERT_HANDLER ::lemon::assert_fail |
599 # define LEMON_DISABLE_ASSERTS |
593 # endif |
600 # endif |
594 #endif |
601 #endif |
595 |
602 |
596 #if defined(NDEBUG) || defined(LEMON_DISABLE_ASSERTS) |
603 #ifdef DOXYGEN |
597 |
604 |
598 # define LEMON_ASSERT(exp, msg) (static_cast<void> (0)) |
605 /// \brief Macro for assertions with customizable message |
599 |
606 /// |
600 #else |
607 /// Macro for assertions with customizable message. |
601 |
608 /// |
602 /** |
609 /// The assertions are disabled in the default behaviour. You can |
603 * \brief Macro for assertions with customizable message |
610 /// enable the assertions with the LEMON_ENABLE_ASSERTS macro what |
604 * |
611 /// provides a log on the standard error about the assertion and aborts |
605 * Macro for assertions with customizable message. |
612 /// the program. If the LEMON_ASSERT_DO_ABORT macro is setted to false |
606 * |
613 /// then the just the log message can be seen on the standard error but |
607 * The behaviour can be customized with LEMON_ASSERT_HANDLER, |
614 /// the program is not stopped. With the LEMON_ASSERT_FAILURE and |
608 * LEMON_ASSERT_EXCEPTION and LEMON_ASSERT_ABORT defines. Asserts can be |
615 /// LEMON_ASSERT_EXCEPTION macros you can set other behaviour to the |
609 * disabled by defining either NDEBUG or LEMON_DISABLE_ASSERTS macros. |
616 /// assertions. The LEMON_ASSERT_FAILURE will always throw an \c |
610 * |
617 /// AssertionFailedError exception with the \c msg error message. The |
611 * \todo We should provide some way to reset to the default behaviour, |
618 /// \c LEMON_ASSERT_EXCEPTION can throw a user defined exception. |
612 * shouldn't we? |
619 /// |
613 * |
620 /// The LEMON_ASSERT macro should be called with the \c exp parameter |
614 * \todo This whole 'assert' business should be placed in a separate |
621 /// which should be an expression convertible to bool. If the given |
615 * include file. The boost assert is not guarded by header sentries |
622 /// parameter is false the assertion is raised and one of the assertion |
616 * which may help to change the behaviour of the assertions in |
623 /// behaviour will be activated. The \c msg should be either a const |
617 * the files. |
624 /// char* message or an exception. When the \c msg is an exception the |
618 * |
625 /// \ref "Exception::what" what() function is called to retrieve and |
619 * \todo __PRETTY_FUNCTION__ should be replaced by something |
626 /// display the error message. |
620 * compiler-independent, like BOOST_CURRENT_FUNCTION |
627 /// |
621 */ |
628 /// |
|
629 /// \todo We should provide some way to reset to the default behaviour, |
|
630 /// shouldn't we? |
|
631 /// |
|
632 /// \todo This whole 'assert' business should be placed in a separate |
|
633 /// include file. The boost assert is not guarded by header sentries |
|
634 /// which may help to change the behaviour of the assertions in |
|
635 /// the files. |
|
636 /// |
|
637 /// \todo __PRETTY_FUNCTION__ should be replaced by something |
|
638 /// compiler-independent, like BOOST_CURRENT_FUNCTION |
622 |
639 |
623 # define LEMON_ASSERT(exp, msg) \ |
640 # define LEMON_ASSERT(exp, msg) \ |
624 (static_cast<void> (!!(exp) ? 0 : ( \ |
641 (static_cast<void> (!!(exp) ? 0 : ( \ |
625 LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
642 LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
626 __PRETTY_FUNCTION__, \ |
643 __PRETTY_FUNCTION__, \ |
627 msg, #exp, LEMON_ASSERT_ABORT), 0))) |
644 msg, #exp, LEMON_ASSERT_DO_ABORT), 0))) |
628 |
645 |
629 #endif // NDEBUG || LEMON_DISABLE_ASSERTS |
646 #else |
|
647 # if defined LEMON_DISABLE_ASSERTS |
|
648 |
|
649 # define LEMON_ASSERT(exp, msg) (static_cast<void> (0)) |
|
650 |
|
651 # else |
|
652 # define LEMON_ASSERT(exp, msg) \ |
|
653 (static_cast<void> (!!(exp) ? 0 : ( \ |
|
654 LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
|
655 __PRETTY_FUNCTION__, \ |
|
656 msg, #exp, LEMON_ASSERT_DO_ABORT), 0))) |
|
657 # endif |
|
658 #endif |
630 |
659 |
631 /** |
660 /** |
632 * \brief Macro for mark not yet implemented features. |
661 * \brief Macro for mark not yet implemented features. |
633 * |
662 * |
634 * \todo Is this the right place for this? It should be used only in |
663 * \todo Is this the right place for this? It should be used only in |