15 #include <boost/preprocessor/facilities/overload.hpp> 16 #include <boost/preprocessor/cat.hpp> 17 #include <boost/preprocessor/facilities/empty.hpp> 39 enum xmresult { XR_SUCCESS = 0, XR_FAILURE = 1 };
43 #define XM_LIKELY(x) (!!(x)) 44 #define XM_UNLIKELY(x) (!!(x)) 45 //------------------------------------------------------------------------------ 53 return static_cast<unsigned int>(_xmresult) & 0x00000001;
55 #define XM_FAILED(_xmresult) ((bool)XM_UNLIKELY(XM_FAILED_impl(_xmresult))) 56 #define XM_SUCCEEDED(_xmresult) ((bool)XM_LIKELY(!XM_FAILED_impl(_xmresult))) 57 //------------------------------------------------------------------------------ 61 #define XM_ASSERT(x) \ 64 if (xms::xmAsserting()) \ 69 #define XM_ASSERT(x) ((void)0) 82 #define XM_ENSURE_SUCCESS_5(x, ret, lvl, msg, ast) \ 85 xms::xmresult __rv = x; \ 86 if (XM_FAILED(__rv)) \ 106 #define XM_ENSURE_SUCCESS_3(x, ret, ast) \ 107 XM_ENSURE_SUCCESS_5(x, ret, xmlog::debug, "XM_ENSURE_SUCCESS(" #x ", " #ret ") failed", ast) 112 #define XM_ENSURE_SUCCESS(...) \ 114 BOOST_PP_OVERLOAD(XM_ENSURE_SUCCESS_, __VA_ARGS__, xms::XM1)(__VA_ARGS__, xms::XM1), \ 119 #define XM_ENSURE_SUCCESS_NO_ASSERT(...) \ 121 BOOST_PP_OVERLOAD(XM_ENSURE_SUCCESS_, __VA_ARGS__, xms::XM0)(__VA_ARGS__, xms::XM0), \ 134 #define XM_ENSURE_SUCCESS_T_5(x, ret, lvl, msg, ast) \ 137 xms::xmresult __rv = x; \ 138 if (XM_FAILED(__rv)) \ 158 #define XM_ENSURE_SUCCESS_T_3(x, ret, ast) \ 159 XM_ENSURE_SUCCESS_T_5(x, ret, xmlog::debug, "XM_ENSURE_SUCCESS_T(" #x ", " #ret ") failed", ast) 164 #define XM_ENSURE_SUCCESS_T(...) \ 166 BOOST_PP_OVERLOAD(XM_ENSURE_SUCCESS_T_, __VA_ARGS__, xms::XM1)(__VA_ARGS__, xms::XM1), \ 171 #define XM_ENSURE_SUCCESS_T_NO_ASSERT(...) \ 173 BOOST_PP_OVERLOAD(XM_ENSURE_SUCCESS_T_, __VA_ARGS__, xms::XM0)(__VA_ARGS__, xms::XM0), \ 185 #define XM_ENSURE_SUCCESS_VOID_4(x, lvl, msg, ast) \ 188 xms::xmresult __rv = x; \ 189 if (XM_FAILED(__rv)) \ 208 #define XM_ENSURE_SUCCESS_VOID_2(x, ast) \ 209 XM_ENSURE_SUCCESS_VOID_4(x, xmlog::debug, "XM_ENSURE_SUCCESS_VOID(" #x ") failed", ast) 215 #define XM_ENSURE_SUCCESS_VOID(...) \ 217 BOOST_PP_OVERLOAD(XM_ENSURE_SUCCESS_VOID_, __VA_ARGS__, xms::XM1)(__VA_ARGS__, xms::XM1), \ 223 #define XM_ENSURE_SUCCESS_VOID_NO_ASSERT(...) \ 225 BOOST_PP_OVERLOAD(XM_ENSURE_SUCCESS_VOID_, __VA_ARGS__, xms::XM0)(__VA_ARGS__, xms::XM0), \ 238 #define XM_ENSURE_TRUE_5(x, ret, lvl, msg, ast) \ 241 if (XM_UNLIKELY(!(x))) \ 261 #define XM_ENSURE_TRUE_3(x, ret, ast) \ 262 XM_ENSURE_TRUE_5(x, ret, xmlog::debug, "XM_ENSURE_TRUE(" #x ", " #ret ") failed", ast) 271 #define XM_ENSURE_TRUE_2(x, ast) XM_ENSURE_TRUE_VOID_2(x, ast) 276 #define XM_ENSURE_TRUE(...) \ 277 BOOST_PP_CAT(BOOST_PP_OVERLOAD(XM_ENSURE_TRUE_, __VA_ARGS__, xms::XM1)(__VA_ARGS__, xms::XM1), \ 282 #define XM_ENSURE_TRUE_NO_ASSERT(...) \ 283 BOOST_PP_CAT(BOOST_PP_OVERLOAD(XM_ENSURE_TRUE_, __VA_ARGS__, xms::XM0)(__VA_ARGS__, xms::XM0), \ 296 #define XM_ENSURE_TRUE_T_5(x, ret, lvl, msg, ast) \ 299 if (XM_UNLIKELY(!(x))) \ 319 #define XM_ENSURE_TRUE_T_3(x, ret, ast) \ 320 XM_ENSURE_TRUE_T_5(x, ret, xmlog::debug, "XM_ENSURE_TRUE_T(" #x ", " #ret ") failed", ast) 325 #define XM_ENSURE_TRUE_T(...) \ 326 BOOST_PP_CAT(BOOST_PP_OVERLOAD(XM_ENSURE_TRUE_T_, __VA_ARGS__, xms::XM1)(__VA_ARGS__, xms::XM1), \ 331 #define XM_ENSURE_TRUE_T_NO_ASSERT(...) \ 332 BOOST_PP_CAT(BOOST_PP_OVERLOAD(XM_ENSURE_TRUE_T_, __VA_ARGS__, xms::XM0)(__VA_ARGS__, xms::XM0), \ 344 #define XM_ENSURE_TRUE_VOID_4(x, lvl, msg, ast) \ 347 if (XM_UNLIKELY(!(x))) \ 366 #define XM_ENSURE_TRUE_VOID_2(x, ast) \ 367 XM_ENSURE_TRUE_VOID_4(x, xmlog::debug, "XM_ENSURE_TRUE_VOID(" #x ") failed", ast) 372 #define XM_ENSURE_TRUE_VOID(...) \ 374 BOOST_PP_OVERLOAD(XM_ENSURE_TRUE_VOID_, __VA_ARGS__, xms::XM1)(__VA_ARGS__, xms::XM1), \ 379 #define XM_ENSURE_TRUE_VOID_NO_ASSERT(...) \ 381 BOOST_PP_OVERLOAD(XM_ENSURE_TRUE_VOID_, __VA_ARGS__, xms::XM0)(__VA_ARGS__, xms::XM0), \ 394 #define XM_ENSURE_FALSE_5(x, ret, lvl, msg, ast) XM_ENSURE_TRUE_5(!(x), ret, lvl, msg, ast) 404 #define XM_ENSURE_FALSE_3(x, ret, ast) \ 405 XM_ENSURE_FALSE_5(x, ret, xmlog::debug, "XM_ENSURE_FALSE(" #x ", " #ret ") failed", ast) 410 #define XM_ENSURE_FALSE(...) \ 411 BOOST_PP_CAT(BOOST_PP_OVERLOAD(XM_ENSURE_FALSE_, __VA_ARGS__, xms::XM1)(__VA_ARGS__, xms::XM1), \ 416 #define XM_ENSURE_FALSE_NO_ASSERT(...) \ 417 BOOST_PP_CAT(BOOST_PP_OVERLOAD(XM_ENSURE_FALSE_, __VA_ARGS__, xms::XM0)(__VA_ARGS__, xms::XM0), \ 430 #define XM_ENSURE_FALSE_T_5(x, ret, lvl, msg, ast) XM_ENSURE_TRUE_T(!(x), ret, lvl, msg, ast) 440 #define XM_ENSURE_FALSE_T_3(x, ret, ast) \ 441 XM_ENSURE_FALSE_T_5(x, ret, xmlog::debug, "XM_ENSURE_FALSE_T(" #x ", " #ret ") failed", ast) 446 #define XM_ENSURE_FALSE_T(...) \ 448 BOOST_PP_OVERLOAD(XM_ENSURE_FALSE_T_, __VA_ARGS__, xms::XM1)(__VA_ARGS__, xms::XM1), \ 453 #define XM_ENSURE_FALSE_T_NO_ASSERT(...) \ 455 BOOST_PP_OVERLOAD(XM_ENSURE_FALSE_T_, __VA_ARGS__, xms::XM0)(__VA_ARGS__, xms::XM0), \ 467 #define XM_ENSURE_FALSE_VOID_4(x, lvl, msg, ast) XM_ENSURE_TRUE_VOID_4(!(x), lvl, msg, ast) 476 #define XM_ENSURE_FALSE_VOID_2(x, ast) \ 477 XM_ENSURE_FALSE_VOID_4(x, xmlog::debug, "XM_ENSURE_FALSE_VOID(" #x ") failed", ast) 482 #define XM_ENSURE_FALSE_VOID(...) \ 484 BOOST_PP_OVERLOAD(XM_ENSURE_FALSE_VOID_, __VA_ARGS__, xms::XM1)(__VA_ARGS__, xms::XM1), \ 489 #define XM_ENSURE_FALSE_VOID_NO_ASSERT(...) \ 491 BOOST_PP_OVERLOAD(XM_ENSURE_FALSE_VOID_, __VA_ARGS__, xms::XM0)(__VA_ARGS__, xms::XM0), \ 498 #define XM_RETURN_XMRESULT(x) \ 500 return (XM_LIKELY(x) ? XR_SUCCESS : XR_FAILURE); \ bool & xmAsserting()
Stores whether we want XM_ASSERT to do something or not.
xmresult
Like Mozilla's nsresult.
unsigned int XM_FAILED_impl(xmresult _xmresult)
Like Mozilla's NS_FAILED in their nsError.h file.
Routines for creating and writing to logs and stacking errors.