mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-07 13:27:13 +01:00
Implement move semantics for Sqrat smart pointers.
This commit is contained in:
parent
eb58f59f81
commit
579bd4d76b
@ -601,6 +601,45 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Move constructor
|
||||||
|
///
|
||||||
|
/// \param other SharedPtr to move
|
||||||
|
///
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
SharedPtr(SharedPtr<T>&& other)
|
||||||
|
: m_Ptr(other.m_Ptr)
|
||||||
|
, m_RefCount(other.m_RefCount)
|
||||||
|
, m_RefCountRefCount(other.m_RefCountRefCount)
|
||||||
|
{
|
||||||
|
other.m_Ptr = NULL;
|
||||||
|
other.m_RefCount = NULL;
|
||||||
|
other.m_RefCountRefCount = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Move constructor
|
||||||
|
///
|
||||||
|
/// \param other SharedPtr to move
|
||||||
|
///
|
||||||
|
/// \tparam U Type of pointer (usually doesnt need to be defined explicitly)
|
||||||
|
///
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <class U>
|
||||||
|
SharedPtr(SharedPtr<U>&& other)
|
||||||
|
: m_Ptr(static_cast<T*>(other.m_Ptr))
|
||||||
|
, m_RefCount(other.m_RefCount)
|
||||||
|
, m_RefCountRefCount(other.m_RefCountRefCount)
|
||||||
|
{
|
||||||
|
other.m_Ptr = NULL;
|
||||||
|
other.m_RefCount = NULL;
|
||||||
|
other.m_RefCountRefCount = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SCRAT_USE_CXX11_OPTIMIZATIONS
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// Copy constructor
|
/// Copy constructor
|
||||||
///
|
///
|
||||||
@ -694,6 +733,65 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Assigns the SharedPtr
|
||||||
|
///
|
||||||
|
/// \param other SharedPtr to move
|
||||||
|
///
|
||||||
|
/// \return The SharedPtr itself
|
||||||
|
///
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
SharedPtr<T>& operator=(SharedPtr<T>&& other)
|
||||||
|
{
|
||||||
|
if (m_Ptr != other.m_Ptr)
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
|
||||||
|
m_Ptr = other.m_Ptr;
|
||||||
|
m_RefCount = other.m_RefCount;
|
||||||
|
m_RefCountRefCount = other.m_RefCountRefCount;
|
||||||
|
|
||||||
|
other.m_Ptr = NULL;
|
||||||
|
other.m_RefCount = NULL;
|
||||||
|
other.m_RefCountRefCount = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Assigns the SharedPtr
|
||||||
|
///
|
||||||
|
/// \param other SharedPtr to move
|
||||||
|
///
|
||||||
|
/// \tparam U Type of pointer (usually doesnt need to be defined explicitly)
|
||||||
|
///
|
||||||
|
/// \return The SharedPtr itself
|
||||||
|
///
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <class U>
|
||||||
|
SharedPtr<T>& operator=(SharedPtr<U>&& other)
|
||||||
|
{
|
||||||
|
if (m_Ptr != static_cast<T*>(other.m_Ptr))
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
|
||||||
|
m_Ptr = static_cast<T*>(other.m_Ptr);
|
||||||
|
m_RefCount = other.m_RefCount;
|
||||||
|
m_RefCountRefCount = other.m_RefCountRefCount;
|
||||||
|
|
||||||
|
other.m_Ptr = NULL;
|
||||||
|
other.m_RefCount = NULL;
|
||||||
|
other.m_RefCountRefCount = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SCRAT_USE_CXX11_OPTIMIZATIONS
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// Sets up a new object to be managed by the SharedPtr
|
/// Sets up a new object to be managed by the SharedPtr
|
||||||
///
|
///
|
||||||
@ -1027,6 +1125,45 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Move constructor
|
||||||
|
///
|
||||||
|
/// \param other WeakPtr to move
|
||||||
|
///
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
WeakPtr(WeakPtr<T>&& other)
|
||||||
|
: m_Ptr(other.m_Ptr)
|
||||||
|
, m_RefCount(other.m_RefCount)
|
||||||
|
, m_RefCountRefCount(other.m_RefCountRefCount)
|
||||||
|
{
|
||||||
|
other.m_Ptr = NULL;
|
||||||
|
other.m_RefCount = NULL;
|
||||||
|
other.m_RefCountRefCount = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Move constructor
|
||||||
|
///
|
||||||
|
/// \param other WeakPtr to move
|
||||||
|
///
|
||||||
|
/// \tparam U Type of pointer (usually doesnt need to be defined explicitly)
|
||||||
|
///
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <class U>
|
||||||
|
WeakPtr(WeakPtr<U>&& other)
|
||||||
|
: m_Ptr(static_cast<T*>(other.m_Ptr))
|
||||||
|
, m_RefCount(other.m_RefCount)
|
||||||
|
, m_RefCountRefCount(other.m_RefCountRefCount)
|
||||||
|
{
|
||||||
|
other.m_Ptr = NULL;
|
||||||
|
other.m_RefCount = NULL;
|
||||||
|
other.m_RefCountRefCount = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SCRAT_USE_CXX11_OPTIMIZATIONS
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// Copy constructor
|
/// Copy constructor
|
||||||
///
|
///
|
||||||
@ -1117,6 +1254,65 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SCRAT_USE_CXX11_OPTIMIZATIONS
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Assigns the WeakPtr
|
||||||
|
///
|
||||||
|
/// \param other WeakPtr to move
|
||||||
|
///
|
||||||
|
/// \return The WeakPtr itself
|
||||||
|
///
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
WeakPtr<T>& operator=(WeakPtr<T>&& other)
|
||||||
|
{
|
||||||
|
if (m_Ptr != other.m_Ptr)
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
|
||||||
|
m_Ptr = other.m_Ptr;
|
||||||
|
m_RefCount = other.m_RefCount;
|
||||||
|
m_RefCountRefCount = other.m_RefCountRefCount;
|
||||||
|
|
||||||
|
other.m_Ptr = NULL;
|
||||||
|
other.m_RefCount = NULL;
|
||||||
|
other.m_RefCountRefCount = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// Assigns the WeakPtr
|
||||||
|
///
|
||||||
|
/// \param other WeakPtr to move
|
||||||
|
///
|
||||||
|
/// \tparam U Type of pointer (usually doesnt need to be defined explicitly)
|
||||||
|
///
|
||||||
|
/// \return The WeakPtr itself
|
||||||
|
///
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <class U>
|
||||||
|
WeakPtr<T>& operator=(WeakPtr<U>&& other)
|
||||||
|
{
|
||||||
|
if (m_Ptr != static_cast<T*>(other.m_Ptr))
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
|
||||||
|
m_Ptr = static_cast<T*>(other.m_Ptr);
|
||||||
|
m_RefCount = other.m_RefCount;
|
||||||
|
m_RefCountRefCount = other.m_RefCountRefCount;
|
||||||
|
|
||||||
|
other.m_Ptr = NULL;
|
||||||
|
other.m_RefCount = NULL;
|
||||||
|
other.m_RefCountRefCount = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SCRAT_USE_CXX11_OPTIMIZATIONS
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// Assigns the WeakPtr
|
/// Assigns the WeakPtr
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user