Make PycRef<T> movable

This commit is contained in:
Michael Hansen
2019-10-08 08:42:33 -07:00
parent 44af6a2c04
commit 66d6c190ac

View File

@@ -6,20 +6,25 @@
template <class _Obj>
class PycRef {
public:
PycRef() : m_obj(0) { }
PycRef() noexcept : m_obj() { }
PycRef(_Obj* obj) : m_obj(obj)
PycRef(_Obj* obj) noexcept : m_obj(obj)
{
if (m_obj)
m_obj->addRef();
}
PycRef(const PycRef<_Obj>& obj) : m_obj(obj.m_obj)
PycRef(const PycRef<_Obj>& obj) noexcept : m_obj(obj.m_obj)
{
if (m_obj)
m_obj->addRef();
}
PycRef(PycRef<_Obj>&& obj) noexcept : m_obj(obj.m_obj)
{
obj.m_obj = nullptr;
}
~PycRef<_Obj>()
{
if (m_obj)
@@ -46,6 +51,13 @@ public:
return *this;
}
PycRef<_Obj>& operator=(PycRef<_Obj>&& obj) noexcept
{
m_obj = obj.m_obj;
obj.m_obj = nullptr;
return *this;
}
bool operator==(_Obj* obj) const { return m_obj == obj; }
bool operator==(const PycRef<_Obj>& obj) const { return m_obj == obj.m_obj; }
bool operator!=(_Obj* obj) const { return m_obj != obj; }
@@ -140,7 +152,9 @@ public:
template <class _Obj>
int PycRef<_Obj>::type() const
{ return m_obj ? m_obj->type() : PycObject::TYPE_NULL; }
{
return m_obj ? m_obj->type() : PycObject::TYPE_NULL;
}
PycRef<PycObject> CreateObject(int type);
PycRef<PycObject> LoadObject(PycData* stream, PycModule* mod);