OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
10 #ifndef COUNTEDPTR_HPP
11 #define COUNTEDPTR_HPP
24 template <
class Tcls_>
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);
101 assert(
m_pT ==
nullptr);
125 return m_pT ==
nullptr;
144 template <
class Tcls_>
149 if (pT !=
nullptr) pT->AddRef();
152 if (pTold !=
nullptr) pTold->Release();
183 operator const T& ()
const
208 virtual int32_t AddRef();
209 virtual int32_t Release();
210 virtual void FinalRelease() {};
Adapter wrapper for CCountedPtr like classes that can't be used directly by stl collections as item t...
Tcls * m_pT
here we hold our pointer to the target
void Assign(Tcls *pT)
assignment operator helper
Tcls * operator->()
dereference of smart pointer - non const way
void Release()
release smart pointer (and decrement ref count) if not null
bool IsNull() const
one way how to test for nullptr value
const Tcls * operator->() const
dereference of smart pointer - const way
T & operator=(const T &t)
assignment operator
CCountedPtr(const CCountedPtr &src)
copy constructor (invoked also when initializing from another smart ptr)
AdaptT(const T &t)
construct by wrapping the given object
CCountedPtr & operator=(Tcls *pT)
assignment operator from raw ptr
CCountedPtr & operator=(const CCountedPtr &src)
assignment operator from another smart ptr
void Attach(Tcls *pT)
assign pointer w/o incrementing ref count
void AddRef()
add one ref to the underlying object
Tcls_ Tcls
redefine the template argument to make it visible for derived classes
CCountedPtr - simple reference counting smart pointer.
Tcls * Detach()
detach pointer w/o decrementing ref count
Tcls ** operator&()
operator & to support output arguments
~CCountedPtr()
destructor releasing the reference
CCountedPtr(Tcls *pObj=nullptr)
default (nullptr) construct or construct from a raw pointer