Make PycRef<T> movable
This commit is contained in:
22
pyc_object.h
22
pyc_object.h
@@ -6,20 +6,25 @@
|
|||||||
template <class _Obj>
|
template <class _Obj>
|
||||||
class PycRef {
|
class PycRef {
|
||||||
public:
|
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)
|
if (m_obj)
|
||||||
m_obj->addRef();
|
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)
|
if (m_obj)
|
||||||
m_obj->addRef();
|
m_obj->addRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PycRef(PycRef<_Obj>&& obj) noexcept : m_obj(obj.m_obj)
|
||||||
|
{
|
||||||
|
obj.m_obj = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
~PycRef<_Obj>()
|
~PycRef<_Obj>()
|
||||||
{
|
{
|
||||||
if (m_obj)
|
if (m_obj)
|
||||||
@@ -46,6 +51,13 @@ public:
|
|||||||
return *this;
|
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==(_Obj* obj) const { return m_obj == obj; }
|
||||||
bool operator==(const PycRef<_Obj>& obj) const { return m_obj == obj.m_obj; }
|
bool operator==(const PycRef<_Obj>& obj) const { return m_obj == obj.m_obj; }
|
||||||
bool operator!=(_Obj* obj) const { return m_obj != obj; }
|
bool operator!=(_Obj* obj) const { return m_obj != obj; }
|
||||||
@@ -140,7 +152,9 @@ public:
|
|||||||
|
|
||||||
template <class _Obj>
|
template <class _Obj>
|
||||||
int PycRef<_Obj>::type() const
|
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> CreateObject(int type);
|
||||||
PycRef<PycObject> LoadObject(PycData* stream, PycModule* mod);
|
PycRef<PycObject> LoadObject(PycData* stream, PycModule* mod);
|
||||||
|
Reference in New Issue
Block a user