// Copyright (C) 2014 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_resource(nullptr) { } template NzObjectRef::NzObjectRef(T* resource) : m_resource(resource) { if (m_resource) m_resource->AddReference(); } template NzObjectRef::NzObjectRef(const NzObjectRef& ref) : m_resource(ref.m_resource) { if (m_resource) m_resource->AddReference(); } template NzObjectRef::NzObjectRef(NzObjectRef&& ref) noexcept : m_resource(ref.m_resource) { ref.m_resource = nullptr; // On vole la référence } template NzObjectRef::~NzObjectRef() { if (m_resource) m_resource->RemoveReference(); } template bool NzObjectRef::IsValid() const { return m_resource != nullptr; } template T* NzObjectRef::Release() { T* resource = m_resource; m_resource = nullptr; return resource; } template bool NzObjectRef::Reset(T* resource) { bool destroyed = false; if (m_resource != resource) { if (m_resource) { destroyed = m_resource->RemoveReference(); m_resource = nullptr; } m_resource = resource; if (m_resource) m_resource->AddReference(); } return destroyed; } template NzObjectRef& NzObjectRef::Swap(NzObjectRef& ref) { std::swap(m_resource, ref.m_resource); return *this; } template NzObjectRef::operator bool() const { return IsValid(); } template NzObjectRef::operator T*() const { return m_resource; } template T* NzObjectRef::operator->() const { return m_resource; } template NzObjectRef& NzObjectRef::operator=(T* resource) { Reset(resource); return *this; } template NzObjectRef& NzObjectRef::operator=(const NzObjectRef& ref) { Reset(ref.m_resource); return *this; } template NzObjectRef& NzObjectRef::operator=(NzObjectRef&& ref) noexcept { Reset(); std::swap(m_resource, ref.m_resource); return *this; } #include