OGLplus  (0.59.0) a C++ wrapper for rendering APIs

result.hpp
Go to the documentation of this file.
1 #ifndef EGLPLUS_EGL_API_RESULT_HPP
9 #define EGLPLUS_EGL_API_RESULT_HPP
10 
11 #include "config.hpp"
12 #include <eagine/anything.hpp>
13 #include <eagine/c_api_wrap.hpp>
14 #include <eagine/string_span.hpp>
15 
16 namespace eagine::eglp {
17 //------------------------------------------------------------------------------
23 public:
24  constexpr auto error_code(anything) noexcept -> auto& {
25  return *this;
26  }
27 
29  constexpr auto message() const noexcept -> string_view {
30  return {"EGL function not available"};
31  }
32 
33 private:
34 };
35 //------------------------------------------------------------------------------
41 public:
43  explicit constexpr operator bool() const noexcept {
44  return egl_types::error_code_no_error(_error_code);
45  }
46 
47  constexpr auto error_code(egl_types::int_type ec) noexcept -> auto& {
48  _error_code = ec;
49  return *this;
50  }
51 
53  auto message() const noexcept -> string_view {
54 #ifdef EGL_BAD_SURFACE
55  if(_error_code == EGL_BAD_SURFACE) {
56  return {"bad surface"};
57  }
58 #endif
59 #ifdef EGL_BAD_CURRENT_SURFACE
60  if(_error_code == EGL_BAD_CURRENT_SURFACE) {
61  return {"bad current surface"};
62  }
63 #endif
64 #ifdef EGL_BAD_DISPLAY
65  if(_error_code == EGL_BAD_DISPLAY) {
66  return {"bad display"};
67  }
68 #endif
69 #ifdef EGL_CONTEXT_LOST
70  if(_error_code == EGL_CONTEXT_LOST) {
71  return {"EGL context lost"};
72  }
73 #endif
74 #ifdef EGL_BAD_PARAMETER
75  if(_error_code == EGL_BAD_PARAMETER) {
76  return {"invalid parameter"};
77  }
78 #endif
79 #ifdef EGL_BAD_ATTRIBUTE
80  if(_error_code == EGL_BAD_ATTRIBUTE) {
81  return {"unrecognized attribute or attribute value"};
82  }
83 #endif
84 #ifdef EGL_BAD_CONFIG
85  if(_error_code == EGL_BAD_CONFIG) {
86  return {"invalid configuration"};
87  }
88 #endif
89 #ifdef EGL_BAD_CONTEXT
90  if(_error_code == EGL_BAD_CONTEXT) {
91  return {"invalid context"};
92  }
93 #endif
94 #ifdef EGL_BAD_NATIVE_PIXMAP
95  if(_error_code == EGL_BAD_NATIVE_PIXMAP) {
96  return {"bad native pixmap"};
97  }
98 #endif
99 #ifdef EGL_BAD_NATIVE_WINDOW
100  if(_error_code == EGL_BAD_NATIVE_WINDOW) {
101  return {"bad native window"};
102  }
103 #endif
104 #ifdef EGL_BAD_MATCH
105  if(_error_code == EGL_BAD_MATCH) {
106  return {"inconsistent attributes"};
107  }
108 #endif
109 #ifdef EGL_BAD_ACCESS
110  if(_error_code == EGL_BAD_ACCESS) {
111  return {"cannot access requested resource"};
112  }
113 #endif
114 #ifdef EGL_NOT_INITIALIZED
115  if(_error_code == EGL_NOT_INITIALIZED) {
116  return {"EGL not initialized"};
117  }
118 #endif
119 #ifdef EGL_BAD_STREAM_KHR
120  if(_error_code == EGL_BAD_STREAM_KHR) {
121  return {"bad EGL stream"};
122  }
123 #endif
124 #ifdef EGL_BAD_OUTPUT_LAYER_EXT
125  if(_error_code == EGL_BAD_OUTPUT_LAYER_EXT) {
126  return {"bad EGL output layer"};
127  }
128 #endif
129 #ifdef EGL_BAD_OUTPUT_PORT_EXT
130  if(_error_code == EGL_BAD_OUTPUT_PORT_EXT) {
131  return {"bad EGL output port"};
132  }
133 #endif
134 #ifdef EGL_BAD_STATE_KHR
135  if(_error_code == EGL_BAD_STATE_KHR) {
136  return {"bad EGL state"};
137  }
138 #endif
139 #ifdef EGL_SUCCESS
140  if(_error_code == EGL_SUCCESS) {
141  return {"no error"};
142  }
143 #endif
144 #ifdef EGL_BAD_ALLOC
145  if(_error_code == EGL_BAD_ALLOC) {
146  return {"out of memory"};
147  }
148 #endif
149  return {"unknown error"};
150  }
151 
152 private:
153  egl_types::int_type _error_code{
154 #ifdef EGL_SUCCESS
155  EGL_SUCCESS
156 #endif
157  };
158 };
159 //------------------------------------------------------------------------------
164 template <typename Result>
166 //------------------------------------------------------------------------------
171 template <typename Result>
173 //------------------------------------------------------------------------------
178 template <typename Result>
180 //------------------------------------------------------------------------------
181 } // namespace eagine::eglp
182 
183 #endif // EGLPLUS_EGL_API_RESULT_HPP
Class wrapping the result of a C-API function call.
Definition: c_api_wrap.hpp:210
api_no_result< Result, egl_no_result_info > egl_no_result
Alias for always-invalid result of a missing EGL API function call.
Definition: result.hpp:165
Class storing information about call result for unavailable EGL functions.
Definition: result.hpp:22
EGL-related code is placed in this namespace.
Definition: eglplus.hpp:11
Typed enumeration for EGL error code constants.
Definition: enum_types.hpp:31
auto message() const noexcept -> string_view
Returns a message associated with the result.
Definition: result.hpp:53
api_opt_result< Result, egl_result_info > egl_opt_result
Alias for conditionally-valid result of a EGL API function call.
Definition: result.hpp:179
api_result< Result, Info, api_result_validity::maybe > api_opt_result
Alias for conditionally-valid result of a C-API function call.
Definition: c_api_wrap.hpp:218
api_result< Result, Info, api_result_validity::never > api_no_result
Alias for always-invalid result of a C-API function call.
Definition: c_api_wrap.hpp:226
Class storing information about an EGL function call result.
Definition: result.hpp:40
EGLint int_type
Signed integer type.
Definition: config.hpp:116
Type that can by constructed from single argument of any other type.
Definition: anything.hpp:16
constexpr auto message() const noexcept -> string_view
Returns a message associated with the result.
Definition: result.hpp:29

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).