12#include <Common/assertion.h>
19template<
bool IS_CONST>
24template<
bool IS_CONST>
30template<
bool IS_CONST>
35 static_assert(
sizeof(T) ==
sizeof(T),
36 "Input must be a complete type.");
46 m_meta = target->getDynamicSdlClass();
50 m_meta = T::getSdlClass();
58 m_meta = T::getSdlStruct();
65 m_meta = T::getSdlFunction();
69 PH_STATIC_ASSERT_DEPENDENT_FALSE(T,
70 "Input is not a valid SDL target type (must be a SDL class/struct/function).");
80template<
bool IS_CONST>
84 using ReturnType = std::conditional_t<IS_CONST, const T, T>;
88 (getClass() !=
nullptr) + (getStruct() !=
nullptr) + (getFunction() !=
nullptr),
93 ClassInstanceType*
const instance = std::holds_alternative<ClassInstanceType*>(m_instance)
94 ? std::get<ClassInstanceType*>(m_instance) :
nullptr;
102 if(std::holds_alternative<StructInstanceType*>(m_instance))
105 if(T::getSdlStruct() == getStruct())
107 StructInstanceType*
const instance = std::get<StructInstanceType*>(m_instance);
108 return static_cast<ReturnType*
>(instance);
114 if(std::holds_alternative<StructInstanceType*>(m_instance))
117 if(T::getSdlFunction() == getFunction())
119 StructInstanceType*
const instance = std::get<StructInstanceType*>(m_instance);
120 return static_cast<ReturnType*
>(instance);
125 return static_cast<ReturnType*
>(
nullptr);
128template<
bool IS_CONST>
131 return std::holds_alternative<const SdlClass*>(m_meta)
132 ? std::get<const SdlClass*>(m_meta) :
nullptr;
135template<
bool IS_CONST>
138 return std::holds_alternative<const SdlStruct*>(m_meta)
139 ? std::get<const SdlStruct*>(m_meta) :
nullptr;
142template<
bool IS_CONST>
145 return std::holds_alternative<const SdlFunction*>(m_meta)
146 ? std::get<const SdlFunction*>(m_meta) :
nullptr;
149template<
bool IS_CONST>
152 return m_meta.index() == variant_index_of<const SdlClass*>(m_meta);
155template<
bool IS_CONST>
158 return m_meta.index() == variant_index_of<const SdlStruct*>(m_meta);
161template<
bool IS_CONST>
164 return m_meta.index() == variant_index_of<const SdlFunction*>(m_meta);
167template<
bool IS_CONST>
170 constexpr auto classIdx = variant_index_of<const SdlClass*, MetaType>();
171 constexpr auto structIdx = variant_index_of<const SdlStruct*, MetaType>();
172 constexpr auto functionIdx = variant_index_of<const SdlFunction*, MetaType>();
174 switch(m_meta.index())
176 case classIdx:
return std::get<classIdx>(m_meta);
177 case structIdx:
return std::get<structIdx>(m_meta);
178 case functionIdx:
return std::get<functionIdx>(m_meta);
179 default:
return nullptr;
183template<
bool IS_CONST>
186 constexpr auto classInstanceIdx = variant_index_of<ClassInstanceType*, InstanceType>();
187 constexpr auto structInstanceIdx = variant_index_of<StructInstanceType*, InstanceType>();
189 switch(m_instance.index())
191 case classInstanceIdx:
return std::get<classInstanceIdx>(m_instance) !=
nullptr;
192 case structInstanceIdx:
return std::get<structInstanceIdx>(m_instance) !=
nullptr;
193 default:
return false;
Definition ISdlInstantiable.h:12
Definition SdlFunction.h:18
Definition SdlStruct.h:25
References a SDL object. This is a lightweight utility for referencing SDL objects....
Definition TSdlAnyInstance.h:20
bool isStruct() const
Definition TSdlAnyInstance.ipp:156
const SdlClass * getClass() const
Definition TSdlAnyInstance.ipp:129
const ISdlInstantiable * getInstantiable() const
Definition TSdlAnyInstance.ipp:168
const SdlStruct * getStruct() const
Definition TSdlAnyInstance.ipp:136
bool isFunction() const
Definition TSdlAnyInstance.ipp:162
TSdlAnyInstance()
Definition TSdlAnyInstance.ipp:20
bool isClass() const
Definition TSdlAnyInstance.ipp:150
const SdlFunction * getFunction() const
Definition TSdlAnyInstance.ipp:143
auto * get() const
Definition TSdlAnyInstance.ipp:82
Checks whether DerivedType is derived from BaseType. The result is also true if both types are the sa...
Definition traits.h:122
Whether T is a well-defined SDL class.
Definition sdl_traits.h:29
Whether T is a well-defined SDL function.
Definition sdl_traits.h:42
Whether T is a well-defined SDL struct.
Definition sdl_traits.h:36
Definition sdl_traits.h:55
DstType * cast_to(SrcType *srcResource)
Cast between SDL resource types. Cast the input SDL resource instance of SrcType to an instance of Ds...
Definition sdl_helpers.ipp:549
The root for all renderer implementations.
Definition EEngineProject.h:6
Low-level helpers for SDL. Helpers are in an additional sdl namespace.