HoviTron Video Pipeline
Macros | Functions
openXRHelp.h File Reference

Some useful functions from the openXR sample (hello_xr) More...

#include "SourcesVulkan/commonVulkan.h"
#include <cstdarg>

Go to the source code of this file.

Macros

#define ENUM_CASE_STR(name, val)   case name: return #name;
 
#define MAKE_TO_STRING_FUNC(enumType)
 
#define CHK_STRINGIFY(x)   #x
 
#define TOSTRING(x)   CHK_STRINGIFY(x)
 
#define FILE_AND_LINE   __FILE__ ":" TOSTRING(__LINE__)
 
#define THROW(msg)   Throw(msg, nullptr, FILE_AND_LINE);
 
#define CHECK(exp)
 
#define CHECK_MSG(exp, msg)
 
#define THROW_XR(xr, cmd)   ThrowXrResult(xr, #cmd, FILE_AND_LINE);
 
#define CHECK_XRCMD(cmd)   CheckXrResult(cmd, #cmd, FILE_AND_LINE);
 
#define CHECK_XRRESULT(res, cmdStr)   CheckXrResult(res, cmdStr, FILE_AND_LINE);
 

Functions

 MAKE_TO_STRING_FUNC (XrReferenceSpaceType)
 
 MAKE_TO_STRING_FUNC (XrViewConfigurationType)
 
 MAKE_TO_STRING_FUNC (XrEnvironmentBlendMode)
 
 MAKE_TO_STRING_FUNC (XrSessionState)
 
 MAKE_TO_STRING_FUNC (XrResult)
 
 MAKE_TO_STRING_FUNC (XrFormFactor)
 
std::string Fmt (const char *fmt,...)
 
void Throw (std::string failureMessage, const char *originator=nullptr, const char *sourceLocation=nullptr)
 
void ThrowXrResult (XrResult res, const char *originator=nullptr, const char *sourceLocation=nullptr)
 
XrResult CheckXrResult (XrResult res, const char *originator=nullptr, const char *sourceLocation=nullptr)
 
std::vector< const char * > ParseExtensionString (char *names)
 

Detailed Description

Some useful functions from the openXR sample (hello_xr)

This file contains some usefull function, macro and struct to be used with openxr. The code here is mainly relate to error handling and getting error message with meaning.

Definition in file openXRHelp.h.

Macro Definition Documentation

◆ CHECK

#define CHECK (   exp)
Value:
{ \
if (!(exp)) { \
Throw("Check failed", #exp, FILE_AND_LINE); \
} \
}

Definition at line 87 of file openXRHelp.h.

◆ CHECK_MSG

#define CHECK_MSG (   exp,
  msg 
)
Value:
{ \
if (!(exp)) { \
Throw(msg, #exp, FILE_AND_LINE); \
} \
}

Definition at line 93 of file openXRHelp.h.

◆ CHECK_XRCMD

#define CHECK_XRCMD (   cmd)    CheckXrResult(cmd, #cmd, FILE_AND_LINE);

Definition at line 113 of file openXRHelp.h.

◆ CHECK_XRRESULT

#define CHECK_XRRESULT (   res,
  cmdStr 
)    CheckXrResult(res, cmdStr, FILE_AND_LINE);

Definition at line 114 of file openXRHelp.h.

◆ CHK_STRINGIFY

#define CHK_STRINGIFY (   x)    #x

Definition at line 71 of file openXRHelp.h.

◆ ENUM_CASE_STR

#define ENUM_CASE_STR (   name,
  val 
)    case name: return #name;

Definition at line 33 of file openXRHelp.h.

◆ FILE_AND_LINE

#define FILE_AND_LINE   __FILE__ ":" TOSTRING(__LINE__)

Definition at line 73 of file openXRHelp.h.

◆ MAKE_TO_STRING_FUNC

#define MAKE_TO_STRING_FUNC (   enumType)
Value:
inline const char* to_string(enumType e) { \
switch (e) { \
XR_LIST_ENUM_##enumType(ENUM_CASE_STR) \
default: return "Unknown " #enumType; \
} \
}

Definition at line 34 of file openXRHelp.h.

◆ THROW

#define THROW (   msg)    Throw(msg, nullptr, FILE_AND_LINE);

Definition at line 86 of file openXRHelp.h.

◆ THROW_XR

#define THROW_XR (   xr,
  cmd 
)    ThrowXrResult(xr, #cmd, FILE_AND_LINE);

Definition at line 112 of file openXRHelp.h.

◆ TOSTRING

#define TOSTRING (   x)    CHK_STRINGIFY(x)

Definition at line 72 of file openXRHelp.h.

Function Documentation

◆ CheckXrResult()

XrResult CheckXrResult ( XrResult  res,
const char *  originator = nullptr,
const char *  sourceLocation = nullptr 
)
inline

Definition at line 104 of file openXRHelp.h.

104 {
105 if (XR_FAILED(res)) {
106 ThrowXrResult(res, originator, sourceLocation);
107 }
108
109 return res;
110}

◆ Fmt()

std::string Fmt ( const char *  fmt,
  ... 
)
inline

Definition at line 50 of file openXRHelp.h.

50 {
51 va_list vl;
52 va_start(vl, fmt);
53 int size = std::vsnprintf(nullptr, 0, fmt, vl);
54 va_end(vl);
55
56 if (size != -1) {
57 std::unique_ptr<char[]> buffer(new char[size + 1]);
58
59 va_start(vl, fmt);
60 size = std::vsnprintf(buffer.get(), size + 1, fmt, vl);
61 va_end(vl);
62 if (size != -1) {
63 return std::string(buffer.get(), size);
64 }
65 }
66
67 throw std::runtime_error("Unexpected vsnprintf failure");
68}

◆ ParseExtensionString()

std::vector< const char * > ParseExtensionString ( char *  names)
inline

Definition at line 116 of file openXRHelp.h.

116 {
117 std::vector<const char*> list;
118 while (*names != 0) {
119 list.push_back(names);
120 while (*(++names) != 0) {
121 if (*names == ' ') {
122 *names++ = '\0';
123 break;
124 }
125 }
126 }
127 return list;
128}

◆ Throw()

void Throw ( std::string  failureMessage,
const char *  originator = nullptr,
const char *  sourceLocation = nullptr 
)
inline

Definition at line 75 of file openXRHelp.h.

75 {
76 if (originator != nullptr) {
77 failureMessage += Fmt("\n Origin: %s", originator);
78 }
79 if (sourceLocation != nullptr) {
80 failureMessage += Fmt("\n Source: %s", sourceLocation);
81 }
82
83 throw std::logic_error(failureMessage);
84}

◆ ThrowXrResult()

void ThrowXrResult ( XrResult  res,
const char *  originator = nullptr,
const char *  sourceLocation = nullptr 
)
inline

Definition at line 100 of file openXRHelp.h.

100 {
101 Throw(Fmt("XrResult failure [%s]", to_string(res)), originator, sourceLocation);
102}