Monado OpenXR Runtime

X_macro definitions for XRT enums to facilitate code generation.

Collaboration diagram for X_macro Lists:

X_macro definitions for XRT enums to facilitate code generation.

These macros allow you to programmatically iterate over all values in an enum without manually maintaining lists in multiple places.

Each enum that has been processed will have a corresponding <ENUM_NAME>_LIST macro defined in the included file.

Usage Examples

Example 1 - Generate a string conversion function:

const char* xrt_result_to_string(xrt_result_t result) {
switch(result) {
#define CASE_STR(name) case name: return #name;
XRT_RESULT_LIST(CASE_STR)
#undef CASE_STR
default: return "UNKNOWN";
}
}
enum xrt_result xrt_result_t
Result type used across Monado.

Example 2 - Generate an array of all enum values:

static const xrt_result_t all_results[] = {
#define ENUM_VALUE(name) name,
XRT_RESULT_LIST(ENUM_VALUE)
#undef ENUM_VALUE
};

Example 3 - Count the number of enum values:

#define COUNT_ONE(name) 1 +
static const int num_results = XRT_RESULT_LIST(COUNT_ONE) 0;
#undef COUNT_ONE