// Copyright (C) 2015 Jérôme Leclercq // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include namespace Nz { template ObjectRef::ObjectRef() : m_object(nullptr) { } template ObjectRef::ObjectRef(T* object) : m_object(object) { if (m_object) m_object->AddReference(); } template ObjectRef::ObjectRef(const ObjectRef& ref) : m_object(ref.m_object) { if (m_object) m_object->AddReference(); } template template ObjectRef::ObjectRef(const ObjectRef& ref) : ObjectRef(ref.Get()) { } template ObjectRef::ObjectRef(ObjectRef&& ref) noexcept : m_object(ref.m_object) { ref.m_object = nullptr; // On vole la référence } template ObjectRef::~ObjectRef() { if (m_object) m_object->RemoveReference(); } template T* ObjectRef::Get() const { return m_object; } template bool ObjectRef::IsValid() const { return m_object != nullptr; } template T* ObjectRef::Release() { T* object = m_object; m_object = nullptr; return object; } template bool ObjectRef::Reset(T* object) { bool destroyed = false; if (m_object != object) { if (m_object) destroyed = m_object->RemoveReference(); m_object = object; if (m_object) m_object->AddReference(); } return destroyed; } template ObjectRef& ObjectRef::Swap(ObjectRef& ref) { std::swap(m_object, ref.m_object); return *this; } template ObjectRef::operator bool() const { return IsValid(); } template ObjectRef::operator T*() const { return m_object; } template T* ObjectRef::operator->() const { return m_object; } template ObjectRef& ObjectRef::operator=(T* object) { Reset(object); return *this; } template ObjectRef& ObjectRef::operator=(const ObjectRef& ref) { Reset(ref.m_object); return *this; } template template ObjectRef& ObjectRef::operator=(const ObjectRef& ref) { static_assert(std::is_convertible::value, "U is not implicitly convertible to T"); Reset(ref.Get()); return *this; } template ObjectRef& ObjectRef::operator=(ObjectRef&& ref) noexcept { Reset(); std::swap(m_object, ref.m_object); return *this; } } #include