12 #ifndef COUNTEDPTR_HPP 13 #define COUNTEDPTR_HPP 26 template <
class Tcls_>
59 if (m_pT != NULL) m_pT->AddRef();
88 inline operator const Tcls*()
const 95 inline operator Tcls*()
103 assert(m_pT == NULL);
122 inline void Assign(Tcls *pT);
152 template <
class Tcls_>
157 if (pT != NULL) pT->AddRef();
160 if (pTold != NULL) pTold->Release();
191 operator const T& ()
const 218 virtual void FinalRelease() {};
CCountedPtr(Tcls *pObj=NULL)
default (NULL) construct or construct from a raw pointer
~CCountedPtr()
destructor releasing the reference
Tcls * m_pT
here we hold our pointer to the target
Tcls ** operator &()
operator & to support output arguments
AdaptT(const T &t)
construct by wrapping the given object
const Tcls * operator->() const
dereference of smart pointer - const way
void Assign(Tcls *pT)
assignment operator helper
bool IsNull() const
one way how to test for NULL value
Tcls * operator->()
dereference of smart pointer - non const way
void Release()
release smart pointer (and decrement ref count) if not null
CCountedPtr(const CCountedPtr &src)
copy constructor (invoked also when initializing from another smart ptr)
void AddRef()
add one ref to the underlaying object
CCountedPtr & operator=(const CCountedPtr &src)
assignment operator from another smart ptr
Tcls_ Tcls
redefine the template argument to make it visible for derived classes
Adapter wrapper for CCountedPtr like classes that can't be used directly by stl collections as item t...
void Attach(Tcls *pT)
another way how to test for NULL value
CCountedPtr & operator=(Tcls *pT)
assignment operator from raw ptr
Tcls * Detach()
detach pointer w/o decrementing ref count
CCountedPtr - simple reference counting smart pointer.