/* * Assert.hpp * * Created on: Mar 18, 2010 * Author: crueger */ #ifndef ASSERT_HPP_ #define ASSERT_HPP_ #include class AssertException{ public: AssertException(std::string _file, int _line) : file(_file), line(_line) {} std::string getFile(){ return file; } int getLine(){ return line; } private: std::string file; int line; }; #ifndef NDEBUG #ifndef STRINGIFY #define STRINGIFY(x) #x #endif #ifdef __GNUC__ // on gcc we know how to exit to the Debugger #define DEBUG_BREAK __builtin_trap() #else #define DEBUG_BREAK exit(1) #endif #define ASSERT(condition,message) \ do{\ static bool ignore = false;\ if(!ignore){\ if(_my_assert::check((condition),STRINGIFY(condition),(message),__FILE__,__LINE__,ignore))\ DEBUG_BREAK;\ } \ }while(0) #define ASSERT_DO_THROW do{_my_assert::always_throw=true;}while(0) #define ASSERT_DONT_THROW do{_my_assert::always_throw=false;}while(0) #else // we need to do something, so this is the usual solution (e.g. assert.h) #define ASSERT(condition,message) (void)(0) #define ASSERT_DO_THROW (void)(0) #define ASSERT_DONT_THROW (void)(0) #endif //! @cond class _my_assert{ public: static bool check(const bool res, const char* condition, const char* message, const char* filename, const int line, bool& ignore); static bool always_throw; }; //! @endcond #endif /* ASSERT_HPP_ */