首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

“产业级” 断言

2012-12-27 
“工业级” 断言class Assert{public:Assert():SMART_ASSERT_A(*this), SMART_ASSERT_B(*this) {}Assert& SM

“工业级” 断言

class Assert{public:    Assert():SMART_ASSERT_A(*this), SMART_ASSERT_B(*this) {}    Assert& SMART_ASSERT_A;    Assert& SMART_ASSERT_B;    //whatever member functions    Assert& print_current_val(int i,const char* c)    {        printf("%s=%i\n", c, i);        return *this;    }    Assert& print_current_val(const char * i,const char* c)    {        printf("%s=%s\n", c, i);        return *this;    }    Assert& print_context(const char * info, const char* c, int i)    {        printf("ASSERT FAIL:%s\nFILE:%s, LINE:%i\n", info, c, i);        return *this;    }};Assert& make_assert(){    static Assert a;    return a;}#define SMART_ASSERT_A(x) SMART_ASSERT_OP(x,B)#define SMART_ASSERT_B(x) SMART_ASSERT_OP(x,A)#define SMART_ASSERT_OP(x,next) \    SMART_ASSERT_A.print_current_val((x),#x).SMART_ASSERT_##next#define SMART_ASSERT(expr) \    if( (expr) ) ; \    else make_assert().print_context(#expr, __FILE__,__LINE__).SMART_ASSERT_A#define _ASSERT SMART_ASSERT

?

热点排行