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

base_node.hpp
Go to the documentation of this file.
1 #ifndef OGLPLUS_TEXGEN_BASE_NODE_HPP
9 #define OGLPLUS_TEXGEN_BASE_NODE_HPP
10 
11 #include "base_output.hpp"
12 #include "interface.hpp"
13 #include <eagine/assert.hpp>
14 #include <eagine/maybe_unused.hpp>
15 
16 namespace eagine::oglp::texgen {
17 
18 class base_node : public node_intf {
19 private:
20  span_size_t _render_input{0};
21 
22 public:
23  base_node() noexcept = default;
24 
25  span_size_t input_count() override;
26 
27  input_intf& input(span_size_t) override;
28 
29  bool can_add_input() override;
30 
31  input_intf& add_input(string_view) override;
32 
33  span_size_t output_count() override;
34 
35  output_intf& output(span_size_t) override;
36 
37  void update_needed() override;
38 
39  void prepare() override;
40 
41  bool render(const render_params&) override;
42 };
43 
44 class base_single_output_node : public base_node {
45 public:
46  virtual base_output& single_output() = 0;
47 
48  string_view type_name() override;
49 
50  span_size_t output_count() override;
51 
52  output_intf& output(span_size_t index) override;
53 };
54 
55 template <typename Output>
56 class single_output_node : public base_single_output_node {
57 protected:
58  Output _output;
59 
60 public:
61  template <typename... P>
62  single_output_node(P&&... p)
63  : _output(*this, std::forward<P>(p)...) {}
64 
65  base_output& single_output() override {
66  return _output;
67  }
68 };
69 
70 template <typename Output, typename T1, T1 Output::*Input1>
71 class unary_single_output_node : public single_output_node<Output> {
72 public:
73  using single_output_node<Output>::single_output_node;
74 
75  span_size_t input_count() override {
76  return 1;
77  }
78 
79  input_intf& input(span_size_t index) override {
80  EAGINE_MAYBE_UNUSED(index);
81  EAGINE_ASSERT(index < input_count());
82  return this->_output.*Input1;
83  }
84 };
85 
86 template <
87  typename Output,
88  typename T1,
89  T1 Output::*Input1,
90  typename T2,
91  T2 Output::*Input2>
92 class binary_single_output_node : public single_output_node<Output> {
93 public:
94  using single_output_node<Output>::single_output_node;
95 
96  span_size_t input_count() override {
97  return 2;
98  }
99 
100  input_intf& input(span_size_t index) override {
101  EAGINE_ASSERT(index < input_count());
102  return (index == 0) ? static_cast<input_intf&>(this->_output.*Input1)
103  : static_cast<input_intf&>(this->_output.*Input2);
104  }
105 };
106 
107 } // namespace eagine::oglp::texgen
108 
109 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
110 #include <oglplus/texgen/base_node.inl>
111 #endif
112 
113 #endif // OGLPLUS_TEXGEN_BASE_NODE_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
static auto type_name(const T &) noexcept -> std::string
Returns the demangled name for type T.
Definition: type_name.hpp:24

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