优化弱引用指针
This commit is contained in:
parent
8af871ed18
commit
4d82f76a4c
@ -33,6 +33,47 @@ CreatureWeakPtr::CreatureWeakPtr()
|
|||||||
INIT_LIST_HEAD(&entry_);
|
INIT_LIST_HEAD(&entry_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CreatureWeakPtr::CreatureWeakPtr(const CreatureWeakPtr& x)
|
||||||
|
{
|
||||||
|
INIT_LIST_HEAD(&entry_);
|
||||||
|
if (x.ptr_) {
|
||||||
|
Attach(x.ptr_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CreatureWeakPtr::CreatureWeakPtr(CreatureWeakPtr&& x)
|
||||||
|
{
|
||||||
|
INIT_LIST_HEAD(&entry_);
|
||||||
|
if (x.ptr_) {
|
||||||
|
Attach(x.ptr_);
|
||||||
|
x.Detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CreatureWeakPtr& CreatureWeakPtr::operator=(const CreatureWeakPtr& x)
|
||||||
|
{
|
||||||
|
if (ptr_) {
|
||||||
|
Detach();
|
||||||
|
}
|
||||||
|
if (x.ptr_) {
|
||||||
|
Attach(x.ptr_);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CreatureWeakPtr&& CreatureWeakPtr::operator=(CreatureWeakPtr&& x)
|
||||||
|
{
|
||||||
|
if (ptr_) {
|
||||||
|
Detach();
|
||||||
|
}
|
||||||
|
if (x.ptr_) {
|
||||||
|
Attach(x.ptr_);
|
||||||
|
x.Detach();
|
||||||
|
}
|
||||||
|
abort();
|
||||||
|
// return *this;
|
||||||
|
}
|
||||||
|
|
||||||
CreatureWeakPtr::~CreatureWeakPtr()
|
CreatureWeakPtr::~CreatureWeakPtr()
|
||||||
{
|
{
|
||||||
Reset();
|
Reset();
|
||||||
|
@ -22,6 +22,10 @@ class CreatureWeakPtr
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
CreatureWeakPtr();
|
CreatureWeakPtr();
|
||||||
|
CreatureWeakPtr(const CreatureWeakPtr& x);
|
||||||
|
CreatureWeakPtr(CreatureWeakPtr&& x);
|
||||||
|
CreatureWeakPtr& operator=(const CreatureWeakPtr& x);
|
||||||
|
CreatureWeakPtr&& operator=(CreatureWeakPtr&& x);
|
||||||
~CreatureWeakPtr();
|
~CreatureWeakPtr();
|
||||||
void Reset();
|
void Reset();
|
||||||
Creature* Get();
|
Creature* Get();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user