Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sstream>
- #include <tchar.h>
- //#define AssertBreakMethod DbgRaiseAssertionFailure
- //#define AssertBreakMethod DbgRaiseAssertionFailure
- #define AssertBreakMethod DebugBreak
- #if !defined(NDEBUG)
- #define USP_INLINE_ASSERTS 1 // inline so stepping works nicely
- #else
- // Use lambda for out-of-line function generation for if body
- #define USP_INLINE_ASSERTS 0 // out of line body in release case
- #endif
- #if USP_INLINE_ASSERTS
- #define USP_ASSERT_PREFIX
- #define USP_ASSERT_SUFFIX
- #else
- #define USP_ASSERT_PREFIX ([&]()
- #define USP_ASSERT_SUFFIX )();
- #endif
- #define shipassert(expr) \
- do \
- { \
- if (!(expr)) \
- USP_ASSERT_PREFIX \
- { \
- OutputDebugStringA(#expr "\n"); \
- AssertBreakMethod(); \
- } \
- USP_ASSERT_SUFFIX \
- } \
- while (false)
- #define WIDENW(m) L##m
- #define WIDENA(m) m
- #define MEXPANDA(m) m
- #define WIDEN_MEXPAND(m) L ## m
- #define MEXPANDW(m) WIDEN_MEXPAND(m)
- #define STRINGIFY2(m) #m
- #define STRINGIFYA(m) STRINGIFY2(m)
- #define WIDEN_STRINGIFY(m) L## #m
- #define STRINGIFYW(m) WIDEN_STRINGIFY(m)
- #ifdef UNICODE
- #define STRINGIFY STRINGIFYW
- #define MEXPAND MEXPANDW
- #define WIDEN WIDENW
- #else
- #define STRINGIFY STRINGIFYA
- #define MEXPAND MEXPANDA
- #define WIDEN WIDENA
- #endif
- #define AssertBreakForce(expr) \
- do \
- { \
- if (!(expr)) \
- USP_ASSERT_PREFIX \
- { \
- OutputDebugStringW(MEXPANDW(__FILE__) \
- WIDENW("(") STRINGIFYW(__LINE__) \
- WIDENW("): Assertion failed: ") \
- WIDENW(#expr) WIDENW("\n")); \
- AssertBreakMethod(); \
- } \
- USP_ASSERT_SUFFIX \
- } \
- while (0)
- // Use this instead of the goofy dialog box that pops up by default
- #if !defined(NDEBUG) || defined(FORCE_ASSERTS)
- #define AssertBreak AssertBreakForce
- #else
- #define AssertBreak __noop
- #endif
- #if UNICODE
- #define _assertBreakForceSS std::wstringstream
- #else
- #define _assertBreakForceSS std::stringstream
- #endif
- // Use this instead of the goofy dialog box that pops up by default
- #define AssertBreakForceOperator(a, b, op) \
- do \
- { \
- if (!((a) op (b))) \
- USP_ASSERT_PREFIX \
- { \
- _assertBreakForceSS ss; \
- ss << WIDEN(__FILE__) WIDEN("(") STRINGIFY(__LINE__) WIDEN(")") << \
- WIDEN(": Assertion failed: ") \
- WIDEN(#a) << WIDEN(" (") << WIDEN(a) << WIDEN(") ") \
- WIDEN(#op) WIDEN(" ") WIDEN(#b) << WIDEN(" (") << b << WIDEN(")\n"); \
- OutputDebugString(ss.str().c_str()); \
- AssertBreakMethod(); \
- } \
- USP_ASSERT_SUFFIX \
- } \
- while (0)
- #if !defined(NDEBUG) || defined(FORCE_ASSERTS)
- #define AssertBreakOperator(a,b,o) AssertBreakForceOperator(a,b,o)
- #else
- #define AssertBreakOperator(a,b,o) __noop()
- #endif
- #define AssertBreakEqual(a, b) AssertBreakOperator((a), (b), ==)
- #define AssertBreakLess(a, b) AssertBreakOperator((a), (b), <)
- #define AssertBreakGreater(a, b) AssertBreakOperator((a), (b), >)
- #define AssertBreakLEqual(a, b) AssertBreakOperator((a), (b), <=)
- #define AssertBreakGEqual(a, b) AssertBreakOperator((a), (b), >=)
- #define AssertBreakNotEqual(a, b) AssertBreakOperator((a), (b), !=)
- #define AssertBreakForceEqual(a, b) AssertBreakForceOperator((a), (b), ==)
- #define AssertBreakForceLess(a, b) AssertBreakForceOperator((a), (b), <)
- #define AssertBreakForceGreater(a, b) AssertBreakForceOperator((a), (b), >)
- #define AssertBreakForceLEqual(a, b) AssertBreakForceOperator((a), (b), <=)
- #define AssertBreakForceGEqual(a, b) AssertBreakForceOperator((a), (b), >=)
- #define AssertBreakForceNotEqual(a, b) AssertBreakForceOperator((a), (b), !=)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement