00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef __ASSERT_H__
00027 #define __ASSERT_H__
00028 
00029 #include <vector>
00030 #include <string.h>
00031 
00032 #include <exception>
00033 
00034 class assert_log_c {
00035 
00036   std::vector<const char *> list;
00037 
00038 public:
00039 
00040   void addLine(const char * line) {
00041     list.push_back(strdup(line));
00042   }
00043 
00044   unsigned int lines(void) const { return list.size(); }
00045   const char * line(unsigned int l) const { return list[l]; }
00046 
00047 };
00048 
00049 class assert_exception : public std::exception {
00050 
00051 public:
00052 
00053   const char * expr;
00054   const char * file;
00055   const char * function;
00056   unsigned int line;
00057 
00058   assert_exception(const char * e, const char * f, unsigned int l, const char * fkt) : expr(e), file(f), function(fkt), line(l) {}
00059 
00060   assert_exception(void) : expr(0), file(0), function(0), line(0) {}
00061 
00062 };
00063 
00064 extern assert_log_c * assert_log;
00065 
00066 void bt_assert_init(void);
00067 
00068 void bt_te(const char * expr, const char * file, unsigned int line, const char * funktion);
00069 
00070 #ifdef NDEBUG
00071 
00072 #define bt_assert(expr)
00073 #define bt_assert2(expr) expr
00074 #define bt_assert_line(line)
00075 
00076 #else
00077 
00078 #ifdef WIN32
00079 #define __STRING(s) #s
00080 #endif
00081 
00082 #ifdef BT_ASSERT_NO_FUNC
00083 #define bt_assert(expr)  if (!(expr)) throw assert_exception(__STRING(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__)
00084 #define bt_assert2(expr)  if (!(expr)) throw assert_exception(__STRING(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__)
00085 #else
00086 #define bt_assert(expr)  if (!(expr)) bt_te(__STRING(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__)
00087 #define bt_assert2(expr)  if (!(expr)) bt_te(__STRING(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__)
00088 #endif
00089 #define bt_assert_line(line) assert_log->addLine(line)
00090 
00091 #endif
00092 
00093 #endif