Add Variant::AsStructure to comparision operator between VariantType and ScriptingTypeHandle

This commit is contained in:
Wojtek Figat
2023-09-24 19:27:23 +02:00
parent 8a00a3e61e
commit 626bdf2e37
2 changed files with 17 additions and 0 deletions

View File

@@ -255,6 +255,13 @@ bool VariantType::operator==(const VariantType& other) const
return false;
}
bool VariantType::operator==(const ScriptingTypeHandle& type) const
{
if (Type == Null)
return !type;
return type && type.GetType().Fullname == GetTypeName();
}
void VariantType::SetTypeName(const StringView& typeName)
{
if (StringUtils::Length(TypeName) != typeName.Length())

View File

@@ -10,6 +10,7 @@ struct Transform;
struct CommonValue;
template<typename T>
class AssetReference;
struct ScriptingTypeHandle;
/// <summary>
/// Represents an object type that can be interpreted as more than one type.
@@ -120,6 +121,7 @@ public:
VariantType& operator=(const VariantType& other);
bool operator==(const Types& type) const;
bool operator==(const VariantType& other) const;
bool operator==(const ScriptingTypeHandle& type) const;
FORCE_INLINE bool operator!=(const VariantType& other) const
{
@@ -345,6 +347,14 @@ public:
Array<Variant, HeapAllocation>& AsArray();
const Array<Variant, HeapAllocation>& AsArray() const;
template<typename T>
const T* AsStructure() const
{
if (Type.Type == VariantType::Structure && Type == T::TypeInitializer)
return (const T*)AsBlob.Data;
return nullptr;
}
public:
void SetType(const VariantType& type);
void SetType(VariantType&& type);