Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef ASSERTS_HPP_INCLUDED
00019 #define ASSERTS_HPP_INCLUDED
00020
00021 #include <cstdlib>
00022 #include <iostream>
00023 #include <csignal>
00024
00025 #ifdef _MSC_VER
00026 #define BREAKPOINT() __debugbreak()
00027 #define WES_HALT() do { BREAKPOINT(); exit(1); } while (false)
00028
00029 #elif defined(__GNUG__) && (defined(__i386__) || defined(__x86_64__)) \
00030 && !defined(__native_client__)
00031 #define BREAKPOINT() asm("int3")
00032 #define WES_HALT() do { BREAKPOINT(); abort(); } while (false)
00033
00034 #elif defined(SIGTRAP)
00035 #define BREAKPOINT() do{ ::std::raise(SIGTRAP); } while (0)
00036 #define WES_HALT() do { BREAKPOINT(); abort(); } while (false)
00037
00038 #else
00039 #define BREAKPOINT()
00040 #define WES_HALT() abort()
00041 #endif
00042
00043 #define ERROR_LOG(a) do { \
00044 std::cerr << __FILE__ << ":" << __LINE__ << " ASSSERTION FAILED: " << a << std::endl; \
00045 WES_HALT(); \
00046 } while (false)
00047
00048
00049
00050 #define ASSERT_LOG(a,b) if (!(a)) { ERROR_LOG(b); } else (void)0
00051
00052 #define FATAL_ERROR ERROR_LOG("FATAL ERROR")
00053
00054
00055
00056
00057
00058
00059 #define UNREACHABLE_CODE ERROR_LOG("REACHED UNREACHABLE CODE")
00060
00061
00062 #define ASSERT_OP(a,op,b) ASSERT_LOG((a) op (b), #a " " #op " " #b " (" << (a) << " " #op " " << (b) << ")")
00063
00064
00065
00066
00067 #define ASSERT_EQ(a,b) ASSERT_OP(a,==,b)
00068 #define ASSERT_NE(a,b) ASSERT_OP(a,!=,b)
00069 #define ASSERT_GE(a,b) ASSERT_OP(a,>=,b)
00070 #define ASSERT_LE(a,b) ASSERT_OP(a,<=,b)
00071 #define ASSERT_GT(a,b) ASSERT_OP(a,>,b)
00072 #define ASSERT_LT(a,b) ASSERT_OP(a,<,b)
00073
00074
00075 #endif
00076