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

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

Protected Member Functions

FORCEINLINE void AddRef ()
 add one ref to the underlaying 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 19 of file countedptr.hpp.


Member Function Documentation

template<class Tcls_>
FORCEINLINE void CCountedPtr< Tcls_ >::Attach ( Tcls pT  )  [inline]

another way how to test for NULL value

yet another way how to test for NULL value assign pointer w/o incrementing ref count

Definition at line 80 of file countedptr.hpp.

References CCountedPtr< Tcls_ >::m_pT, and CCountedPtr< Tcls_ >::Release().


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

Generated on Wed Apr 1 14:38:34 2009 for OpenTTD by  doxygen 1.5.6