7#include "Base/Headers/String.h"
8#include "Base/Headers/Exception.h"
9#include "Base/Headers/Translator.h"
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; \
26MAKE_TO_STRING_FUNC(XrReferenceSpaceType);
27MAKE_TO_STRING_FUNC(XrViewConfigurationType);
28MAKE_TO_STRING_FUNC(XrEnvironmentBlendMode);
29MAKE_TO_STRING_FUNC(XrSessionState);
30MAKE_TO_STRING_FUNC(XrResult);
31MAKE_TO_STRING_FUNC(XrFormFactor);
33#define CHK_STRINGIFY(x) #x
34#define TOSTRING(x) CHK_STRINGIFY(x)
35#define FILE_AND_LINE __FILE__ ":" TOSTRING(__LINE__)
42 [[noreturn]]
inline void Throw(
StringView failure_message,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr)
44 String message(failure_message);
45 if (originator !=
nullptr) {
46 message +=
StringView(
"\n Origin: ") + originator;
48 if (sourceLocation !=
nullptr) {
49 message +=
StringView(
"\n Source: ")+ sourceLocation;
55#define THROW(msg) Throw(msg, nullptr, FILE_AND_LINE);
59 Throw("Check failed", #exp, FILE_AND_LINE); \
62#define CHECK_MSG(exp, msg) \
65 Throw(msg, #exp, FILE_AND_LINE); \
73 [[noreturn]]
inline void ThrowXrResult(XrResult res,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
74 String s(
"XrResult failure ");
76 Throw(s, originator, sourceLocation);
84 inline XrResult
CheckXrResult(XrResult res,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
92#define THROW_XR(xr, cmd) ThrowXrResult(xr, #cmd, FILE_AND_LINE);
93#define CHECK_XRCMD(cmd) CheckXrResult(cmd, #cmd, FILE_AND_LINE);
94#define CHECK_XRRESULT(res, cmdStr) CheckXrResult(res, cmdStr, FILE_AND_LINE);
96#ifdef XR_USE_PLATFORM_WIN32
98 [[noreturn]]
inline void ThrowHResult(HRESULT hr,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
99 Throw(Fmt(
"HRESULT failure [%x]", hr), originator, sourceLocation);
102 inline HRESULT CheckHResult(HRESULT hr,
const char* originator =
nullptr,
const char* sourceLocation =
nullptr) {
104 ThrowHResult(hr, originator, sourceLocation);
110#define THROW_HR(hr, cmd) ThrowHResult(hr, #cmd, FILE_AND_LINE);
111#define CHECK_HRCMD(cmd) CheckHResult(cmd, #cmd, FILE_AND_LINE);
112#define CHECK_HRESULT(res, cmdStr) CheckHResult(res, cmdStr, FILE_AND_LINE);
Provides consistent interface to handle errors through the throw expression.
The core String View class for the NDEVR API.
The core String class for the NDEVR API.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
The primary namespace for the NDEVR SDK.
void Throw(StringView failure_message, const char *originator=nullptr, const char *sourceLocation=nullptr)
Throw an Exception with an OpenXR error message, optional originator, and source location.
void ThrowXrResult(XrResult res, const char *originator=nullptr, const char *sourceLocation=nullptr)
Throw an Exception for a failed XrResult.
XrResult CheckXrResult(XrResult res, const char *originator=nullptr, const char *sourceLocation=nullptr)
Check an XrResult and throw if it indicates failure.