All Classes Files Functions Variables Typedefs Pages
VertexSlot.hpp
1 #pragma once
2 
3 #include "VertexSlot.fpp"
4 #include "GLException.hpp"
5 #include "../service/StaticLogger.hpp"
6 
7 #include <initializer_list>
8 #include <cstring>
9 
10 namespace lumina {
11 namespace internal {
12 
13 class VertexSlot {
14 protected:
15  void* m_buffer;
16 
17  VertexSlot(void* buf) : m_buffer(buf) {}
18 };
19 
20 template <typename T, typename... Ts>
21 class VertexSlotAssign : public VertexSlot {
22 public:
23  using VertexSlot::VertexSlot;
24 
25  VertexSlotComma<Ts...> operator=(T data) {
26  *static_cast<T*>(this->m_buffer) = data;
27  return VertexSlotComma<Ts...>(static_cast<T*>(this->m_buffer) + 1);
28  }
29 
30  void set(T head, Ts... tail) {
31  *static_cast<T*>(this->m_buffer) = head;
32  VertexSlotAssign<Ts...>(static_cast<T*>(this->m_buffer) + 1).set(tail...);
33  }
34 
35  template <typename...> friend class VertexSet;
36  template <typename, typename...> friend class VertexSlotAssign;
37 };
38 
39 template <typename T>
41 public:
42  using VertexSlot::VertexSlot;
43 
44  void operator=(T data) { *static_cast<T*>(this->m_buffer) = data; }
45 
46  void set(T head) { *static_cast<T*>(this->m_buffer) = head; }
47 
48  template <typename...> friend class VertexSet;
49  template <typename, typename...> friend class VertexSlotAssign;
50 };
51 
53 public:
54  VertexFloatSlot(void* buf, int size) : m_buffer(buf), m_size(size) {}
55 
56  float& operator[](int index) {
57  if(index >= m_size) {
58 
59  }
60  return static_cast<float*>(this->m_buffer)[index];
61  }
62  void operator=(std::initializer_list<float> data) {
63  if(data.size() > m_size) {
64  slogError("[VertexSlot] Size of initializer_list <", data.size(),
65  "> bigger than size of the slot <", m_size, ">!");
66  throw GLException("[VertexSlot] Size of initializer_list bigger than "
67  "size of the slot");
68  }
69  std::memcpy(this->m_buffer, data.begin(), data.size() * sizeof(float));
70  }
71 
72  template <typename...> friend class VertexSet;
73  template <typename, typename...> friend class VertexSlotAssign;
74 
75 private:
76  void* m_buffer;
77  int m_size;
78 };
79 
80 
81 template <typename T, typename... Ts>
82 class VertexSlotComma : public VertexSlot {
83 public:
84  using VertexSlot::VertexSlot;
85 
86  VertexSlotComma<Ts...> operator,(T data) {
87  *static_cast<T*>(this->m_buffer) = data;
88  return VertexSlotComma<Ts...>(static_cast<T*>(this->m_buffer) + 1);
89  }
90 
91  template <typename, typename...> friend class VertexSlotAssign;
92 };
93 
94 template <typename T>
96 public:
97  using VertexSlot::VertexSlot;
98 
99  void operator,(T data) { *static_cast<T*>(this->m_buffer) = data; }
100 
101  template <typename, typename...> friend class VertexSlotAssign;
102  template <typename, typename...> friend class VertexSlotComma;
103 };
104 
105 
106 }
107 }
Definition: VertexSlot.fpp:8
Definition: VertexSlot.hpp:52
Definition: GLException.hpp:7
Definition: VertexSet.hpp:12
Definition: VertexSlot.fpp:7
Definition: VertexSlot.hpp:13
Definition: VertexSlot.hpp:95
Definition: VertexSlot.hpp:40