[565] | 1 | /*! |
---|
| 2 | \file |
---|
| 3 | \brief BDM's exception-throwing macros. |
---|
| 4 | \author Vaclav Barta. |
---|
| 5 | |
---|
| 6 | ----------------------------------- |
---|
| 7 | BDM++ - C++ library for Bayesian Decision Making under Uncertainty |
---|
| 8 | |
---|
| 9 | Using IT++ for numerical operations |
---|
| 10 | ----------------------------------- |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | #ifndef bdmerror_h |
---|
| 14 | #define bdmerror_h |
---|
| 15 | |
---|
| 16 | // modelled after IT++ assert macros, somewhat simplified |
---|
| 17 | |
---|
| 18 | #include <sstream> |
---|
| 19 | #include <string> |
---|
| 20 | |
---|
| 21 | namespace bdm { |
---|
| 22 | |
---|
| 23 | //! Helper function for the \c bdm_assert and \c bdm_assert_debug macros |
---|
[737] | 24 | void bdm_assert_f ( const std::string &ass, const std::string &msg, const std::string &file, int line ); |
---|
[565] | 25 | |
---|
| 26 | //! Helper function for the \c bdm_error macro |
---|
[737] | 27 | void bdm_error_f ( const std::string &msg, const std::string &file, int line ); |
---|
[565] | 28 | |
---|
| 29 | //! Helper function for the \c bdm_warning macro |
---|
[737] | 30 | void bdm_warning_f ( const std::string &msg, const std::string &file, int line ); |
---|
[565] | 31 | |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | //! Throw std::runtime_exception if \c t is not true |
---|
| 35 | #define bdm_assert(t, s) \ |
---|
| 36 | if (!(t)) { \ |
---|
| 37 | std::ostringstream bdm_out; \ |
---|
| 38 | bdm_out << s; \ |
---|
| 39 | bdm::bdm_assert_f(#t, bdm_out.str(), __FILE__, __LINE__); \ |
---|
| 40 | } else ((void) 0) |
---|
| 41 | |
---|
| 42 | #if defined(NDEBUG) |
---|
| 43 | //! Throw std::runtime_exception if \c t is not true and NDEBUG is not defined |
---|
| 44 | #define bdm_assert_debug(t, s) ((void) 0) |
---|
| 45 | #else |
---|
| 46 | //! Throw std::runtime_exception if \c t is not true and NDEBUG is not defined |
---|
| 47 | #define bdm_assert_debug(t, s) bdm_assert(t, s) |
---|
| 48 | #endif // if defined(NDEBUG) |
---|
| 49 | |
---|
[1020] | 50 | #if defined(NDEBUG) |
---|
| 51 | //! DO argument if in DEBUG model |
---|
| 52 | #define DEBUG(command) ((void) 0) |
---|
| 53 | #else |
---|
| 54 | //! DO argument if in DEBUG model |
---|
| 55 | #define DEBUG(command) command |
---|
| 56 | #endif // if defined(NDEBUG) |
---|
| 57 | |
---|
[565] | 58 | //! Unconditionally throw std::runtime_error |
---|
| 59 | #define bdm_error(s) \ |
---|
| 60 | if (true) { \ |
---|
| 61 | std::ostringstream bdm_out; \ |
---|
| 62 | bdm_out << s; \ |
---|
| 63 | bdm::bdm_error_f(bdm_out.str(), __FILE__, __LINE__); \ |
---|
| 64 | } else ((void) 0) |
---|
| 65 | |
---|
| 66 | //! Display a warning message |
---|
| 67 | #define bdm_warning(s) \ |
---|
| 68 | if (true) { \ |
---|
| 69 | std::ostringstream bdm_out; \ |
---|
| 70 | bdm_out << s; \ |
---|
| 71 | bdm::bdm_warning_f(bdm_out.str(), __FILE__, __LINE__); \ |
---|
| 72 | } else ((void) 0) |
---|
| 73 | |
---|
[766] | 74 | #define NOT_IMPLEMENTED(RESULT) { bdm_error( "Not implemented" ); return RESULT; } |
---|
| 75 | |
---|
| 76 | #define NOT_IMPLEMENTED_VOID { bdm_error( "Not implemented" ); } |
---|
| 77 | |
---|
[565] | 78 | #endif |
---|