// 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 template NzObjectRef::NzObjectRef() : m_object(nullptr) { } template NzObjectRef::NzObjectRef(T* object) : m_object(object) { if (m_object) m_object->AddReference(); } template NzObjectRef::NzObjectRef(const NzObjectRef& ref) : m_object(ref.m_object) { if (m_object) m_object->AddReference(); } template template NzObjectRef::NzObjectRef(const NzObjectRef& ref) : NzObjectRef(ref.Get()) { } template NzObjectRef::NzObjectRef(NzObjectRef&& ref) noexcept : m_object(ref.m_object) { ref.m_object = nullptr; // On vole la référence } template NzObjectRef::~NzObjectRef() { if (m_object) m_object->RemoveReference(); } template T* NzObjectRef::Get() const { return m_object; } template bool NzObjectRef::IsValid() const { return m_object != nullptr; } template T* NzObjectRef::Release() { T* object = m_object; m_object = nullptr; return object; } template bool NzObjectRef::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 NzObjectRef& NzObjectRef::Swap(NzObjectRef& ref) { std::swap(m_object, ref.m_object); return *this; } template NzObjectRef::operator bool() const { return IsValid(); } template NzObjectRef::operator T*() const { return m_object; } template T* NzObjectRef::operator->() const { return m_object; } template NzObjectRef& NzObjectRef::operator=(T* object) { Reset(object); return *this; } template NzObjectRef& NzObjectRef::operator=(const NzObjectRef& ref) { Reset(ref.m_object); return *this; } template template NzObjectRef& NzObjectRef::operator=(const NzObjectRef& ref) { static_assert(std::is_convertible::value, "U is not implicitly convertible to T"); Reset(ref.Get()); return *this; } template NzObjectRef& NzObjectRef::operator=(NzObjectRef&& ref) noexcept { Reset(); std::swap(m_object, ref.m_object); return *this; } #include