12 #ifndef COUNTEDPTR_HPP 13 #define COUNTEDPTR_HPP 26 template <
class Tcls_>
59 if (m_pT !=
nullptr) m_pT->AddRef();
66 if (m_pT !=
nullptr) {
76 assert(m_pT !=
nullptr);
83 assert(m_pT !=
nullptr);
88 inline operator const Tcls*()
const 90 assert(m_pT ==
nullptr);
95 inline operator Tcls*()
103 assert(m_pT ==
nullptr);
122 inline void Assign(Tcls *pT);
127 return m_pT ==
nullptr;
152 template <
class Tcls_>
157 if (pT !=
nullptr) pT->AddRef();
160 if (pTold !=
nullptr) pTold->Release();
191 operator const T& ()
const 218 virtual void FinalRelease() {};
~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 nullptr 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 underlying 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 nullptr value
CCountedPtr & operator=(Tcls *pT)
assignment operator from raw ptr
Tcls * Detach()
detach pointer w/o decrementing ref count
CCountedPtr(Tcls *pObj=nullptr)
default (nullptr) construct or construct from a raw pointer
CCountedPtr - simple reference counting smart pointer.