4#if PL_ENABLED(PL_COMPILER_MSVC_PURE)
5# define CALL_FUNCTOR(functor, type) return functor.operator()<type>(std::forward<Args>(args)...)
7# define CALL_FUNCTOR(functor, type) return functor.template operator()<type>(std::forward<Args>(args)...)
10template <
typename Functor,
class... Args>
16 CALL_FUNCTOR(ref_functor,
bool);
20 CALL_FUNCTOR(ref_functor, plInt8);
24 CALL_FUNCTOR(ref_functor, plUInt8);
28 CALL_FUNCTOR(ref_functor, plInt16);
32 CALL_FUNCTOR(ref_functor, plUInt16);
36 CALL_FUNCTOR(ref_functor, plInt32);
40 CALL_FUNCTOR(ref_functor, plUInt32);
44 CALL_FUNCTOR(ref_functor, plInt64);
48 CALL_FUNCTOR(ref_functor, plUInt64);
52 CALL_FUNCTOR(ref_functor,
float);
56 CALL_FUNCTOR(ref_functor,
double);
60 CALL_FUNCTOR(ref_functor,
plColor);
68 CALL_FUNCTOR(ref_functor,
plVec2);
72 CALL_FUNCTOR(ref_functor,
plVec3);
76 CALL_FUNCTOR(ref_functor,
plVec4);
104 CALL_FUNCTOR(ref_functor,
plQuat);
108 CALL_FUNCTOR(ref_functor,
plMat3);
112 CALL_FUNCTOR(ref_functor,
plMat4);
120 CALL_FUNCTOR(ref_functor,
plString);
132 CALL_FUNCTOR(ref_functor,
plTime);
136 CALL_FUNCTOR(ref_functor,
plUuid);
140 CALL_FUNCTOR(ref_functor,
plAngle);
164 PL_REPORT_FAILURE(
"Could not dispatch type '{0}'", type);
177 friend struct ConvertFunc;
179 static void To(
const plVariant& value,
bool& result,
bool& bSuccessful)
184 result = value.ConvertNumber<plInt32>() != 0;
195 PL_REPORT_FAILURE(
"Conversion to bool failed");
198 static void To(
const plVariant& value, plInt8& result,
bool& bSuccessful)
200 plInt32 tempResult = 0;
201 To(value, tempResult, bSuccessful);
202 result = (plInt8)tempResult;
205 static void To(
const plVariant& value, plUInt8& result,
bool& bSuccessful)
207 plUInt32 tempResult = 0;
208 To(value, tempResult, bSuccessful);
209 result = (plUInt8)tempResult;
212 static void To(
const plVariant& value, plInt16& result,
bool& bSuccessful)
214 plInt32 tempResult = 0;
215 To(value, tempResult, bSuccessful);
216 result = (plInt16)tempResult;
219 static void To(
const plVariant& value, plUInt16& result,
bool& bSuccessful)
221 plUInt32 tempResult = 0;
222 To(value, tempResult, bSuccessful);
223 result = (plUInt16)tempResult;
226 static void To(
const plVariant& value, plInt32& result,
bool& bSuccessful)
231 result = value.ConvertNumber<plInt32>();
242 PL_REPORT_FAILURE(
"Conversion to int failed");
245 static void To(
const plVariant& value, plUInt32& result,
bool& bSuccessful)
250 result = value.ConvertNumber<plUInt32>();
254 plInt64 tmp = result;
261 result = (plUInt32)tmp;
264 PL_REPORT_FAILURE(
"Conversion to uint failed");
267 static void To(
const plVariant& value, plInt64& result,
bool& bSuccessful)
272 result = value.ConvertNumber<plInt64>();
283 PL_REPORT_FAILURE(
"Conversion to int64 failed");
286 static void To(
const plVariant& value, plUInt64& result,
bool& bSuccessful)
291 result = value.ConvertNumber<plUInt64>();
295 plInt64 tmp = result;
302 result = (plUInt64)tmp;
305 PL_REPORT_FAILURE(
"Conversion to uint64 failed");
308 static void To(
const plVariant& value,
float& result,
bool& bSuccessful)
313 result = value.ConvertNumber<
float>();
327 PL_REPORT_FAILURE(
"Conversion to float failed");
330 static void To(
const plVariant& value,
double& result,
bool& bSuccessful)
335 result = value.ConvertNumber<
double>();
346 PL_REPORT_FAILURE(
"Conversion to double failed");
355 result =
"<Invalid>";
359 ToStringFunc toStringFunc;
360 toStringFunc.m_pThis = &value;
361 toStringFunc.m_pResult = &result;
387 PL_REPORT_FAILURE(
"Conversion to plColor failed");
395 result = value.Cast<
plColor>();
397 PL_REPORT_FAILURE(
"Conversion to plColorGammaUB failed");
400 template <
typename T,
typename V1,
typename V2>
401 static void ToVec2X(
const plVariant& value, T& result,
bool& bSuccessful)
407 const V1& v = value.Cast<V1>();
408 result = T(
static_cast<typename T::ComponentType
>(v.x),
static_cast<typename T::ComponentType
>(v.y));
410 else if (value.
IsA<V2>())
412 const V2& v = value.Cast<V2>();
413 result = T(
static_cast<typename T::ComponentType
>(v.x),
static_cast<typename T::ComponentType
>(v.y));
417 PL_REPORT_FAILURE(
"Conversion to plVec2X failed");
422 static void To(
const plVariant& value,
plVec2& result,
bool& bSuccessful) { ToVec2X<plVec2, plVec2I32, plVec2U32>(value, result, bSuccessful); }
424 static void To(
const plVariant& value,
plVec2I32& result,
bool& bSuccessful) { ToVec2X<plVec2I32, plVec2, plVec2U32>(value, result, bSuccessful); }
426 static void To(
const plVariant& value,
plVec2U32& result,
bool& bSuccessful) { ToVec2X<plVec2U32, plVec2I32, plVec2>(value, result, bSuccessful); }
428 template <
typename T,
typename V1,
typename V2>
429 static void ToVec3X(
const plVariant& value, T& result,
bool& bSuccessful)
435 const V1& v = value.Cast<V1>();
436 result = T(
static_cast<typename T::ComponentType
>(v.x),
static_cast<typename T::ComponentType
>(v.y),
static_cast<typename T::ComponentType
>(v.z));
438 else if (value.
IsA<V2>())
440 const V2& v = value.Cast<V2>();
441 result = T(
static_cast<typename T::ComponentType
>(v.x),
static_cast<typename T::ComponentType
>(v.y),
static_cast<typename T::ComponentType
>(v.z));
445 PL_REPORT_FAILURE(
"Conversion to plVec3X failed");
450 static void To(
const plVariant& value,
plVec3& result,
bool& bSuccessful) { ToVec3X<plVec3, plVec3I32, plVec3U32>(value, result, bSuccessful); }
452 static void To(
const plVariant& value,
plVec3I32& result,
bool& bSuccessful) { ToVec3X<plVec3I32, plVec3, plVec3U32>(value, result, bSuccessful); }
454 static void To(
const plVariant& value,
plVec3U32& result,
bool& bSuccessful) { ToVec3X<plVec3U32, plVec3I32, plVec3>(value, result, bSuccessful); }
456 template <
typename T,
typename V1,
typename V2>
457 static void ToVec4X(
const plVariant& value, T& result,
bool& bSuccessful)
463 const V1& v = value.Cast<V1>();
464 result = T(
static_cast<typename T::ComponentType
>(v.x),
static_cast<typename T::ComponentType
>(v.y),
static_cast<typename T::ComponentType
>(v.z),
static_cast<typename T::ComponentType
>(v.w));
466 else if (value.
IsA<V2>())
468 const V2& v = value.Cast<V2>();
469 result = T(
static_cast<typename T::ComponentType
>(v.x),
static_cast<typename T::ComponentType
>(v.y),
static_cast<typename T::ComponentType
>(v.z),
static_cast<typename T::ComponentType
>(v.w));
473 PL_REPORT_FAILURE(
"Conversion to plVec4X failed");
478 static void To(
const plVariant& value,
plVec4& result,
bool& bSuccessful) { ToVec4X<plVec4, plVec4I32, plVec4U32>(value, result, bSuccessful); }
480 static void To(
const plVariant& value,
plVec4I32& result,
bool& bSuccessful) { ToVec4X<plVec4I32, plVec4, plVec4U32>(value, result, bSuccessful); }
482 static void To(
const plVariant& value,
plVec4U32& result,
bool& bSuccessful) { ToVec4X<plVec4U32, plVec4I32, plVec4>(value, result, bSuccessful); }
489 result.Assign(value.Cast<
plString>());
495 To(value, s, bSuccessful);
513 To(value, s, bSuccessful);
518 template <
typename T>
519 static void To(
const plVariant& value, T& result,
bool& bSuccessful)
527 template <
typename T>
528 PL_ALWAYS_INLINE
void operator()()
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
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
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 IsValid() const
Returns whether this variant stores any other type than 'Invalid'.
Definition Variant_inl.h:274
static auto DispatchTo(Functor &ref_functor, Type::Enum type, Args &&... args)
This will call the overloaded operator() (function call operator) of the provided functor.
Definition VariantHelper_inl.h:11
Type::Enum GetType() const
Returns the exact plVariant::Type value.
Definition Variant_inl.h:351
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.
PL_FOUNDATION_DLL plResult StringToBool(plStringView sText, bool &out_bRes, const char **out_pLastParsePosition=nullptr)
Parses szString and checks that the first word it finds starts with a phrase that can be interpreted ...
Definition ConversionUtils.cpp:310
PL_FOUNDATION_DLL plResult StringToInt(plStringView sText, plInt32 &out_iRes, const char **out_pLastParsePosition=nullptr)
Parses szString and converts it to an integer value. Returns PL_FAILURE if the string contains no par...
Definition ConversionUtils.cpp:87
PL_FOUNDATION_DLL plResult StringToInt64(plStringView sText, plInt64 &out_iRes, const char **out_pLastParsePosition=nullptr)
Same as StringToInt but converts to a 64bit integer value instead.
Definition ConversionUtils.cpp:111
PL_ALWAYS_INLINE const plStringBuilder & ToString(bool value, plStringBuilder &out_sResult)
Converts a bool to a string.
Definition ConversionUtils.h:176
PL_FOUNDATION_DLL plResult StringToFloat(plStringView sText, double &out_fRes, const char **out_pLastParsePosition=nullptr)
Parses szString and converts it to a double value. Returns PL_FAILURE if the string contains no parse...
Definition ConversionUtils.cpp:162
plStringView GetView() const
Returns a string view to this string's data.
Definition StringBase_inl.h:329
The time class encapsulates a double value storing the time in seconds.
Definition Time.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
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
@ Matrix3
The variant stores an plMat3. A heap allocation is required to store this data type.
Definition VariantType.h:53
@ DataBuffer
The variant stores an plDataBuffer, a typedef to DynamicArray<plUInt8>. A heap allocation is required...
Definition VariantType.h:58
@ UInt8
The variant stores an plUInt8.
Definition VariantType.h:33
@ ColorGamma
The variant stores an plColorGammaUB value.
Definition VariantType.h:62
@ 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
@ Matrix4
The variant stores an plMat4. A heap allocation is required to store this data type.
Definition VariantType.h:54
@ Uuid
The variant stores an plUuid value.
Definition VariantType.h:60
@ 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
@ Time
The variant stores an plTime value.
Definition VariantType.h:59
@ Color
The variant stores an plColor.
Definition VariantType.h:42
@ UInt16
The variant stores an plUInt16.
Definition VariantType.h:35
@ Angle
The variant stores an plAngle value.
Definition VariantType.h:61
@ Float
The variant stores a float.
Definition VariantType.h:40
@ VariantArray
The variant stores an array of plVariant's. A heap allocation is required to store this data type.
Definition VariantType.h:69
@ Vector2I
The variant stores an plVec2I32.
Definition VariantType.h:46
@ VariantDictionary
The variant stores a dictionary (hashmap) of plVariant's. A heap allocation is required to store this...
Definition VariantType.h:70
@ 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
@ Transform
The variant stores an plTransform. A heap allocation is required to store this data type.
Definition VariantType.h:55
@ Quaternion
The variant stores an plQuat.
Definition VariantType.h:52
@ Vector4U
The variant stores an plVec4U32.
Definition VariantType.h:51
@ 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