/** @brief Reference counting class for the shared_ptr implementation */
classcount
{
public:
count(unsignedintval):val_(val){}
voiddec(){--val_;}
voidinc(){++val_;}
boolis_null(){returnval_==0;}
unsignedintval(){returnval_;}
private:
unsignedintval_;
};
/** @brief Interface for the reference counter inside the shared_ptr */
structaux
{
detail::countcount;
aux():count(1){}
virtualvoiddestroy()=0;
virtual~aux(){}
};
/** @brief Implementation helper for the reference counting mechanism inside shared_ptr. */
template<classU,classDeleter>
structauximpl:publicdetail::aux
{
U*p;
Deleterd;
auximpl(U*pu,Deleterx):p(pu),d(x){}
virtualvoiddestroy(){d(p);}
};
/** @brief Default deleter class for a pointer. The default is to just call 'delete' on the pointer. Provide your own implementations for 'delete[]' and 'free'. */
template<classU>
structdefault_deleter
{
voidoperator()(U*p)const{deletep;}
};
}
classshared_ptr_base
{
protected:
detail::aux*pa;
public:
unsignedintcount(){returnpa->count.val();}
};
/** @brief A shared pointer class similar to boost::shared_ptr. Reimplemented in order to avoid a Boost-dependency. Will be replaced by tools::shared_ptr as soon as C++11 is widely available. */