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

result.hpp
Go to the documentation of this file.
1 #ifndef OALPLUS_ALUT_API_RESULT_HPP
9 #define OALPLUS_ALUT_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::oalp {
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 {"ALUT function not available"};
31  }
32 
33 private:
34 };
35 //------------------------------------------------------------------------------
41 public:
42  using enum_type = alut_types::enum_type;
43 
45  explicit constexpr operator bool() const noexcept {
46  return alut_types::error_code_no_error(_error_code);
47  }
48 
49  constexpr auto error_code(enum_type ec) noexcept -> auto& {
50  _error_code = ec;
51  return *this;
52  }
53 
54  constexpr auto error_code() const noexcept -> enum_type {
55  return _error_code;
56  }
57 
59  auto message() const noexcept -> string_view {
60 #ifdef ALUT_ERROR_INVALID_ENUM
61  if(_error_code == ALUT_ERROR_INVALID_ENUM) {
62  return {"invalid enumeration parameter value"};
63  }
64 #endif
65 #ifdef ALUT_ERROR_INVALID_VALUE
66  if(_error_code == ALUT_ERROR_INVALID_VALUE) {
67  return {"invalid parameter value"};
68  }
69 #endif
70 #ifdef ALUT_ERROR_INVALID_OPERATION
71  if(_error_code == ALUT_ERROR_INVALID_OPERATION) {
72  return {"invalid operation"};
73  }
74 #endif
75 #ifdef ALUT_ERROR_NO_CURRENT_CONTEXT
76  if(_error_code == ALUT_ERROR_NO_CURRENT_CONTEXT) {
77  return {"no current context"};
78  }
79 #endif
80 #ifdef ALUT_ERROR_AL_ERROR_ON_ENTRY
81  if(_error_code == ALUT_ERROR_AL_ERROR_ON_ENTRY) {
82  return {"AL error on entry to function"};
83  }
84 #endif
85 #ifdef ALUT_ERROR_ALC_ERROR_ON_ENTRY
86  if(_error_code == ALUT_ERROR_ALC_ERROR_ON_ENTRY) {
87  return {"ALC error on entry to function"};
88  }
89 #endif
90 #ifdef ALUT_ERROR_OPEN_DEVICE
91  if(_error_code == ALUT_ERROR_OPEN_DEVICE) {
92  return {"failed to open device"};
93  }
94 #endif
95 #ifdef ALUT_ERROR_CLOSE_DEVICE
96  if(_error_code == ALUT_ERROR_CLOSE_DEVICE) {
97  return {"failed to close device"};
98  }
99 #endif
100 #ifdef ALUT_ERROR_CREATE_CONTEXT
101  if(_error_code == ALUT_ERROR_CREATE_CONTEXT) {
102  return {"failed to create context"};
103  }
104 #endif
105 #ifdef ALUT_ERROR_DESTROY_CONTEXT
106  if(_error_code == ALUT_ERROR_DESTROY_CONTEXT) {
107  return {"failed to destroy context"};
108  }
109 #endif
110 #ifdef ALUT_ERROR_GEN_BUFFERS
111  if(_error_code == ALUT_ERROR_GEN_BUFFERS) {
112  return {"failed to generate audio buffers"};
113  }
114 #endif
115 #ifdef ALUT_ERROR_BUFFER_DATA
116  if(_error_code == ALUT_ERROR_BUFFER_DATA) {
117  return {"failed to store data in buffer"};
118  }
119 #endif
120 #ifdef ALUT_ERROR_IO_ERROR
121  if(_error_code == ALUT_ERROR_IO_ERROR) {
122  return {"input/output error"};
123  }
124 #endif
125 #ifdef ALUT_ERROR_UNSUPPORTED_FILE_TYPE
126  if(_error_code == ALUT_ERROR_UNSUPPORTED_FILE_TYPE) {
127  return {"unsupported file type"};
128  }
129 #endif
130 #ifdef ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE
131  if(_error_code == ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE) {
132  return {"unsupported file sub-type"};
133  }
134 #endif
135 #ifdef ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE
136  if(_error_code == ALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA) {
137  return {"corrupt or truncated data"};
138  }
139 #endif
140 #ifdef ALUT_ERROR_NO_ERROR
141  if(_error_code == ALUT_ERROR_NO_ERROR) {
142  return {"no error"};
143  }
144 #endif
145 #ifdef ALUT_ERROR_OUT_OF_MEMORY
146  if(_error_code == ALUT_ERROR_OUT_OF_MEMORY) {
147  return {"out of memory"};
148  }
149 #endif
150  return {"unknown error"};
151  }
152 
153 private:
154  enum_type _error_code{
155 #ifdef ALUT_ERROR_NO_ERROR
156  ALUT_ERROR_NO_ERROR
157 #endif
158  };
159 };
160 //------------------------------------------------------------------------------
165 template <typename Result>
167 //------------------------------------------------------------------------------
172 template <typename Result>
174 //------------------------------------------------------------------------------
179 template <typename Result>
181 //------------------------------------------------------------------------------
182 } // namespace eagine::oalp
183 
184 #endif // OALPLUS_ALUT_API_RESULT_HPP
Class storing information about call result for unavailable ALUT functions.
Definition: result.hpp:22
Class wrapping the result of a C-API function call.
Definition: c_api_wrap.hpp:210
Typed enumeration for GL error code constants.
Definition: enum_types.hpp:32
api_opt_result< Result, alut_result_info > alut_opt_result
Class wrapping the result of a ALUT API function call.
Definition: result.hpp:180
Class storing information about an ALUT function call result.
Definition: result.hpp:40
auto message() const noexcept -> string_view
Returns a message associated with the result.
Definition: result.hpp:59
al_types::enum_type enum_type
Enum type.
Definition: config.hpp:40
constexpr auto message() const noexcept -> string_view
Returns a message associated with the result.
Definition: result.hpp:29
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
api_no_result< Result, alut_no_result_info > alut_no_result
Alias for always-invalid result of a missing ALUT API function call.
Definition: result.hpp:166
AL-related code is placed in this namespace.
Definition: oalplus.hpp:11
Type that can by constructed from single argument of any other type.
Definition: anything.hpp:16

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