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

result.hpp
Go to the documentation of this file.
1 #ifndef OALPLUS_ALC_API_RESULT_HPP
9 #define OALPLUS_ALC_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 {"ALC function not available"};
31  }
32 
33 private:
34 };
35 //------------------------------------------------------------------------------
41 public:
42  using enum_type = alc_types::enum_type;
43 
45  explicit constexpr operator bool() const noexcept {
46  return alc_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 ALC_INVALID_ENUM
61  if(_error_code == ALC_INVALID_ENUM) {
62  return {"invalid enumeration parameter value"};
63  }
64 #endif
65 #ifdef ALC_INVALID_VALUE
66  if(_error_code == ALC_INVALID_VALUE) {
67  return {"invalid parameter value"};
68  }
69 #endif
70 #ifdef ALC_INVALID_CONTEXT
71  if(_error_code == ALC_INVALID_CONTEXT) {
72  return {"invalid context"};
73  }
74 #endif
75 #ifdef ALC_INVALID_DEVICE
76  if(_error_code == ALC_INVALID_DEVICE) {
77  return {"invalid device"};
78  }
79 #endif
80 #ifdef ALC_NO_ERROR
81  if(_error_code == ALC_NO_ERROR) {
82  return {"no error"};
83  }
84 #endif
85 #ifdef ALC_OUT_OF_MEMORY
86  if(_error_code == ALC_OUT_OF_MEMORY) {
87  return {"out of memory"};
88  }
89 #endif
90  return {"unknown error"};
91  }
92 
93 private:
94  enum_type _error_code{
95 #ifdef ALC_NO_ERROR
96  ALC_NO_ERROR
97 #endif
98  };
99 };
100 //------------------------------------------------------------------------------
105 template <typename Result>
107 //------------------------------------------------------------------------------
112 template <typename Result>
114 //------------------------------------------------------------------------------
119 template <typename Result>
121 //------------------------------------------------------------------------------
122 } // namespace eagine::oalp
123 
124 #endif // OALPLUS_ALC_API_RESULT_HPP
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, alc_result_info > alc_opt_result
Class wrapping the result of a ALC API function call.
Definition: result.hpp:120
Class storing information about an ALC function call result.
Definition: result.hpp:40
auto message() const noexcept -> string_view
Returns a message associated with the result.
Definition: result.hpp:59
constexpr auto message() const noexcept -> string_view
Returns a message associated with the result.
Definition: result.hpp:29
Class storing information about call result for unavailable ALC functions.
Definition: result.hpp:22
api_no_result< Result, alc_no_result_info > alc_no_result
Alias for always-invalid result of a missing ALC API function call.
Definition: result.hpp:106
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
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).