00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00025 #ifndef BTK_DEBUG_H
00026 #define BTK_DEBUG_H
00027
00028 #include <exception>
00029 #include <string>
00030
00031 namespace BTK {
00032 namespace debug {
00039 extern unsigned debug_level;
00040
00051 #ifndef NDEBUG
00052 # define DBG_OUT(level) if (BTK::debug::debug_level >= (level)) std::cerr
00053 #else
00054 # define DBG_OUT(level) if (0) std::cerr
00055 #endif
00056
00057 typedef enum {EXIT, CONTINUE, IGNORE} assert_code;
00058
00059 typedef assert_code (*assert_handler)(std::string const &,
00060 std::string const &,
00061 unsigned);
00062
00063 assert_code default_assert_handler(std::string const & msg,
00064 std::string const & file,
00065 unsigned line);
00066
00067 extern assert_handler current_assert_handler;
00068
00069 class BTKAssertion : public std::exception {
00070 public:
00071 BTKAssertion(std::string const & msg) throw() : _msg(msg.c_str()) {}
00072 BTKAssertion(char const * msg = "") throw() : _msg(msg) {}
00073 ~BTKAssertion() throw() {}
00074 virtual char const * what() const throw() {return _msg.c_str();}
00075 private:
00076 std::string _msg;
00077 };
00078
00079 };
00080
00081 #ifndef NDEBUG
00082 #define BTK_ASSERT(expr,str) if (!(expr)) { \
00083 static BTK::debug::assert_code status = \
00084 BTK::debug::EXIT; \
00085 if (status != BTK::debug::IGNORE) { \
00086 status = BTK::debug:: \
00087 current_assert_handler((str), \
00088 __FILE__, \
00089 __LINE__); \
00090 if (BTK::debug::EXIT == status) \
00091 throw BTK::debug::BTKAssertion(str); \
00092 } \
00093 };
00094
00095 #else
00096 #define BTK_ASSERT(expr,str)
00097 #endif
00098
00099 };
00100
00101 #endif // BTK_DEBUG_H