10 #ifndef COUNTEDPTR_HPP 11 #define COUNTEDPTR_HPP 24 template <
class Tcls_>
57 if (m_pT !=
nullptr) m_pT->AddRef();
64 if (m_pT !=
nullptr) {
74 assert(m_pT !=
nullptr);
81 assert(m_pT !=
nullptr);
86 inline operator const Tcls*()
const 88 assert(m_pT ==
nullptr);
93 inline operator Tcls*()
101 assert(m_pT ==
nullptr);
120 inline void Assign(Tcls *pT);
125 return m_pT ==
nullptr;
150 template <
class Tcls_>
155 if (pT !=
nullptr) pT->AddRef();
158 if (pTold !=
nullptr) pTold->Release();
189 operator const T& ()
const 216 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.