Optimized ResourceRef assignation

Former-commit-id: 9dfdadb8e34f17c93caabef12f097504c89ee51b
This commit is contained in:
Lynix 2013-03-16 01:01:16 +01:00
parent 63fae2f9ca
commit b82cbc074b
2 changed files with 18 additions and 0 deletions

View File

@ -32,6 +32,7 @@ class NzResourceRef
operator T*() const; operator T*() const;
T* operator->() const; T* operator->() const;
NzResourceRef& operator=(T* resource);
NzResourceRef& operator=(const NzResourceRef& ref); NzResourceRef& operator=(const NzResourceRef& ref);
NzResourceRef& operator=(NzResourceRef&& ref); NzResourceRef& operator=(NzResourceRef&& ref);

View File

@ -93,6 +93,23 @@ T* NzResourceRef<T>::operator->() const
return m_resource; return m_resource;
} }
template<typename T>
NzResourceRef<T>& NzResourceRef<T>::operator=(T* resource)
{
if (m_resource != resource)
{
Release();
if (resource)
{
m_resource = resource;
m_resource->AddResourceReference();
}
}
return *this;
}
template<typename T> template<typename T>
NzResourceRef<T>& NzResourceRef<T>::operator=(const NzResourceRef& ref) NzResourceRef<T>& NzResourceRef<T>::operator=(const NzResourceRef& ref)
{ {