XRTraits C++ OpenXR Utilities
Functions
Cast-Like Functions

Casts for OpenXR tagged types, as well as utilities for traversing a next chain. More...

Functions

template<typename TargetType , typename SourceType >
TargetType xrtraits::casts::xr_get_chained_struct (SourceType *src)
 
template<typename T >
T * xrtraits::casts::xr_get_chained_struct (T *src)
 
template<typename TargetType , typename SourceType >
TargetType xrtraits::casts::xr_tagged_dynamic_cast (SourceType &&source)
 
template<typename TargetType , typename SourceType >
TargetType xrtraits::casts::xr_tagged_risky_cast (SourceType source)
 

Detailed Description

Casts for OpenXR tagged types, as well as utilities for traversing a next chain.

Function Documentation

◆ xr_get_chained_struct() [1/2]

template<typename TargetType , typename SourceType >
TargetType xrtraits::casts::xr_get_chained_struct ( SourceType *  src)
inline

#include <xrtraits/casts/GetChained.h>

Follow the chained next pointers in an OpenXR tagged struct until we reach the end or find one matching the desired type.

If no desired type is given, it is assumed to be the same as the source type, as is used in API entry point implementations.

Given a type that is a pointer to a (possibly const) OpenXR tagged struct with known tag, and an input pointer that is either (possibly const) void * or a pointer to a (possibly const) OpenXR tagged struct, iterate through the current struct and all chained structs found via the next pointer, until a nullptr is hit or we find one whose tag matches the tag expected for the target type.

If a match is found, it is casted to the same "const-ness" as the input and returned. If no match is found, then nullptr is returned.

Unlike xr_tagged_risky_cast() and xr_tagged_dynamic_cast(), this function has a high likelihood of not finding what it is looking for, so there is no support for returning a reference type.

See also
xr_tagged_risky_cast() to which this function is closely related

Source parameter is specified as SourceType * src instead of SourceType src to avoid getting std::nullptr_t as SourceType.

◆ xr_get_chained_struct() [2/2]

template<typename T >
T* xrtraits::casts::xr_get_chained_struct ( T *  src)
inline

#include <xrtraits/casts/GetChained.h>

Overload that doesn't require explicit specification of a template parameter, for "converting" a type to the type it already is.

◆ xr_tagged_dynamic_cast()

template<typename TargetType , typename SourceType >
TargetType xrtraits::casts::xr_tagged_dynamic_cast ( SourceType &&  source)
inline

#include <xrtraits/casts/TaggedDynamicCast.h>

OpenXR structure cast, analogous to the standard dynamic_cast.

Provide a single type parameter (target type) as well as the pointer/reference parameter.

Input should be a pointer or reference to a (possibly const) structure, with static type starting with XrStructureType type; const void * next;. The type member of the input is examined to ensure it matches the value defined by the spec (as indicated by generated type traits) for the TargetType provided.

  • If TargetType is a pointer type, then a mismatch of type (or input of nullptr) results in a nullptr return.
  • If TargetType is a reference type, then a mismatch of type (or input of nullptr) results in a bad_tagged_cast exception.

References XRTRAITS_MAYBE_UNUSED.

◆ xr_tagged_risky_cast()

template<typename TargetType , typename SourceType >
TargetType xrtraits::casts::xr_tagged_risky_cast ( SourceType  source)
inline

#include <xrtraits/casts/TaggedRiskyCast.h>

OpenXR structure cast, somewhat analogous to a slightly-riskier version of the standard dynamic_cast.

Cast a void * (or void const *) that is assumed to be a pointer to some XR tagged type, to a given XR tagged type pointer, if the tag matches. Provide a single type parameter (target type) as well as the input pointer.

Undefined behavior if the void * is not a pointer to some XR tagged type, because we behave as if it were! If you have an actual specific type, not just a tag, then see xr_tagged_dynamic_cast pointer/reference parameter.

Input should be a pointer or reference to a (possibly const) structure, with static type starting with XrStructureType type; const void * next;. The type member of the input is examined to ensure it matches the value defined by the spec (as indicated by generated type traits) for the TargetType provided.

  • If TargetType is a pointer type, then a mismatch of type (or null input) results in a nullptr return.
  • If TargetType is a reference type, then a mismatch of type (or null input) results in a bad_tagged_cast exception.

Unlike xr_tagged_dynamic_cast, this function cannot take references as input.

References xrtraits::is_same_v, and XRTRAITS_MAYBE_UNUSED.