Monado OpenXR Runtime
oxr_chain.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Utilities for accessing members in an OpenXR structure chain.
6  * @author Ryan Pavlik <ryan.pavlik@collabora.com>
7  */
8 
9 #pragma once
10 
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /*!
18  * @ingroup oxr_api
19  * @{
20  */
21 
22 /*!
23  * Finds an input struct of the given type in a next-chain.
24  *
25  * Returns NULL if nothing matching is found.
26  *
27  * Prefer using OXR_GET_INPUT_FROM_CHAIN() instead, since it includes the
28  * casting.
29  */
30 static inline XrBaseInStructure const *
31 oxr_find_input_in_chain(const void *ptr, XrStructureType desired)
32 {
33  while (ptr != NULL) {
34  XrBaseInStructure const *base = (XrBaseInStructure const *)ptr;
35  if (base->type == desired) {
36  return base;
37  }
38  ptr = base->next;
39  }
40  return NULL;
41 }
42 
43 /*!
44  * Finds an input struct of the given type in a next-chain and casts it as
45  * desired.
46  *
47  * Returns NULL if nothing matching is found.
48  *
49  * Note: There is no protection here to ensure that STRUCTURE_TYPE_ENUM (an
50  * XrStructureType value) and TYPE (a type name) actually match!
51  */
52 #define OXR_GET_INPUT_FROM_CHAIN(PTR, STRUCTURE_TYPE_ENUM, TYPE) \
53  ((TYPE const *)oxr_find_input_in_chain(PTR, STRUCTURE_TYPE_ENUM))
54 
55 /*!
56  * Finds an output struct of the given type in a next-chain.
57  *
58  * Returns NULL if nothing matching is found.
59  *
60  * Prefer using OXR_GET_OUTPUT_FROM_CHAIN() instead, since it includes the
61  * casting.
62  */
63 static inline XrBaseOutStructure *
64 oxr_find_output_in_chain(void *ptr, XrStructureType desired)
65 {
66  while (ptr != NULL) {
67  XrBaseOutStructure *base = (XrBaseOutStructure *)ptr;
68  if (base->type == desired) {
69  return base;
70  }
71  ptr = base->next;
72  }
73  return NULL;
74 }
75 
76 /*!
77  * Finds an output struct of the given type in a next-chain and casts it as
78  * desired.
79  *
80  * Returns NULL if nothing matching is found.
81  *
82  * Note: There is no protection here to ensure that STRUCTURE_TYPE_ENUM (an
83  * XrStructureType value) and TYPE (a type name) actually match!
84  */
85 #define OXR_GET_OUTPUT_FROM_CHAIN(PTR, STRUCTURE_TYPE_ENUM, TYPE) \
86  ((TYPE *)oxr_find_output_in_chain(PTR, STRUCTURE_TYPE_ENUM))
87 
88 /*!
89  * @}
90  */
91 
92 #ifdef __cplusplus
93 }
94 #endif
Include all of the openxr headers in one place.