Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
SdlNativeData.h
Go to the documentation of this file.
1#pragma once
2
4#include "SDL/ESdlDataType.h"
5#include "Utility/TFunction.h"
8#include "Utility/TAnyPtr.h"
9
10#include <Common/primitive_type.h>
11
12#include <cstddef>
13#include <variant>
14#include <string>
15#include <typeindex>
16#include <optional>
17#include <type_traits>
18
19namespace ph
20{
21
22template<typename Variant>
24{
25public:
26 using VariantType = Variant;
27
29
30 template<typename T>
31 TSdlAccessorVariant(T value);
32
34
35 template<typename T>
36 bool has() const;
37
38 template<typename T>
39 T& get();
40
41 template<typename T>
42 const T& get() const;
43
44 template<typename T>
45 void set(T value);
46
47 std::size_t index() const;
48 bool isEmpty() const;
49
50 auto getVariant() -> VariantType&;
51 auto getVariant() const -> const VariantType&;
52
53private:
54 VariantType m_variant;
55};
56
58 std::monostate,
59 int64,
60 float64,
63
65 std::monostate,
66 int64,
67 float64,
70
87class SdlNativeData final
88{
89public:
90 template<typename Func>
92
93 using ElementGetter = TElementAccessor<SdlGetterVariant(std::size_t elementIdx)>;
94 using ElementSetter = TElementAccessor<bool(std::size_t elementIdx, SdlSetterVariant input)>;
95
99 std::size_t numElements = 0;
100
105 std::size_t tupleSize = 0;
106
110
114
120 uint8 isNullClearable : 1 = false;
121
127 template<typename ElementType>
128 static SdlNativeData fromSingleElement(
129 ElementType* elementPtr,
130 ESdlDataFormat elementContainer,
131 ESdlDataType elementType,
132 bool canSet = false,
133 bool canDirectAccess = false);
134
138
141 explicit SdlNativeData(ElementGetter getter);
142
146
149 SdlNativeData(ElementGetter getter, ElementSetter setter, AnyNonConstPtr directPtr);
150
151 template<typename T>
152 requires std::is_arithmetic_v<T> || std::is_enum_v<T>
153 std::optional<T> get(std::size_t elementIdx) const;
154
155 template<typename T>
156 requires std::is_pointer_v<T>
157 T get(std::size_t elementIdx) const;
158
159 template<typename T>
160 requires std::is_arithmetic_v<T> || std::is_enum_v<T>
161 bool set(std::size_t elementIdx, T value) const;
162
163 template<typename T>
164 requires std::is_pointer_v<T>
165 bool set(std::size_t elementIdx, T ptr) const;
166
167 template<typename T>
168 requires std::is_null_pointer_v<T>
169 bool set(std::size_t elementIdx, T nullPtr) const;
170
175 template<typename T>
176 T* directAccess() const;
177
178 void setDirectAccessor(AnyNonConstPtr accessor);
179
180 bool isIntegerElement() const;
181 bool isFloatingPointElement() const;
182
183 operator bool () const;
184
185public:
189 template<typename ElementType>
190 static auto permissiveElementGetter(ElementType* elementPtr) -> SdlGetterVariant;
191
195 template<typename ElementType>
196 static auto permissiveElementSetter(SdlSetterVariant input, ElementType* out_elementPtr) -> bool;
197
198private:
199 ElementGetter m_elementGetter;
200 ElementSetter m_elementSetter;
201 AnyNonConstPtr m_directPtr;
202};
203
204}// end namespace ph
205
Definition SdlNativeData.h:88
uint8 isNullClearable
Whether the data can be set as empty by assigning null to it. For example, if this flag is true and t...
Definition SdlNativeData.h:120
bool set(std::size_t elementIdx, T nullPtr) const
bool set(std::size_t elementIdx, T ptr) const
A type-safe, lightweight wrapper for any raw pointer type. Using std::any with a raw pointer type cou...
Definition TAnyPtr.h:17
Definition SdlNativeData.h:24
Variant VariantType
Definition SdlNativeData.h:26
T & get()
Definition SdlNativeData.ipp:38
auto getVariant() -> VariantType &
Definition SdlNativeData.ipp:72
bool has() const
Definition SdlNativeData.ipp:31
TSdlAccessorVariant()
Definition SdlNativeData.ipp:14
bool isEmpty() const
Definition SdlNativeData.ipp:66
void set(T value)
Definition SdlNativeData.ipp:54
std::size_t index() const
Definition SdlNativeData.ipp:60
References a SDL object. This is a lightweight utility for referencing SDL objects....
Definition TSdlAnyInstance.h:20
Definition TFunction.h:23
The root for all renderer implementations.
Definition EEngineProject.h:6
TSdlAccessorVariant< std::variant< std::monostate, int64, float64, SdlConstInstance, AnyConstPtr > > SdlGetterVariant
Definition SdlNativeData.h:57
ESdlDataFormat
Format of the data used by SDL. Each listed data format tells how a group of data is arranged interna...
Definition ESdlDataFormat.h:13
ESdlDataType
Common data types used by SDL. Each listed data type has some form of one to one mapping to a specifi...
Definition ESdlDataType.h:13
Definition TAABB2D.h:96