// Copyright (c) Wojciech Figat. All rights reserved. #pragma once #include "Engine/Scripting/ScriptingObjectInterfaceReferenceUtils.h" /// /// The scene object interface reference. /// /// The type of the scripting interface. template API_CLASS(InBuild) class ScriptingObjectInterfaceReference : public ScriptingObjectReferenceBase { typedef ScriptingObjectInterfaceReferenceHelper Helper; public: typedef ScriptingObjectInterfaceReference Type; public: /// /// Initializes a new instance of the class. /// ScriptingObjectInterfaceReference() { } /// /// Initializes a new instance of the class. /// /// The object to link. ScriptingObjectInterfaceReference(SceneObject* obj) : ScriptingObjectReferenceBase(Helper::IsValidObject(obj) ? obj : nullptr) { } /// /// Initializes a new instance of the class. /// /// The interface object to link. ScriptingObjectInterfaceReference(T* interfaceObj) : ScriptingObjectReferenceBase(Helper::GetSceneObject(interfaceObj)) { } /// /// Initializes a new instance of the class. /// /// The other property. ScriptingObjectInterfaceReference(const ScriptingObjectInterfaceReference& other) : ScriptingObjectReferenceBase(other._object) { } ScriptingObjectInterfaceReference(ScriptingObjectInterfaceReference&& other) noexcept : ScriptingObjectReferenceBase(MoveTemp(other)) { } /// /// Finalizes an instance of the class. /// ~ScriptingObjectInterfaceReference() { } public: FORCE_INLINE bool operator==(SceneObject* other) const { return _object == other; } FORCE_INLINE bool operator!=(SceneObject* other) const { return _object != other; } FORCE_INLINE bool operator==(T* other) const { return Get() == other; } FORCE_INLINE bool operator!=(T* other) const { return Get() != other; } FORCE_INLINE bool operator==(const ScriptingObjectInterfaceReference& other) const { return _object == other._object; } FORCE_INLINE bool operator!=(const ScriptingObjectInterfaceReference& other) const { return _object != other._object; } FORCE_INLINE ScriptingObjectInterfaceReference& operator=(SceneObject* other) { OnSet(Helper::IsValidObject(other) ? other : nullptr); return *this; } FORCE_INLINE ScriptingObjectInterfaceReference& operator=(T* other) { OnSet(Helper::GetSceneObject(other)); return *this; } ScriptingObjectInterfaceReference& operator=(const ScriptingObjectInterfaceReference& other) { OnSet(other._object); return *this; } ScriptingObjectInterfaceReference& operator=(ScriptingObjectInterfaceReference&& other) noexcept { ScriptingObjectReferenceBase::operator=(MoveTemp(other)); return *this; } FORCE_INLINE ScriptingObjectInterfaceReference& operator=(const Guid& id) { OnSet(Helper::FindSceneObject(id)); return *this; } /// /// Implicit conversion to the interface. /// FORCE_INLINE operator T*() const { return Get(); } /// /// Implicit conversion to boolean value. /// FORCE_INLINE operator bool() const { return _object != nullptr; } /// /// Interface accessor. /// FORCE_INLINE T* operator->() const { return Get(); } /// /// Gets the interface pointer. /// FORCE_INLINE T* Get() const { return ScriptingObject::ToInterface(_object); } /// /// Gets the referenced object. /// FORCE_INLINE SceneObject* GetObject() const { return static_cast(_object); } /// /// Copies the object ID into the raw storage. /// FORCE_INLINE void CopyID(uint32 id[4]) const { memset(id, 0, sizeof(uint32) * 4); if (_object) { const Guid value = GetID(); memcpy(id, &value, sizeof(uint32) * 4); } } /// /// Gets the object as a given type (static cast). /// template FORCE_INLINE U* As() const { return static_cast(_object); } }; template uint32 GetHash(const ScriptingObjectInterfaceReference& key) { return GetHash(key.GetID()); }