XRTraits C++ OpenXR Utilities
TypeError.h
Go to the documentation of this file.
1 // Copyright 2018-2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Header
6  * @author Ryan Pavlik <ryan.pavlik@collabora.com>
7  */
8 
9 #pragma once
10 
11 #ifdef XRTRAITS_USE_EXCEPTIONS
12 
13 // Internal Includes
14 #include "BaseExceptions.h" // IWYU pragma: export
15 
16 // Library Includes
17 // - none
18 
19 // Standard Includes
20 #include <cstddef> // for std::nullptr_t
21 
22 namespace xrtraits {
23 namespace exceptions {
24 
25  /*!
26  * Default error code for type errors.
27  *
28  * @relates type_error
29  */
30  static constexpr XrResult DEFAULT_TYPE_ERROR_CODE =
31  XR_ERROR_VALIDATION_FAILURE;
32 
33  /*!
34  * Exception thrown by xrtraits::verifyDynamicType() and friends when
35  * input isn't the type required.
36  *
37  * @ingroup exceptions
38  */
40  {
41  /*!
42  * Constructor taking a message
43  */
44  type_error(std::string&& msg, XrResult result);
45 
46  /*!
47  * Constructor for getting nullptr instead of the given type as
48  * a parameter
49  */
50  type_error(const char* paramName, std::nullptr_t,
51  XrStructureType expectedType, XrResult result);
52 
53  /*!
54  * Constructor for getting something other than the expected
55  * type as a parameter
56  */
57  type_error(const char* paramName, XrStructureType actualType,
58  XrStructureType expectedType, XrResult result);
59 
60  /*! Constructor for getting something other than the expected
61  * type as an array element.
62  */
63  type_error(const char* paramName, XrStructureType actualType,
64  XrStructureType expectedType, std::ptrdiff_t index,
65  XrResult result);
66 
67  /*! Constructor for getting nullptr instead of a pointer to an
68  * array of the given size and type.
69  */
70  type_error(const char* paramName, std::nullptr_t,
71  XrStructureType expectedType, std::ptrdiff_t size,
72  XrResult result);
73  };
74 
75  /*!
76  * Exception thrown by xrtraits::getFromChain() and friends when input
77  * doesn't include the type required.
78  *
79  * @ingroup exceptions
80  */
82  {
83  /*!
84  * Constructor taking a message.
85  */
86  get_from_chain_error(std::string&& msg, XrResult result);
87 
88  /*!
89  * Constructor for getting nullptr instead of a chain containing
90  * a desired type.
91  */
92  get_from_chain_error(const char* paramName, std::nullptr_t,
93  XrStructureType expectedType,
94  XrResult result);
95 
96  /*!
97  * Constructor for not finding the desired type in a struct
98  * chain.
99  */
100  get_from_chain_error(const char* paramName,
101  XrStructureType headType,
102  XrStructureType expectedType,
103  XrResult result);
104  };
105 } // namespace exceptions
106 } // namespace xrtraits
107 
108 #endif // XRTRAITS_USE_EXCEPTIONS
Main namespace for these C++ OpenXR utilities.
Definition: GetChained.h:26
Definition: BaseExceptions.h:163
XrResult result() const noexcept
type_error(std::string &&msg, XrResult result)
Definition: TypeError.h:39