00001 #ifndef _theplu_yat_utility_yat_assert_
00002 #define _theplu_yat_utility_yat_assert_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Exception.h"
00026
00027 #include <sstream>
00028 #include <stdexcept>
00029 #include <string>
00030
00031 namespace theplu {
00032 namespace yat {
00033 namespace utility {
00034
00043 template<class X> inline void yat_assert(bool assertion, std::string msg)
00044 #ifdef YAT_DEBUG
00045 { if (!assertion) throw X(std::string("yat_assert:")+msg); }
00046 #else
00047 { }
00048 #endif
00049
00050 }}}
00051
00052
00053 #ifdef YAT_DEBUG
00054
00055
00056
00057
00058
00059 #define YAT_ASSERT(expr) \
00060 if (!(expr)) { \
00061 std::stringstream yat_msg_; \
00062 yat_msg_ << __FILE__ << ":" << __LINE__ << " failed assertion `" \
00063 << #expr << "'"; \
00064 theplu::yat::utility::yat_assert<theplu::yat::utility::runtime_error>(expr, \
00065 yat_msg_.str()); \
00066 } \
00067 else theplu::yat::utility::yat_assert<std::runtime_error>(expr, "")
00068 #else
00069
00070 #define YAT_ASSERT(expr) theplu::yat::utility::yat_assert<std::runtime_error>(expr, "")
00071 #endif
00072
00073
00074 #endif