00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "exception.h"
00021
00022 #ifndef EASSERT_H
00023 #define EASSERT_H
00024
00025 namespace cwidget
00026 {
00027 namespace util
00028 {
00030 class AssertionFailure : public Exception
00031 {
00032 std::string file;
00033 std::string func;
00034 std::string exp;
00035 std::string msg;
00036 size_t line;
00037 public:
00046 AssertionFailure(const std::string &file,
00047 size_t line,
00048 const std::string &func,
00049 const std::string &exp,
00050 const std::string &msg);
00051
00052 std::string errmsg() const;
00053
00055 std::string get_file() const
00056 {
00057 return file;
00058 }
00059
00061 size_t get_line() const
00062 {
00063 return line;
00064 }
00065
00067 std::string get_func() const
00068 {
00069 return func;
00070 }
00071
00073 std::string get_exp() const
00074 {
00075 return exp;
00076 }
00077 };
00078 }
00079 }
00080
00084 #define eassert2(invariant, msg) \
00085 do { if(!(invariant)) \
00086 throw cwidget::util::AssertionFailure(__FILE__, __LINE__, __PRETTY_FUNCTION__, #invariant, msg); \
00087 } while(0)
00088
00094 #define eassert(invariant) eassert2(invariant, "")
00095
00096 #endif