1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include "[MathLog.h]"19 #include "[assume.h]"20 21 #include <sstream>22 23 #ifdef assert24 #undef assert25 #endif26 27 #ifdef FAIL_USING_EXCEPTIONS28 #include <stdexcept>29 #define RuntimeFailure(str) throw std::runtime_error(str)30 #elif defined(OPTIMIZED_RELEASE) || defined(NDEBUG)31 #define RuntimeFailure(str) ((void)0)32 #define RUNTIME_FAILURE_DISABLED33 #elif defined(_MSC_VER)34 #include <crtdbg.h>35 #define RuntimeFailure(str) do { LOGE("%s", str); _CrtDbgBreak(); } while(0)36 #else37 #define RuntimeFailure(str) do { LOGE("%s", str); } while(0)38 #endif39 40 #ifdef RUNTIME_FAILURE_DISABLED41 42 #define assert(x) ((void)0)43 #define asserteq(x,y) ((void)0)44 #define assertcmp(x, cmp, y) ((void)0)45 46 47 48 49 50 #ifdef _MSC_VER51 #define MATH_IGNORE_UNUSED_VARS_WARNING __pragma(warning(disable:4189)) // C4189: 'variableName' : local variable is initialized but not referenced52 #elif defined(__GNUC__) && (__GNUC__*10000+__GNUC_MINOR*100) >= 4060053 54 #define MATH_IGNORE_UNUSED_VARS_WARNING _Pragma("GCC diagnostic ignored \"-Wunused-variable\"") _Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"")55 #else56 #define MATH_IGNORE_UNUSED_VARS_WARNING _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")57 #endif58 59 #else60 61 #define MATH_IGNORE_UNUSED_VARS_WARNING62 63 #define assert(x) \64 MULTI_LINE_MACRO_BEGIN \65 if (!(x)) \66 { \67 const char *error = #x " in " __FILE__ ":" STRINGIZE(__LINE__); \68 MARK_UNUSED(error); \69 RuntimeFailure(error); \70 } \71 MULTI_LINE_MACRO_END72 73 #define asserteq(x,y) \74 MULTI_LINE_MACRO_BEGIN \75 if ((x) != (y)) \76 { \77 std::stringstream std_stringstream; \78 std_stringstream << "Assertion '" #x "' == '" #y "' failed! (" << (x) << " != " << (y) << "!) in " __FILE__ ":" STRINGIZE(__LINE__); \79 RuntimeFailure(std_stringstream.str().c_str()); \80 } \81 MULTI_LINE_MACRO_END82 83 #define assertcmp(x, cmp, y) \84 MULTI_LINE_MACRO_BEGIN \85 if (!((x) cmp (y))) \86 { \87 std::stringstream std_stringstream; \88 std_stringstream << "Assertion '" #x "' " #cmp " '" #y "' failed! (" << (x) << " and " << (y) << "!) in " __FILE__ ":" STRINGIZE(__LINE__); \89 RuntimeFailure(std_stringstream.str().c_str()); \90 } \91 MULTI_LINE_MACRO_END92 93 #endif Go back to previous page