6#include <Common/assertion.h>
13template<
typename Variant>
15 : m_variant(
std::monostate{})
18template<
typename Variant>
21 : m_variant(
std::move(value))
24template<
typename Variant>
26 : m_variant(
std::move(variant))
29template<
typename Variant>
33 return std::holds_alternative<T>(m_variant);
36template<
typename Variant>
41 return std::get<T>(m_variant);
44template<
typename Variant>
49 return std::get<T>(m_variant);
52template<
typename Variant>
56 std::get<T>(m_variant) = std::move(value);
59template<
typename Variant>
62 return m_variant.index();
65template<
typename Variant>
68 return has<std::monostate>();
71template<
typename Variant>
78template<
typename Variant>
85template<
typename ElementType>
87 ElementType*
const elementPtr,
91 const bool canDirectAccess)
100 nativeData.m_elementGetter =
108 nativeData.m_elementGetter =
111 return std::monostate{};
119 nativeData.m_elementSetter =
127 nativeData.m_elementSetter =
137 nativeData.m_directPtr = elementPtr;
150 return std::monostate{};
175 : m_elementGetter(
std::move(getter))
176 , m_elementSetter(
std::move(setter))
177 , m_directPtr(directPtr)
181 requires std::is_arithmetic_v<T> || std::is_enum_v<T>
184 PH_ASSERT(m_elementGetter);
187 switch(output.
index())
189 case 1:
return static_cast<T
>(output.
get<int64>());
190 case 2:
return static_cast<T
>(output.
get<float64>());
191 default:
return std::nullopt;
196 requires std::is_pointer_v<T>
199 PH_ASSERT(m_elementGetter);
201 using PtrRemovedT = std::remove_pointer_t<T>;
217 requires std::is_arithmetic_v<T> || std::is_enum_v<T>
220 PH_ASSERT(m_elementSetter);
222 if constexpr(std::is_integral_v<T> || std::is_enum_v<T>)
224 return m_elementSetter(elementIdx,
static_cast<int64
>(value));
226 else if constexpr(std::is_floating_point_v<T>)
228 return m_elementSetter(elementIdx,
static_cast<float64
>(value));
237 requires std::is_pointer_v<T>
240 PH_ASSERT(m_elementSetter);
242 using PtrRemovedT = std::remove_pointer_t<T>;
255 requires std::is_null_pointer_v<T>
258 return m_elementSetter(elementIdx, std::monostate{});
264 return m_directPtr.
get<T>();
269 m_directPtr = accessor;
306inline SdlNativeData::operator bool ()
const
308 return numElements > 0;
311template<
typename ElementType>
315 PH_ASSERT(elementPtr);
317 if constexpr(std::is_arithmetic_v<ElementType> || std::is_enum_v<ElementType>)
319 const auto elementValue = *elementPtr;
320 if constexpr(std::is_integral_v<ElementType> || std::is_enum_v<ElementType>)
325 return static_cast<int64
>(elementValue);
327 else if constexpr(std::is_floating_point_v<ElementType>)
330 return static_cast<float64
>(elementValue);
334 PH_STATIC_ASSERT_DEPENDENT_FALSE(ElementType,
335 "Unsupported element value type.");
348template<
typename ElementType>
352 PH_ASSERT(out_elementPtr);
354 if constexpr(std::is_arithmetic_v<ElementType> || std::is_enum_v<ElementType>)
359 switch(input.index())
362 *out_elementPtr =
static_cast<ElementType
>(input.get<int64>());
366 *out_elementPtr =
static_cast<ElementType
>(input.get<float64>());
379 *out_elementPtr = *inputPtr;
393 *out_elementPtr = *inputPtr;
Definition SdlNativeData.h:88
static auto permissiveElementSetter(SdlSetterVariant input, ElementType *out_elementPtr) -> bool
Given a valid target element, set its value in a permissive way (with auto conversions).
Definition SdlNativeData.ipp:349
std::size_t numElements
Hint for number of elements in this block of native data. For example, numElements would be 12 for an...
Definition SdlNativeData.h:99
void setDirectAccessor(AnyNonConstPtr accessor)
Definition SdlNativeData.ipp:267
T * directAccess() const
Directly access the underlying data. Use of direct accessor may invalidate getter and setter accessor...
Definition SdlNativeData.ipp:262
static auto permissiveElementGetter(ElementType *elementPtr) -> SdlGetterVariant
Given a valid target element, get its value in a permissive way (with auto conversions).
Definition SdlNativeData.ipp:312
ESdlDataType elementType
Hint for the type of elements.
Definition SdlNativeData.h:113
bool set(std::size_t elementIdx, T value) const
Definition SdlNativeData.ipp:218
std::optional< T > get(std::size_t elementIdx) const
Definition SdlNativeData.ipp:182
ESdlDataFormat elementContainer
Hint for the type that encapsulates elements.
Definition SdlNativeData.h:109
bool isFloatingPointElement() const
Definition SdlNativeData.ipp:293
SdlNativeData()
Creates empty native data.
Definition SdlNativeData.ipp:146
static SdlNativeData fromSingleElement(ElementType *elementPtr, ESdlDataFormat elementContainer, ESdlDataType elementType, bool canSet=false, bool canDirectAccess=false)
Creates native data for a single element pointer.
Definition SdlNativeData.ipp:86
bool isIntegerElement() const
Definition SdlNativeData.ipp:272
auto * get() const
Definition TAnyPtr.h:72
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
auto * get() const
Definition TSdlAnyInstance.ipp:82
Definition TFunction.h:23
Definition sdl_traits.h:55
The root for all renderer implementations.
Definition EEngineProject.h:6
TAnyPtr< false > AnyNonConstPtr
A type-safe, lightweight wrapper for any non-const raw pointer type.
Definition TAnyPtr.h:47
TAnyPtr< true > AnyConstPtr
A type-safe, lightweight wrapper for any const raw pointer type.
Definition TAnyPtr.h:43
TSdlAnyInstance< true > SdlConstInstance
Definition sdl_fwd.h:33
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
TSdlAnyInstance< false > SdlNonConstInstance
Definition sdl_fwd.h:34