10#include <openxr/openxr.h>
12#include <openxr/openxr_reflection.h>
16#define ENUM_CASE_STR(name, val) case name: return #name;
17#define MAKE_TO_STRING_FUNC(enumType) \
18 inline const char* to_string(enumType e) { \
20 XR_LIST_ENUM_##enumType(ENUM_CASE_STR) \
21 default: return "Unknown " #enumType; \
33#define CHK_STRINGIFY(x) #x
34#define TOSTRING(x) CHK_STRINGIFY(x)
35#define FILE_AND_LINE __FILE__ ":" TOSTRING(__LINE__)
38 [[noreturn]]
inline void Throw(
String failureMessage,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
39 if (originator !=
nullptr) {
40 failureMessage +=
String(
"\n Origin: ") + originator;
42 if (sourceLocation !=
nullptr) {
43 failureMessage +=
String(
"Source: ")+ sourceLocation;
49#define THROW(msg) Throw(msg, nullptr, FILE_AND_LINE);
53 Throw("Check failed", #exp, FILE_AND_LINE); \
56#define CHECK_MSG(exp, msg) \
59 Throw(msg, #exp, FILE_AND_LINE); \
63 [[noreturn]]
inline void ThrowXrResult(XrResult res,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
64 String s(
"XrResult failure ");
66 Throw(s, originator, sourceLocation);
69 inline XrResult
CheckXrResult(XrResult res,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
77#define THROW_XR(xr, cmd) ThrowXrResult(xr, #cmd, FILE_AND_LINE);
78#define CHECK_XRCMD(cmd) CheckXrResult(cmd, #cmd, FILE_AND_LINE);
79#define CHECK_XRRESULT(res, cmdStr) CheckXrResult(res, cmdStr, FILE_AND_LINE);
81#ifdef XR_USE_PLATFORM_WIN32
83 [[noreturn]]
inline void ThrowHResult(HRESULT hr,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
84 Throw(Fmt(
"HRESULT failure [%x]", hr), originator, sourceLocation);
87 inline HRESULT CheckHResult(HRESULT hr,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
89 ThrowHResult(hr, originator, sourceLocation);
95#define THROW_HR(hr, cmd) ThrowHResult(hr, #cmd, FILE_AND_LINE);
96#define CHECK_HRCMD(cmd) CheckHResult(cmd, #cmd, FILE_AND_LINE);
97#define CHECK_HRESULT(res, cmdStr) CheckHResult(res, cmdStr, FILE_AND_LINE);
#define _t(english_string)
Definition Translator.h:90
#define MAKE_TO_STRING_FUNC(enumType)
Definition XRErrorHandling.h:17
const char * to_string(XrReferenceSpaceType e)
Definition XRErrorHandling.h:26
Provides consistent interface to handle errors through the throw expression. All exceptions generated...
Definition Exception.hpp:47
The core String class for the NDEVR API.
Definition String.h:69
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
XrResult CheckXrResult(XrResult res, const char *originator=nullptr, const char *sourceLocation=nullptr)
Definition XRErrorHandling.h:69
void Throw(String failureMessage, const char *originator=nullptr, const char *sourceLocation=nullptr)
Definition XRErrorHandling.h:38
void ThrowXrResult(XrResult res, const char *originator=nullptr, const char *sourceLocation=nullptr)
Definition XRErrorHandling.h:63