123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #ifndef REALM_UTIL_ASSERT_HPP
- #define REALM_UTIL_ASSERT_HPP
- #include <realm/util/features.h>
- #include <realm/util/terminate.hpp>
- #if REALM_ENABLE_ASSERTIONS || defined(REALM_DEBUG)
- #define REALM_ASSERTIONS_ENABLED 1
- #else
- #define REALM_ASSERTIONS_ENABLED 0
- #endif
- #define REALM_ASSERT_RELEASE(condition) \
- (REALM_LIKELY(condition) ? static_cast<void>(0) \
- : realm::util::terminate("Assertion failed: " #condition, __FILE__, __LINE__))
- #if REALM_ASSERTIONS_ENABLED
- #define REALM_ASSERT(condition) REALM_ASSERT_RELEASE(condition)
- #else
- #define REALM_ASSERT(condition) static_cast<void>(sizeof bool(condition))
- #endif
- #ifdef REALM_DEBUG
- #define REALM_ASSERT_DEBUG(condition) REALM_ASSERT_RELEASE(condition)
- #else
- #define REALM_ASSERT_DEBUG(condition) static_cast<void>(sizeof bool(condition))
- #endif
- #define REALM_STRINGIFY(X) #X
- #define REALM_ASSERT_RELEASE_EX(condition, ...) \
- (REALM_LIKELY(condition) ? static_cast<void>(0) \
- : realm::util::terminate_with_info("Assertion failed: " #condition, __LINE__, __FILE__, \
- REALM_STRINGIFY((__VA_ARGS__)), __VA_ARGS__))
- #ifdef REALM_DEBUG
- #define REALM_ASSERT_DEBUG_EX REALM_ASSERT_RELEASE_EX
- #else
- #define REALM_ASSERT_DEBUG_EX(condition, ...) static_cast<void>(sizeof bool(condition))
- #endif
- #if REALM_ENABLE_ASSERTIONS || defined(REALM_DEBUG)
- #define REALM_ASSERT_EX REALM_ASSERT_RELEASE_EX
- #define REALM_ASSERT_3(left, cmp, right) \
- (REALM_LIKELY((left)cmp(right)) ? static_cast<void>(0) \
- : realm::util::terminate("Assertion failed: " \
- "" #left " " #cmp " " #right, \
- __FILE__, __LINE__, left, right))
- #define REALM_ASSERT_7(left1, cmp1, right1, logical, left2, cmp2, right2) \
- (REALM_LIKELY(((left1)cmp1(right1))logical((left2)cmp2(right2))) \
- ? static_cast<void>(0) \
- : realm::util::terminate("Assertion failed: " \
- "" #left1 " " #cmp1 " " #right1 " " #logical " " \
- "" #left2 " " #cmp2 " " #right2, \
- __FILE__, __LINE__, left1, right1, left2, right2))
- #define REALM_ASSERT_11(left1, cmp1, right1, logical1, left2, cmp2, right2, logical2, left3, cmp3, right3) \
- (REALM_LIKELY(((left1)cmp1(right1))logical1((left2)cmp2(right2)) logical2((left3)cmp3(right3))) \
- ? static_cast<void>(0) \
- : realm::util::terminate("Assertion failed: " \
- "" #left1 " " #cmp1 " " #right1 " " #logical1 " " \
- "" #left2 " " #cmp2 " " #right2 " " #logical2 " " \
- "" #left3 " " #cmp3 " " #right3, \
- __FILE__, __LINE__, left1, right1, left2, right2, left3, right3))
- #else
- #define REALM_ASSERT_EX(condition, ...) static_cast<void>(sizeof bool(condition))
- #define REALM_ASSERT_3(left, cmp, right) static_cast<void>(sizeof bool((left)cmp(right)))
- #define REALM_ASSERT_7(left1, cmp1, right1, logical, left2, cmp2, right2) \
- static_cast<void>(sizeof bool(((left1)cmp1(right1))logical((left2)cmp2(right2))))
- #define REALM_ASSERT_11(left1, cmp1, right1, logical1, left2, cmp2, right2, logical2, left3, cmp3, right3) \
- static_cast<void>(sizeof bool(((left1)cmp1(right1))logical1((left2)cmp2(right2)) logical2((left3)cmp3(right3))))
- #endif
- #define REALM_UNREACHABLE() realm::util::terminate("Unreachable code", __FILE__, __LINE__)
- #ifdef REALM_COVER
- #define REALM_COVER_NEVER(x) false
- #define REALM_COVER_ALWAYS(x) true
- #else
- #define REALM_COVER_NEVER(x) (x)
- #define REALM_COVER_ALWAYS(x) (x)
- #endif
- #endif
|