12 #include "../Common.h" 14 #ifdef XRTRAITS_HAVE_CONSTEXPR_IF 29 #ifndef XRTRAITS_DOXYGEN 31 using ::std::conditional_t;
32 using ::std::enable_if_t;
33 using ::std::is_const;
34 using ::std::is_pointer;
35 using ::std::is_reference;
37 using ::std::remove_pointer_t;
42 template <
typename SourceType>
43 using possibly_const_void_ptr =
44 conditional_t<is_const<remove_pointer_t<SourceType>>::value,
52 template <
typename SourceType>
53 inline auto risky_get_next(SourceType source)
56 is_same_v<SourceType, const void*> ||
57 is_same_v<SourceType, void*>,
58 "risky_get_next is only for void* or const void*");
59 return cast_to_base(source)->next;
65 template <
typename TargetType,
typename SourceType>
66 inline void xr_get_chained_struct_static_assertions()
68 constexpr
bool is_source_void =
69 is_same_v<remove_reference_pointer_cv_t<SourceType>,
71 constexpr
bool is_source_xr_tagged =
72 traits::is_xr_tagged_type_v<SourceType>;
73 constexpr
bool is_source_void_or_xr_tagged =
74 is_source_void || is_source_xr_tagged;
81 is_pointer_v<SourceType> &&
82 is_source_void_or_xr_tagged,
83 "Can only use xr_get_chained_struct to traverse " 84 "starting from a pointer to (possibly const) void, " 85 "or from a pointer to a (possibly const) XR tagged " 88 is_pointer_v<TargetType> &&
89 traits::is_xr_tagged_type_v<TargetType>,
90 "Can only use xr_get_chained_struct to " 91 "find and cast to a pointer to a " 92 "(possibly const) XR tagged type.");
100 traits::has_xr_type_tag_v<TargetType>,
101 "Can only use xr_get_chained_struct to find and " 102 "cast to a pointer/reference to a concrete XR " 103 "tagged type with a known, defined type tag value " 104 "(XrStructureType enum value).");
107 remove_reference_pointer_t<SourceType>>::value
108 ? std::is_const<remove_reference_pointer_t<
111 "Cannot remove const qualification through " 112 "xr_get_chained_struct");
119 template <
typename TargetType,
typename SourceType>
120 inline TargetType xr_get_chained_struct_impl(SourceType src)
122 while (
nullptr != src) {
130 src = risky_get_next(src);
137 #endif // !XRTRAITS_DOXYGEN 171 template <
typename TargetType,
typename SourceType>
175 detail::xr_get_chained_struct_static_assertions<TargetType,
179 using type_erased_input_ptr =
180 detail::possibly_const_void_ptr<SourceType*>;
183 return detail::xr_get_chained_struct_impl<TargetType>(
184 static_cast<type_erased_input_ptr
>(src));
196 detail::xr_get_chained_struct_static_assertions<T*, T*>();
200 using type_erased_input_ptr =
201 detail::possibly_const_void_ptr<T*>;
204 return detail::xr_get_chained_struct_impl<T*>(
205 static_cast<type_erased_input_ptr
>(src));
211 #endif // XRTRAITS_HAVE_CONSTEXPR_IF Main namespace for these C++ OpenXR utilities.
Definition: GetChained.h:26
Header providing a slightly-riskier relative of xr_tagged_dynamic_cast() that works on void pointers ...
Header shared between the two type-safe cast headers.
TargetType xr_get_chained_struct(SourceType *src)
Definition: GetChained.h:172
TargetType xr_tagged_risky_cast(SourceType source)
Definition: TaggedRiskyCast.h:110