SharedPtr: Fixes and support for casting to other SharedPtr types
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3a84e4998c
commit
e9a009478f
@ -42,7 +42,7 @@ template <typename T> class SharedPtr
|
|||||||
|
|
||||||
SharedPtr(const SharedPtr<T>& other) : m_ptr(other.m_ptr), m_ref_count(other.m_ref_count)
|
SharedPtr(const SharedPtr<T>& other) : m_ptr(other.m_ptr), m_ref_count(other.m_ref_count)
|
||||||
{
|
{
|
||||||
m_ref_count->ref();
|
if (m_ref_count) m_ref_count->ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr(SharedPtr<T>&& other) : m_ptr(other.m_ptr), m_ref_count(other.m_ref_count)
|
SharedPtr(SharedPtr<T>&& other) : m_ptr(other.m_ptr), m_ref_count(other.m_ref_count)
|
||||||
@ -51,6 +51,12 @@ template <typename T> class SharedPtr
|
|||||||
other.m_ref_count = nullptr;
|
other.m_ref_count = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Tp> operator SharedPtr<Tp>()
|
||||||
|
{
|
||||||
|
if (m_ref_count) m_ref_count->ref();
|
||||||
|
return { (Tp*)m_ptr, m_ref_count };
|
||||||
|
}
|
||||||
|
|
||||||
~SharedPtr()
|
~SharedPtr()
|
||||||
{
|
{
|
||||||
if (m_ref_count && m_ref_count->unref())
|
if (m_ref_count && m_ref_count->unref())
|
||||||
@ -73,7 +79,7 @@ template <typename T> class SharedPtr
|
|||||||
m_ptr = other.m_ptr;
|
m_ptr = other.m_ptr;
|
||||||
m_ref_count = other.m_ref_count;
|
m_ref_count = other.m_ref_count;
|
||||||
|
|
||||||
m_ref_count->ref();
|
if (m_ref_count) m_ref_count->ref();
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user