OpenTTD Source  20240919-master-gdf0233f4c2
CCountedPtr< Tcls_ > Class Template Reference

CCountedPtr - simple reference counting smart pointer. More...

#include <countedptr.hpp>

Public Types

typedef Tcls_ Tcls
 redefine the template argument to make it visible for derived classes
 

Public Member Functions

 CCountedPtr (Tcls *pObj=nullptr)
 default (nullptr) construct or construct from a raw pointer
 
 CCountedPtr (const CCountedPtr &src)
 copy constructor (invoked also when initializing from another smart ptr)
 
 ~CCountedPtr ()
 destructor releasing the reference
 
void Release ()
 release smart pointer (and decrement ref count) if not null
 
const Tclsoperator-> () const
 dereference of smart pointer - const way
 
Tclsoperator-> ()
 dereference of smart pointer - non const way
 
 operator const Tcls * () const
 raw pointer casting operator - const way
 
 operator Tcls * ()
 raw pointer casting operator - non-const way
 
Tcls ** operator& ()
 operator & to support output arguments
 
CCountedPtroperator= (Tcls *pT)
 assignment operator from raw ptr
 
CCountedPtroperator= (const CCountedPtr &src)
 assignment operator from another smart ptr
 
void Assign (Tcls *pT)
 assignment operator helper
 
bool IsNull () const
 one way how to test for nullptr value
 
void Attach (Tcls *pT)
 assign pointer w/o incrementing ref count
 
TclsDetach ()
 detach pointer w/o decrementing ref count
 

Protected Member Functions

void AddRef ()
 add one ref to the underlying object
 

Protected Attributes

Tclsm_pT
 here we hold our pointer to the target
 

Detailed Description

template<class Tcls_>
class CCountedPtr< Tcls_ >

CCountedPtr - simple reference counting smart pointer.

One of the standard ways how to maintain object's lifetime.

See http://ootips.org/yonat/4dev/smart-pointers.html for more

general info about smart pointers.

This class implements ref-counted pointer for objects/interfaces that support AddRef() and Release() methods.

Definition at line 25 of file countedptr.hpp.


The documentation for this class was generated from the following file: