3#include <Foundation/Algorithm/HashingUtils.h>
4#include <Foundation/Containers/DynamicArray.h>
5#include <Foundation/Containers/HashTable.h>
6#include <Foundation/Math/Declarations.h>
7#include <Foundation/Strings/HashedString.h>
8#include <Foundation/Threading/AtomicInteger.h>
9#include <Foundation/Types/TypedPointer.h>
10#include <Foundation/Types/Types.h>
11#include <Foundation/Types/VariantType.h>
13#include <Foundation/Reflection/Implementation/DynamicRTTI.h>
14#include <Foundation/Utilities/ConversionUtils.h>
25 PL_DECLARE_POD_TYPE();
26 const void* m_pObject =
nullptr;
27 const plRTTI* m_pType =
nullptr;
31 return m_pObject == rhs.m_pObject;
119 template <
typename T>
126 void CopyTypedObject(
const void* value,
const plRTTI* pType);
129 void MoveTypedObject(
void* value,
const plRTTI* pType);
138 void operator=(
plVariant&& other)
noexcept;
143 template <
typename T>
152 bool operator==(
const plVariant& other)
const;
154 PL_ADD_DEFAULT_OPERATOR_NOTEQUAL(
const plVariant&);
157 template <
typename T>
160#if PL_DISABLED(PL_USE_CPP20_OPERATORS)
162 template <
typename T>
163 bool operator!=(
const T& other)
const
165 return !(*
this == other);
170 bool IsValid()
const;
175 bool IsNumber()
const;
178 bool IsFloatingPoint()
const;
181 bool IsString()
const;
184 bool IsHashedString()
const;
190 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::DirectCast,
int> = 0>
193 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::PointerCast,
int> = 0>
196 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::TypedObject,
int> = 0>
212 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::DirectCast,
int> = 0>
215 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::PointerCast,
int> = 0>
218 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::TypedObject,
int> = 0>
222 const T& Get()
const;
228 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::DirectCast,
int> = 0>
231 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::PointerCast,
int> = 0>
240 const void* GetData()
const;
244 const plRTTI* GetReflectedType()
const;
249 const plVariant operator[](plUInt32 uiIndex)
const;
268 template <
typename T>
280 template <
typename T>
281 T ConvertTo(
plResult* out_pConversionStatus =
nullptr)
const;
293 template <
typename Functor,
class... Args>
294 static auto DispatchTo(Functor& ref_functor,
Type::Enum type, Args&&... args);
297 plUInt64 ComputeHash(plUInt64 uiSeed = 0)
const;
301 friend struct CompareFunc;
302 friend struct GetTypeFromVariantFunc;
309 PL_ALWAYS_INLINE SharedData(
void* pPtr,
const plRTTI* pType)
314 virtual ~SharedData() =
default;
315 virtual SharedData* Clone()
const = 0;
318 template <
typename T>
319 class TypedSharedData :
public SharedData
325 PL_ALWAYS_INLINE TypedSharedData(
const T& value,
const plRTTI* pType =
nullptr)
326 : SharedData(&m_t, pType)
331 virtual SharedData* Clone()
const override
333 return PL_DEFAULT_NEW(TypedSharedData<T>, m_t, m_pType);
337 class RTTISharedData :
public SharedData
340 RTTISharedData(
void* pData,
const plRTTI* pType);
344 virtual SharedData* Clone()
const override;
349 constexpr static int DataSize = 4 *
sizeof(float) -
sizeof(
void*);
350 plUInt8 m_Data[DataSize];
358 InlinedStruct inlined;
361 plUInt32 m_uiType : 31;
362 plUInt32 m_bIsShared : 1;
364 template <
typename T>
365 void InitInplace(
const T& value);
367 template <
typename T>
368 void InitShared(
const T& value);
370 template <
typename T>
372 template <
typename T>
375 void InitTypedPointer(
void* value,
const plRTTI* pType);
381 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::DirectCast,
int> = 0>
382 const T& Cast()
const;
383 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::PointerCast,
int> = 0>
385 template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification ==
plVariantClass::TypedObject,
int> = 0>
386 const T Cast()
const;
388 const T& Cast()
const;
390 static bool IsNumberStatic(plUInt32 type);
391 static bool IsFloatingPointStatic(plUInt32 type);
392 static bool IsStringStatic(plUInt32 type);
393 static bool IsHashedStringStatic(plUInt32 type);
394 static bool IsVector2Static(plUInt32 type);
395 static bool IsVector3Static(plUInt32 type);
396 static bool IsVector4Static(plUInt32 type);
399 static bool IsDerivedFrom(
const plRTTI* pType1,
const plRTTI* pType2);
402 template <
typename T>
403 T ConvertNumber()
const;
411PL_ALWAYS_INLINE T plDynamicCast(
const plVariant& variant)
413 if (variant.
IsA<T>())
415 return variant.
Get<T>();
435#include <Foundation/Types/Implementation/VariantHelper_inl.h>
437#include <Foundation/Types/Implementation/Variant_inl.h>
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
A 8bit per channel unsigned normalized (values interpreted as 0-1) color storage format that represen...
Definition Color8UNorm.h:99
plColor represents an RGBA color in linear color space. Values are stored as float,...
Definition Color.h:44
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
A class to use together with plHashedString for quick comparisons with temporary strings that need no...
Definition HashedString.h:151
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
Definition VariantHelper_inl.h:175
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
bool operator==(const T &other) const
See non-templated operator==.
void operator=(const T &value)
Deduces the type of T and stores value.
bool CanConvertTo() const
Returns whether the stored type can generally be converted to the desired type.
const T & Get() const
Returns the variants value as the provided type.
bool IsA() const
Returns whether the stored type is exactly the given type.
This namespace provides common math-functionality as functions.
Definition Constants.h:6
PL_FORCE_INLINE T Lerp(T f1, T f2, float fFactor)
Returns the linear interpolation of f1 and f2. factor is a value between 0 and 1.
Definition Math_inl.h:230
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
Type traits.
Definition TypeTraits.h:12
Defines a reference to an immutable object owned by an plVariant.
Definition Variant.h:24
A typed raw pointer.
Definition TypedPointer.h:13
helper struct to wrap a string pointer
Definition Variant.h:52
@ CustomTypeCast
Custom object types.
Definition VariantType.h:90
@ PointerCast
Any cast to T*.
Definition VariantType.h:88
@ DirectCast
A standard type.
Definition VariantType.h:87
@ TypedObject
plTypedObject cast. Needed because at no point does and plVariant ever store a plTypedObject so it ca...
Definition VariantType.h:89
A helper struct to convert the C++ type, which is passed as the template argument,...
Definition VariantType.h:97
This enum describes the type of data that is currently stored inside the variant.
Definition VariantType.h:20
Enum
This enum describes the type of data that is currently stored inside the variant. Note that changes t...
Definition VariantType.h:26