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

api.hpp
Go to the documentation of this file.
1 #ifndef OALPLUS_ALUT_API_API_HPP
9 #define OALPLUS_ALUT_API_API_HPP
10 
11 #include "../al_api/object_name.hpp"
12 #include "c_api.hpp"
13 #include "enum_types.hpp"
14 #include <eagine/scope_exit.hpp>
15 #include <eagine/string_list.hpp>
16 
17 namespace eagine::oalp {
18 //------------------------------------------------------------------------------
19 #define OALPAFP(FUNC) decltype(c_api::FUNC), &c_api::FUNC
20 //------------------------------------------------------------------------------
25 template <typename ApiTraits>
26 class basic_alut_operations : public basic_alut_c_api<ApiTraits> {
27 
28 public:
29  using api_traits = ApiTraits;
31 
32  using enum_type = typename alut_types::enum_type;
33  using char_type = typename alut_types::char_type;
34 
35  struct derived_func : derived_c_api_function<c_api, api_traits, nothing_t> {
36  using base = derived_c_api_function<c_api, api_traits, nothing_t>;
37  using base::base;
38 
39  template <typename Res>
40  constexpr auto _check(Res&& res) const noexcept {
41  res.error_code(this->api().GetError());
42  return std::forward<Res>(res);
43  }
44  };
45 
46  template <typename W, W c_api::*F, typename Signature = typename W::signature>
47  class func;
48 
49  template <typename W, W c_api::*F, typename RVC, typename... Params>
50  class func<W, F, RVC(Params...)>
51  : public wrapped_c_api_function<c_api, api_traits, nothing_t, W, F> {
52  using base = wrapped_c_api_function<c_api, api_traits, nothing_t, W, F>;
53 
54  private:
55  template <typename Res>
56  constexpr auto _check(Res&& res) const noexcept {
57  res.error_code(this->api().GetError());
58  return std::forward<Res>(res);
59  }
60 
61  protected:
62  template <typename... Args>
63  constexpr auto _chkcall(Args&&... args) const noexcept {
64  return this->_check(this->_call(std::forward<Args>(args)...));
65  }
66 
67  using base::_conv;
68 
69  public:
70  using base::base;
71 
72  constexpr auto operator()(Params... params) const noexcept {
73  return this->_chkcall(_conv(params)...)
74  .cast_to(type_identity<RVC>{});
75  }
76  };
77 
78  // init
79  func<OALPAFP(Init)> init;
80 
81  // create_buffer_hello_world
83  create_buffer_hello_world;
84 
85  // exit
86  struct : func<OALPAFP(Exit)> {
87  using base = func<OALPAFP(Exit)>;
88  using base::base;
89  using base::operator();
90 
91  auto raii() noexcept {
92  return eagine::finally([=]() { (*this)(); });
93  }
94  } exit;
95 
96  basic_alut_operations(api_traits& traits);
97 };
98 //------------------------------------------------------------------------------
99 #undef OALPAFP
100 //------------------------------------------------------------------------------
101 } // namespace eagine::oalp
102 
103 #endif // OALPLUS_ALUT_API_API_HPP
alut_api_function< bool_type(int *, char **), nullptr > Init
Definition: c_api.hpp:104
alut_api_function< enum_type(), nullptr > GetError
Definition: c_api.hpp:92
alut_api_function< bool_type(), nullptr > Exit
Definition: c_api.hpp:141
static auto finally(Func func) -> func_on_scope_exit< Func >
Function constructing on-scope-exit actions.
Definition: scope_exit.hpp:144
al_types::enum_type enum_type
Enum type.
Definition: config.hpp:40
Class wrapping the C-functions from the ALUT API.
Definition: c_api.hpp:31
alut_api_function< name_type(), nullptr > CreateBufferHelloWorld
Definition: c_api.hpp:130
Owning wrapper for C-API opaque handle types.
Definition: handle.hpp:98
Template type used mostly for function type-tag dispatching.
Definition: type_identity.hpp:19
al_types::char_type char_type
String character type.
Definition: config.hpp:37
AL-related code is placed in this namespace.
Definition: oalplus.hpp:11
Class wrapping the functions from the ALUT API.
Definition: api.hpp:26

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