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

result.hpp
Go to the documentation of this file.
1 #ifndef OALPLUS_AL_API_RESULT_HPP
9 #define OALPLUS_AL_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 {"AL function not available"};
31  }
32 
33 private:
34 };
35 //------------------------------------------------------------------------------
41 public:
42  using enum_type = al_types::enum_type;
43 
45  explicit constexpr operator bool() const noexcept {
46  return al_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 
55  auto message() const noexcept -> string_view {
56 #ifdef AL_INVALID_NAME
57  if(_error_code == AL_INVALID_NAME) {
58  return {"invalid object name"};
59  }
60 #endif
61 #ifdef AL_INVALID_ENUM
62  if(_error_code == AL_INVALID_ENUM) {
63  return {"invalid enumeration value"};
64  }
65 #endif
66 #ifdef AL_INVALID_VALUE
67  if(_error_code == AL_INVALID_VALUE) {
68  return {"invalid parameter value"};
69  }
70 #endif
71 #ifdef AL_INVALID_OPERATION
72  if(_error_code == AL_INVALID_OPERATION) {
73  return {"invalid operation"};
74  }
75 #endif
76 #ifdef AL_NO_ERROR
77  if(_error_code == AL_NO_ERROR) {
78  return {"no error"};
79  }
80 #endif
81 #ifdef AL_OUT_OF_MEMORY
82  if(_error_code == AL_OUT_OF_MEMORY) {
83  return {"out of memory"};
84  }
85 #endif
86  return {"unknown error"};
87  }
88 
89 private:
90  enum_type _error_code{
91 #ifdef AL_NO_ERROR
92  AL_NO_ERROR
93 #endif
94  };
95 };
96 //------------------------------------------------------------------------------
101 template <typename Result>
103 //------------------------------------------------------------------------------
108 template <typename Result>
110 //------------------------------------------------------------------------------
115 template <typename Result>
117 //------------------------------------------------------------------------------
118 } // namespace eagine::oalp
119 
120 #endif // OALPLUS_AL_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
auto message() const noexcept -> string_view
Returns a message associated with the result.
Definition: result.hpp:55
Class storing information about call result for unavailable AL functions.
Definition: result.hpp:22
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
api_no_result< Result, al_no_result_info > al_no_result
Alias for always-invalid result of a missing AL API function call.
Definition: result.hpp:102
Class storing information about an AL function call result.
Definition: result.hpp:40
api_opt_result< Result, al_result_info > al_opt_result
Alias for conditionally-valid result of an AL API function call.
Definition: result.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).