优化弱引用指针
This commit is contained in:
parent
8af871ed18
commit
4d82f76a4c
@ -33,6 +33,47 @@ CreatureWeakPtr::CreatureWeakPtr()
|
||||
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()
|
||||
{
|
||||
Reset();
|
||||
|
@ -22,6 +22,10 @@ class CreatureWeakPtr
|
||||
public:
|
||||
|
||||
CreatureWeakPtr();
|
||||
CreatureWeakPtr(const CreatureWeakPtr& x);
|
||||
CreatureWeakPtr(CreatureWeakPtr&& x);
|
||||
CreatureWeakPtr& operator=(const CreatureWeakPtr& x);
|
||||
CreatureWeakPtr&& operator=(CreatureWeakPtr&& x);
|
||||
~CreatureWeakPtr();
|
||||
void Reset();
|
||||
Creature* Get();
|
||||
|
Loading…
x
Reference in New Issue
Block a user