Plasma Engine  2.0
Loading...
Searching...
No Matches
Variant_inl.h
1
2PL_WARNING_PUSH()
3PL_WARNING_DISABLE_MSVC(4702) // Unreachable code for some reason
4
5PL_ALWAYS_INLINE plVariant::plVariant()
6{
7 m_uiType = Type::Invalid;
8 m_bIsShared = false;
9}
10
11PL_WARNING_POP()
12
13PL_WARNING_PUSH()
14PL_WARNING_DISABLE_CLANG("-Wunused-local-typedef")
15PL_WARNING_DISABLE_GCC("-Wunused-local-typedefs")
16
17PL_ALWAYS_INLINE plVariant::plVariant(const plVariant& other)
18{
19 CopyFrom(other);
20}
21
22PL_ALWAYS_INLINE plVariant::plVariant(plVariant&& other) noexcept
23{
24 MoveFrom(std::move(other));
25}
26
27PL_ALWAYS_INLINE plVariant::plVariant(const bool& value)
28{
29 InitInplace(value);
30}
31
32PL_ALWAYS_INLINE plVariant::plVariant(const plInt8& value)
33{
34 InitInplace(value);
35}
36
37PL_ALWAYS_INLINE plVariant::plVariant(const plUInt8& value)
38{
39 InitInplace(value);
40}
41
42PL_ALWAYS_INLINE plVariant::plVariant(const plInt16& value)
43{
44 InitInplace(value);
45}
46
47PL_ALWAYS_INLINE plVariant::plVariant(const plUInt16& value)
48{
49 InitInplace(value);
50}
51
52PL_ALWAYS_INLINE plVariant::plVariant(const plInt32& value)
53{
54 InitInplace(value);
55}
56
57PL_ALWAYS_INLINE plVariant::plVariant(const plUInt32& value)
58{
59 InitInplace(value);
60}
61
62PL_ALWAYS_INLINE plVariant::plVariant(const plInt64& value)
63{
64 InitInplace(value);
65}
66
67PL_ALWAYS_INLINE plVariant::plVariant(const plUInt64& value)
68{
69 InitInplace(value);
70}
71
72PL_ALWAYS_INLINE plVariant::plVariant(const float& value)
73{
74 InitInplace(value);
75}
76
77PL_ALWAYS_INLINE plVariant::plVariant(const double& value)
78{
79 InitInplace(value);
80}
81
82PL_ALWAYS_INLINE plVariant::plVariant(const plColor& value)
83{
84 InitInplace(value);
85}
86
87PL_ALWAYS_INLINE plVariant::plVariant(const plVec2& value)
88{
89 InitInplace(value);
90}
91
92PL_ALWAYS_INLINE plVariant::plVariant(const plVec3& value)
93{
94 InitInplace(value);
95}
96
97PL_ALWAYS_INLINE plVariant::plVariant(const plVec4& value)
98{
99 InitInplace(value);
100}
101
102PL_ALWAYS_INLINE plVariant::plVariant(const plVec2I32& value)
103{
104 InitInplace(value);
105}
106
107PL_ALWAYS_INLINE plVariant::plVariant(const plVec3I32& value)
108{
109 InitInplace(value);
110}
111
112PL_ALWAYS_INLINE plVariant::plVariant(const plVec4I32& value)
113{
114 InitInplace(value);
115}
116
117PL_ALWAYS_INLINE plVariant::plVariant(const plVec2U32& value)
118{
119 InitInplace(value);
120}
121
122PL_ALWAYS_INLINE plVariant::plVariant(const plVec3U32& value)
123{
124 InitInplace(value);
125}
126
127PL_ALWAYS_INLINE plVariant::plVariant(const plVec4U32& value)
128{
129 InitInplace(value);
130}
131
132PL_ALWAYS_INLINE plVariant::plVariant(const plQuat& value)
133{
134 InitInplace(value);
135}
136
137PL_ALWAYS_INLINE plVariant::plVariant(const plTime& value)
138{
139 InitInplace(value);
140}
141
142PL_ALWAYS_INLINE plVariant::plVariant(const plUuid& value)
143{
144 InitInplace(value);
145}
146
147PL_ALWAYS_INLINE plVariant::plVariant(const plAngle& value)
148{
149 InitInplace(value);
150}
151
152PL_ALWAYS_INLINE plVariant::plVariant(const plColorGammaUB& value)
153{
154 InitInplace(value);
155}
156
157PL_ALWAYS_INLINE plVariant::plVariant(const plHashedString& value)
158{
159 InitInplace(value);
160}
161
162PL_ALWAYS_INLINE plVariant::plVariant(const plTempHashedString& value)
163{
164 InitInplace(value);
165}
166
167template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::CustomTypeCast, int>>
168PL_ALWAYS_INLINE plVariant::plVariant(const T& value)
169{
170 const constexpr bool forceSharing = TypeDeduction<T>::forceSharing;
171 const constexpr bool inlineSized = sizeof(T) <= InlinedStruct::DataSize;
172 const constexpr bool isPOD = plIsPodType<T>::value;
173 InitTypedObject(value, plTraitInt < (!forceSharing && inlineSized && isPOD) ? 1 : 0 > ());
174}
175
176template <typename T>
177PL_ALWAYS_INLINE plVariant::plVariant(const T* value)
178{
179 constexpr bool bla = !std::is_same<T, void>::value;
180 static_assert(bla);
181 InitTypedPointer(const_cast<T*>(value), plGetStaticRTTI<T>());
182}
183
184PL_ALWAYS_INLINE plVariant::plVariant(void* value, const plRTTI* pType)
185{
186 InitTypedPointer(value, pType);
187}
188
189PL_ALWAYS_INLINE plVariant::~plVariant()
190{
191 Release();
192}
193
194PL_ALWAYS_INLINE void plVariant::operator=(const plVariant& other)
195{
196 if (this != &other)
197 {
198 Release();
199 CopyFrom(other);
200 }
201}
202
203PL_ALWAYS_INLINE void plVariant::operator=(plVariant&& other) noexcept
204{
205 if (this != &other)
206 {
207 Release();
208 MoveFrom(std::move(other));
209 }
210}
211
212template <typename T>
213PL_ALWAYS_INLINE void plVariant::operator=(const T& value)
214{
215 *this = plVariant(value);
216}
217
218template <typename T>
219PL_FORCE_INLINE bool plVariant::operator==(const T& other) const
220{
221 if (IsFloatingPoint())
222 {
223 if constexpr (TypeDeduction<T>::value > Type::Invalid && TypeDeduction<T>::value <= Type::Double)
224 {
225 return ConvertNumber<double>() == static_cast<double>(other);
226 }
227
228 return false;
229 }
230 else if (IsNumber())
231 {
232 if constexpr (TypeDeduction<T>::value > Type::Invalid && TypeDeduction<T>::value <= Type::Double)
233 {
234 return ConvertNumber<plInt64>() == static_cast<plInt64>(other);
235 }
236
237 return false;
238 }
239
240 if constexpr (std::is_same_v<T, plHashedString>)
241 {
242 if (m_uiType == Type::TempHashedString)
243 {
244 return Cast<plTempHashedString>() == other;
245 }
246 }
247 else if constexpr (std::is_same_v<T, plTempHashedString>)
248 {
249 if (m_uiType == Type::HashedString)
250 {
251 return Cast<plHashedString>() == other;
252 }
253 }
254 else if constexpr (std::is_same_v<T, plStringView>)
255 {
256 if (m_uiType == Type::String)
257 {
258 return Cast<plString>().GetView() == other;
259 }
260 }
261 else if constexpr (std::is_same_v<T, plString>)
262 {
263 if (m_uiType == Type::StringView)
264 {
265 return Cast<plStringView>() == other.GetView();
266 }
267 }
268
269 using StorageType = typename TypeDeduction<T>::StorageType;
270 PL_ASSERT_DEV(IsA<StorageType>(), "Stored type '{0}' does not match comparison type '{1}'", m_uiType, TypeDeduction<T>::value);
271 return Cast<StorageType>() == other;
272}
273
274PL_ALWAYS_INLINE bool plVariant::IsValid() const
275{
276 return m_uiType != Type::Invalid;
277}
278
279PL_ALWAYS_INLINE bool plVariant::IsNumber() const
280{
281 return IsNumberStatic(m_uiType);
282}
283
284PL_ALWAYS_INLINE bool plVariant::IsFloatingPoint() const
285{
286 return IsFloatingPointStatic(m_uiType);
287}
288
289PL_ALWAYS_INLINE bool plVariant::IsString() const
290{
291 return IsStringStatic(m_uiType);
292}
293
294PL_ALWAYS_INLINE bool plVariant::IsHashedString() const
295{
296 return IsHashedStringStatic(m_uiType);
297}
298
299template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::DirectCast, int>>
300PL_ALWAYS_INLINE bool plVariant::IsA() const
301{
302 return m_uiType == TypeDeduction<T>::value;
303}
304
305template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::PointerCast, int>>
306PL_ALWAYS_INLINE bool plVariant::IsA() const
307{
308 if (m_uiType == TypeDeduction<T>::value)
309 {
310 const plTypedPointer& ptr = *reinterpret_cast<const plTypedPointer*>(&m_Data);
311 // Always allow cast to void*.
312 if constexpr (std::is_same<T, void*>::value || std::is_same<T, const void*>::value)
313 {
314 return true;
315 }
316 else if (ptr.m_pType)
317 {
318 using NonPointerT = typename plTypeTraits<T>::NonConstReferencePointerType;
319 const plRTTI* pType = plGetStaticRTTI<NonPointerT>();
320 return IsDerivedFrom(ptr.m_pType, pType);
321 }
322 else if (!ptr.m_pObject)
323 {
324 // nullptr can be converted to anything
325 return true;
326 }
327 }
328 return false;
329}
330
331template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::TypedObject, int>>
332PL_ALWAYS_INLINE bool plVariant::IsA() const
333{
334 return m_uiType == TypeDeduction<T>::value;
335}
336
337template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::CustomTypeCast, int>>
338PL_ALWAYS_INLINE bool plVariant::IsA() const
339{
340 using NonRefT = typename plTypeTraits<T>::NonConstReferenceType;
341 if (m_uiType == TypeDeduction<T>::value)
342 {
343 if (const plRTTI* pType = GetReflectedType())
344 {
345 return IsDerivedFrom(pType, plGetStaticRTTI<NonRefT>());
346 }
347 }
348 return false;
349}
350
352{
353 return static_cast<Type::Enum>(m_uiType);
354}
355
356template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::DirectCast, int>>
357PL_ALWAYS_INLINE const T& plVariant::Get() const
358{
359 PL_ASSERT_DEV(IsA<T>(), "Stored type '{0}' does not match requested type '{1}'", m_uiType, TypeDeduction<T>::value);
360 return Cast<T>();
361}
362
363template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::PointerCast, int>>
364PL_ALWAYS_INLINE T plVariant::Get() const
365{
366 PL_ASSERT_DEV(IsA<T>(), "Stored type '{0}' does not match requested type '{1}'", m_uiType, TypeDeduction<T>::value);
367 return Cast<T>();
368}
369
370template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::TypedObject, int>>
371PL_ALWAYS_INLINE const T plVariant::Get() const
372{
373 PL_ASSERT_DEV(IsA<T>(), "Stored type '{0}' does not match requested type '{1}'", m_uiType, TypeDeduction<T>::value);
374 return Cast<T>();
375}
376
377template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::CustomTypeCast, int>>
378PL_ALWAYS_INLINE const T& plVariant::Get() const
379{
380 PL_ASSERT_DEV(m_uiType == TypeDeduction<T>::value, "Stored type '{0}' does not match requested type '{1}'", m_uiType, TypeDeduction<T>::value);
381 return Cast<T>();
382}
383
384template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::DirectCast, int>>
385PL_ALWAYS_INLINE T& plVariant::GetWritable()
386{
388 return const_cast<T&>(Get<T>());
389}
390
391template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::PointerCast, int>>
392PL_ALWAYS_INLINE T plVariant::GetWritable()
393{
395 return const_cast<T>(Get<T>());
396}
397
398template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::CustomTypeCast, int>>
399PL_ALWAYS_INLINE T& plVariant::GetWritable()
400{
402 return const_cast<T&>(Get<T>());
403}
404
405PL_ALWAYS_INLINE const void* plVariant::GetData() const
406{
407 if (m_uiType == Type::TypedPointer)
408 {
409 return Cast<plTypedPointer>().m_pObject;
410 }
411 return m_bIsShared ? m_Data.shared->m_Ptr : &m_Data;
412}
413
414template <typename T>
415PL_ALWAYS_INLINE bool plVariant::CanConvertTo() const
416{
417 return CanConvertTo(static_cast<Type::Enum>(TypeDeduction<T>::value));
418}
419
420template <typename T>
421T plVariant::ConvertTo(plResult* out_pConversionStatus /* = nullptr*/) const
422{
423 if (!CanConvertTo<T>())
424 {
425 if (out_pConversionStatus != nullptr)
426 *out_pConversionStatus = PL_FAILURE;
427
428 return T();
429 }
430
431 if (m_uiType == TypeDeduction<T>::value)
432 {
433 if (out_pConversionStatus != nullptr)
434 *out_pConversionStatus = PL_SUCCESS;
435
436 return Cast<T>();
437 }
438
439 T result = {};
440 bool bSuccessful = true;
441 plVariantHelper::To(*this, result, bSuccessful);
442
443 if (out_pConversionStatus != nullptr)
444 *out_pConversionStatus = bSuccessful ? PL_SUCCESS : PL_FAILURE;
445
446 return result;
447}
448
449
451
452template <typename T>
453PL_FORCE_INLINE void plVariant::InitInplace(const T& value)
454{
455 static_assert(TypeDeduction<T>::value != Type::Invalid, "value of this type cannot be stored in a Variant");
456 static_assert(plGetTypeClass<T>::value <= plTypeIsMemRelocatable::value, "in place data needs to be POD or mem relocatable");
457 static_assert(sizeof(T) <= sizeof(m_Data), "value of this type is too big to bestored inline in a Variant");
458 plMemoryUtils::CopyConstruct(reinterpret_cast<T*>(&m_Data), value, 1);
459
460 m_uiType = TypeDeduction<T>::value;
461 m_bIsShared = false;
462}
463
464template <typename T>
465PL_FORCE_INLINE void plVariant::InitTypedObject(const T& value, plTraitInt<0>)
466{
467 using StorageType = typename TypeDeduction<T>::StorageType;
468
469 static_assert((sizeof(StorageType) > sizeof(InlinedStruct::DataSize)) || TypeDeduction<T>::forceSharing, "Value should be inplace instead.");
470 static_assert(TypeDeduction<T>::value == Type::TypedObject, "value of this type cannot be stored in a Variant");
471 const plRTTI* pType = plGetStaticRTTI<T>();
472 m_Data.shared = PL_DEFAULT_NEW(TypedSharedData<StorageType>, value, pType);
473 m_uiType = Type::TypedObject;
474 m_bIsShared = true;
475}
476
477template <typename T>
478PL_FORCE_INLINE void plVariant::InitTypedObject(const T& value, plTraitInt<1>)
479{
480 using StorageType = typename TypeDeduction<T>::StorageType;
481 static_assert((sizeof(StorageType) <= InlinedStruct::DataSize) && !TypeDeduction<T>::forceSharing, "Value can't be stored inplace.");
482 static_assert(TypeDeduction<T>::value == Type::TypedObject, "value of this type cannot be stored in a Variant");
483 static_assert(plIsPodType<T>::value, "in place data needs to be POD");
484 plMemoryUtils::CopyConstruct(reinterpret_cast<T*>(&m_Data), value, 1);
485 m_Data.inlined.m_pType = plGetStaticRTTI<T>();
486 m_uiType = Type::TypedObject;
487 m_bIsShared = false;
488}
489
490inline void plVariant::Release()
491{
492 if (m_bIsShared)
493 {
494 if (m_Data.shared->m_uiRef.Decrement() == 0)
495 {
496 PL_DEFAULT_DELETE(m_Data.shared);
497 }
498 }
499}
500
501inline void plVariant::CopyFrom(const plVariant& other)
502{
503 m_uiType = other.m_uiType;
504 m_bIsShared = other.m_bIsShared;
505
506 if (m_bIsShared)
507 {
508 m_Data.shared = other.m_Data.shared;
509 m_Data.shared->m_uiRef.Increment();
510 }
511 else if (other.IsValid())
512 {
513 m_Data = other.m_Data;
514 }
515}
516
517PL_ALWAYS_INLINE void plVariant::MoveFrom(plVariant&& other)
518{
519 m_uiType = other.m_uiType;
520 m_bIsShared = other.m_bIsShared;
521 m_Data = other.m_Data;
522
523 other.m_uiType = Type::Invalid;
524 other.m_bIsShared = false;
525 other.m_Data.shared = nullptr;
526}
527
528template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::DirectCast, int>>
529const T& plVariant::Cast() const
530{
531 const bool validType = plConversionTest<T, typename TypeDeduction<T>::StorageType>::sameType;
532 static_assert(validType, "Invalid Cast, can only cast to storage type");
533
534 return m_bIsShared ? *static_cast<const T*>(m_Data.shared->m_Ptr) : *reinterpret_cast<const T*>(&m_Data);
535}
536
537template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::PointerCast, int>>
538T plVariant::Cast() const
539{
540 const plTypedPointer& ptr = *reinterpret_cast<const plTypedPointer*>(&m_Data);
541
542 const plRTTI* pType = GetReflectedType();
543 PL_IGNORE_UNUSED(pType);
544 using NonRefPtrT = typename plTypeTraits<T>::NonConstReferencePointerType;
545 if constexpr (!std::is_same<T, void*>::value && !std::is_same<T, const void*>::value)
546 {
547 PL_ASSERT_DEV(pType == nullptr || IsDerivedFrom(pType, plGetStaticRTTI<NonRefPtrT>()), "Object of type '{0}' does not derive from '{}'", GetTypeName(pType), GetTypeName(plGetStaticRTTI<NonRefPtrT>()));
548 }
549 return static_cast<T>(ptr.m_pObject);
550}
551
552template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::TypedObject, int>>
553const T plVariant::Cast() const
554{
555 plTypedObject obj;
556 obj.m_pObject = GetData();
557 obj.m_pType = GetReflectedType();
558 return obj;
559}
560
561template <typename T, typename std::enable_if_t<plVariantTypeDeduction<T>::classification == plVariantClass::CustomTypeCast, int>>
562const T& plVariant::Cast() const
563{
564 const plRTTI* pType = GetReflectedType();
565 PL_IGNORE_UNUSED(pType);
566 using NonRefT = typename plTypeTraits<T>::NonConstReferenceType;
567 PL_ASSERT_DEV(IsDerivedFrom(pType, plGetStaticRTTI<NonRefT>()), "Object of type '{0}' does not derive from '{}'", GetTypeName(pType), GetTypeName(plGetStaticRTTI<NonRefT>()));
568
569 return m_bIsShared ? *static_cast<const T*>(m_Data.shared->m_Ptr) : *reinterpret_cast<const T*>(&m_Data);
570}
571
572PL_ALWAYS_INLINE bool plVariant::IsNumberStatic(plUInt32 type)
573{
574 return type > Type::FirstStandardType && type <= Type::Double;
575}
576
577PL_ALWAYS_INLINE bool plVariant::IsFloatingPointStatic(plUInt32 type)
578{
579 return type == Type::Float || type == Type::Double;
580}
581
582PL_ALWAYS_INLINE bool plVariant::IsStringStatic(plUInt32 type)
583{
584 return type == Type::String || type == Type::StringView;
585}
586
587PL_ALWAYS_INLINE bool plVariant::IsHashedStringStatic(plUInt32 type)
588{
589 return type == Type::HashedString || type == Type::TempHashedString;
590}
591
592PL_ALWAYS_INLINE bool plVariant::IsVector2Static(plUInt32 type)
593{
594 return type == Type::Vector2 || type == Type::Vector2I || type == Type::Vector2U;
595}
596
597PL_ALWAYS_INLINE bool plVariant::IsVector3Static(plUInt32 type)
598{
599 return type == Type::Vector3 || type == Type::Vector3I || type == Type::Vector3U;
600}
601
602PL_ALWAYS_INLINE bool plVariant::IsVector4Static(plUInt32 type)
603{
604 return type == Type::Vector4 || type == Type::Vector4I || type == Type::Vector4U;
605}
606
607template <typename T>
608T plVariant::ConvertNumber() const
609{
610 switch (m_uiType)
611 {
612 case Type::Bool:
613 return static_cast<T>(Cast<bool>());
614 case Type::Int8:
615 return static_cast<T>(Cast<plInt8>());
616 case Type::UInt8:
617 return static_cast<T>(Cast<plUInt8>());
618 case Type::Int16:
619 return static_cast<T>(Cast<plInt16>());
620 case Type::UInt16:
621 return static_cast<T>(Cast<plUInt16>());
622 case Type::Int32:
623 return static_cast<T>(Cast<plInt32>());
624 case Type::UInt32:
625 return static_cast<T>(Cast<plUInt32>());
626 case Type::Int64:
627 return static_cast<T>(Cast<plInt64>());
628 case Type::UInt64:
629 return static_cast<T>(Cast<plUInt64>());
630 case Type::Float:
631 return static_cast<T>(Cast<float>());
632 case Type::Double:
633 return static_cast<T>(Cast<double>());
634 }
635
636 PL_REPORT_FAILURE("Variant is not a number");
637 return T(0);
638}
639
640template <>
642{
643 PL_ALWAYS_INLINE static plUInt32 Hash(const plVariant& value)
644 {
645 plUInt64 uiHash = value.ComputeHash(0);
646 return (plUInt32)uiHash;
647 }
648
649 PL_ALWAYS_INLINE static bool Equal(const plVariant& a, const plVariant& b)
650 {
651 return a.GetType() == b.GetType() && a == b;
652 }
653};
654
655PL_WARNING_POP()
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
T Increment()
Increments the internal value and returns the incremented value.
Definition AtomicInteger_inl.h:35
T Decrement()
Decrements the internal value and returns the decremented value.
Definition AtomicInteger_inl.h:41
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
static void CopyConstruct(Destination *pDestination, const Source &copy, size_t uiCount=1)
Constructs uiCount objects of type T in a raw buffer at pDestination, by creating uiCount copies of c...
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
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
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
const plRTTI * GetReflectedType() const
Returns the plRTTI type of the held value. For TypedPointer and TypedObject this will return the type...
Definition Variant.cpp:593
plVariant()
Initializes the variant to be 'Invalid'.
Definition Variant_inl.h:5
bool IsHashedString() const
Returns whether the stored type is a hashed string (plHashedString or plTempHashedString).
Definition Variant_inl.h:294
bool IsValid() const
Returns whether this variant stores any other type than 'Invalid'.
Definition Variant_inl.h:274
bool operator==(const plVariant &other) const
Will compare the value of this variant to that of other.
Definition Variant.cpp:349
bool IsNumber() const
Returns whether the stored type is numerical type either integer or floating point.
Definition Variant_inl.h:279
~plVariant()
If necessary, this will deallocate any heap memory that is not in use any more.
Definition Variant_inl.h:189
const void * GetData() const
Returns a const void* to the internal data. For TypedPointer and TypedObject this will return a point...
Definition Variant_inl.h:405
T ConvertTo(plResult *out_pConversionStatus=nullptr) const
Tries to convert the stored value to the given type. The optional status parameter can be used to che...
Definition Variant_inl.h:421
plTypedPointer GetWriteAccess()
Returns an writable plTypedPointer to the internal data. If the data is currently shared a clone will...
Definition Variant.cpp:391
plUInt64 ComputeHash(plUInt64 uiSeed=0) const
Computes the hash value of the stored data. Returns uiSeed (unchanged) for an invalid Variant.
Definition Variant.cpp:532
bool IsString() const
Returns whether the stored type is a string (plString or plStringView).
Definition Variant_inl.h:289
bool IsFloatingPoint() const
Returns whether the stored type is floating point (float or double).
Definition Variant_inl.h:284
Type::Enum GetType() const
Returns the exact plVariant::Type value.
Definition Variant_inl.h:351
bool CanConvertTo() const
Returns whether the stored type can generally be converted to the desired type.
void operator=(const plVariant &other)
Copies the data from the other variant into this one.
Definition Variant_inl.h:194
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.
Static Conversion Test.
Definition TypeTraits.h:73
If there is an % operator which takes a plTypeIsMemRelocatable and returns a CompileTimeTrueType T is...
Definition TypeTraits.h:67
Helper struct to calculate the Hash of different types.
Definition HashingUtils.h:75
If there is an % operator which takes a TypeIsPod and returns a CompileTimeTrueType T is Pod....
Definition TypeTraits.h:43
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
typename std::remove_const< typename std::remove_reference< T >::type >::type NonConstReferenceType
removes reference and const qualifier
Definition TypeTraits.h:218
typename std::remove_const< typename std::remove_reference< typename std::remove_pointer< T >::type >::type >::type NonConstReferencePointerType
removes reference, const and pointer qualifier Note that this removes the const and reference of the ...
Definition TypeTraits.h:225
Defines a reference to an immutable object owned by an plVariant.
Definition Variant.h:24
A typed raw pointer.
Definition TypedPointer.h:13
@ 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
Enum
This enum describes the type of data that is currently stored inside the variant. Note that changes t...
Definition VariantType.h:26
@ UInt8
The variant stores an plUInt8.
Definition VariantType.h:33
@ Vector3I
The variant stores an plVec3I32.
Definition VariantType.h:47
@ Int8
The variant stores an plInt8.
Definition VariantType.h:32
@ TempHashedString
The variant stores an plTempHashedString value.
Definition VariantType.h:64
@ Vector2U
The variant stores an plVec2U32.
Definition VariantType.h:49
@ Bool
The variant stores a bool.
Definition VariantType.h:31
@ Int32
The variant stores an plInt32.
Definition VariantType.h:36
@ Vector3
The variant stores an plVec3.
Definition VariantType.h:44
@ Vector4I
The variant stores an plVec4I32.
Definition VariantType.h:48
@ String
The variant stores a string. A heap allocation is required to store this data type.
Definition VariantType.h:56
@ Double
The variant stores a double.
Definition VariantType.h:41
@ TypedPointer
The variant stores an plTypedPointer value. Reflected type and data queries will match the pointed to...
Definition VariantType.h:71
@ FirstStandardType
*** Types that are flagged as 'StandardTypes' (see DetermineTypeFlags) ***
Definition VariantType.h:30
@ UInt16
The variant stores an plUInt16.
Definition VariantType.h:35
@ Float
The variant stores a float.
Definition VariantType.h:40
@ Vector2I
The variant stores an plVec2I32.
Definition VariantType.h:46
@ StringView
The variant stores an plStringView.
Definition VariantType.h:57
@ Vector3U
The variant stores an plVec3U32.
Definition VariantType.h:50
@ HashedString
The variant stores an plHashedString value.
Definition VariantType.h:63
@ Vector2
The variant stores an plVec2.
Definition VariantType.h:43
@ UInt32
The variant stores an plUInt32.
Definition VariantType.h:37
@ Vector4U
The variant stores an plVec4U32.
Definition VariantType.h:51
@ Invalid
The variant stores no (valid) data at the moment.
Definition VariantType.h:27
@ Int16
The variant stores an plInt16.
Definition VariantType.h:34
@ UInt64
The variant stores an plUInt64.
Definition VariantType.h:39
@ Vector4
The variant stores an plVec4.
Definition VariantType.h:45
@ TypedObject
The variant stores an plTypedObject value. Reflected type and data queries will match the object....
Definition VariantType.h:72
@ Int64
The variant stores an plInt64.
Definition VariantType.h:38