14#define CHECK_XRCMD(cmd) xr::detail::_CheckXrResult(cmd, #cmd, FILE_AND_LINE)
15#define CHECK_XRRESULT(res, cmdStr) xr::detail::_CheckXrResult(res, cmdStr, FILE_AND_LINE)
17#define CHECK_HRCMD(cmd) xr::detail::_CheckHResult(cmd, #cmd, FILE_AND_LINE)
18#define CHECK_HRESULT(res, cmdStr) xr::detail::_CheckHResult(res, cmdStr, FILE_AND_LINE)
20#define DEBUG_PRINT(...) ::OutputDebugStringA((xr::detail::_Fmt(__VA_ARGS__) + "\n").c_str())
23#define CHK_STRINGIFY(x) #x
24#define TOSTRING(x) CHK_STRINGIFY(x)
25#define FILE_AND_LINE __FILE__ ":" TOSTRING(__LINE__)
27 inline std::string
_Fmt(
const char* fmt, ...) {
30 int size = std::vsnprintf(
nullptr, 0, fmt, vl);
34 std::unique_ptr<char[]> buffer(
new char[size + 1]);
37 size = std::vsnprintf(buffer.get(), size + 1, fmt, vl);
40 return std::string(buffer.get(), size);
44 throw std::runtime_error(
"Unexpected vsnprintf failure");
47 [[noreturn]]
inline void _Throw(std::string failureMessage,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
48 if (originator !=
nullptr) {
49 failureMessage +=
_Fmt(
"\n Origin: %s", originator);
51 if (sourceLocation !=
nullptr) {
52 failureMessage +=
_Fmt(
"\n Source: %s", sourceLocation);
55 throw std::logic_error(failureMessage);
58#define THROW(msg) xr::detail::_Throw(msg, nullptr, FILE_AND_LINE)
62 xr::detail::_Throw("Check failed", #exp, FILE_AND_LINE); \
65#define CHECK_MSG(exp, msg) \
68 xr::detail::_Throw(msg, #exp, FILE_AND_LINE); \
72 [[noreturn]]
inline void _ThrowXrResult(XrResult res,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
76 inline XrResult
_CheckXrResult(XrResult res,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
85 [[noreturn]]
inline void _ThrowHResult(HRESULT hr,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
89 inline HRESULT _CheckHResult(HRESULT hr,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
91 xr::detail::_ThrowHResult(hr, originator, sourceLocation);
void _ThrowXrResult(XrResult res, const char *originator=nullptr, const char *sourceLocation=nullptr)
XrResult _CheckXrResult(XrResult res, const char *originator=nullptr, const char *sourceLocation=nullptr)
void _Throw(std::string failureMessage, const char *originator=nullptr, const char *sourceLocation=nullptr)
std::string _Fmt(const char *fmt,...)