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

const_output.hpp
Go to the documentation of this file.
1 #ifndef OGLPLUS_TEXGEN_CONST_OUTPUT_HPP
9 #define OGLPLUS_TEXGEN_CONST_OUTPUT_HPP
10 
11 #include "base_output.hpp"
12 #include "param_format.hpp"
13 #include <eagine/integer_range.hpp>
14 #include <array>
15 #include <type_traits>
16 
17 namespace eagine::oglp::texgen {
18 
19 template <typename T>
20 class constant_output;
21 
22 class constant_output_base : public base_output {
23 public:
24  constant_output_base(node_intf& parent) noexcept
25  : base_output(parent) {}
26 
27  string_view type_name() noexcept override {
28  return string_view("Const");
29  }
30 
31  render_param_bits required_params() override {
32  return render_param_bits();
33  }
34 };
35 
36 template <typename T, span_size_t N>
37 class constant_output<T[N]> : public constant_output_base {
38 private:
39  std::array<T, N> _coords;
40 
41 public:
42  constant_output(node_intf& parent) noexcept
43  : constant_output_base(parent)
44  , _coords{} {}
45 
46  template <typename... P, typename = std::enable_if_t<sizeof...(P) == N>>
47  constant_output(node_intf& parent, P... coords) noexcept
48  : constant_output_base(parent)
49  , _coords{{T(coords)...}} {}
50 
51  template <typename... P, typename = std::enable_if_t<sizeof...(P) == N>>
52  void set(P... coords) noexcept {
53  _coords = std::array<T, N>{{T(coords)...}};
54  }
55 
56  bool set_default_value(span_size_t c, float v) override {
57  if(c < N) {
58  _coords[std_size(c)] = T(v);
59  return true;
60  }
61  return false;
62  }
63 
64  slot_data_type value_type() noexcept override {
65  return get_data_type_v<T[N]>;
66  }
67 
68  std::ostream& expression(std::ostream& out, compile_context&) override {
69  out << data_type_name(value_type());
70  out << "(";
71  out << _coords[0];
72  for(auto i : integer_range(1, N)) {
73  out << ", " << _coords[std_size(i)];
74  }
75  return out << ")";
76  }
77 };
78 
79 } // namespace eagine::oglp::texgen
80 
81 #endif // OGLPLUS_TEXGEN_CONST_OUTPUT_HPP
value_type
Value tree value element data type enumeration.
Definition: interface.hpp:27
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
static constexpr auto std_size(T v) noexcept
Converts argument to std size type.
Definition: types.hpp:52
integer_range(B, E) -> integer_range< std::common_type_t< B, E >>
Deduction guide for integer_range.

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