rcolyer.net
RC Lib  Version 201607061602
Public Member Functions | List of all members
RC::APtr< T > Class Template Reference

A reference counting ptr that auto-deletes what it points to when the last copy leaves scope or is otherwise destructed. More...

#include <APtr.h>

Public Member Functions

 APtr (T *t_ptr=NULL)
 Default constructor assigning the value of the pointer. More...
 
 APtr (const APtr< T > &other)
 Copy constructor. More...
 
template<class Tderived >
 APtr (const Ptr< Tderived > &other)
 A conversion constructor which creates a new APtr from a Ptr of the same or a derived type. More...
 
APtroperator= (const APtr< T > &other)
 An assignment operator, which increases the shared reference count with the source APtr. More...
 
 ~APtr ()
 Destructor which decreases the shared reference count. More...
 
void Delete ()
 Delete the object pointed to and set the shared pointer for all linked APtr's to NULL. More...
 
T * Raw () const
 Returns a direct reference to the enclosed pointer. More...
 
void Assert () const
 Throws RC::ErrorMsgNull if the pointer is null.
 
bool IsSet () const
 True if the pointer is non-NULL. More...
 
bool IsNull () const
 True if the pointer is NULL. More...
 
T & operator* ()
 Dereferences the pointer, or throws an exception if null. More...
 
const T & operator* () const
 Const version of operator*()
 
T * operator-> ()
 Provides access to the enclosed pointer, or throws RC::ErrorMsgNull if null. More...
 
const T * operator-> () const
 Const version of operator->()
 
 operator T * () const
 Implicitly casts to the enclosed pointer, without null checking.
 
template<class Type >
Ptr< Type > Cast ()
 Dynamically casts to an RC::Ptr of the type used as a template parameter on this function. More...
 
template<class Type >
const Ptr< Type > Cast () const
 Const version of Cast()
 
template<class Type >
bool CanCast () const
 True if it can dynamically cast to this type.
 
template<class Type >
Type & As ()
 Dynamically casts and dereferences to the type presented as a template parameter, or throws ErrorMsgCast if it fails.
 
template<class Type >
const Type & As () const
 Const version of As()
 
T & As ()
 Dereference as the default type. More...
 
const T & As () const
 Const version of operator*()
 

Detailed Description

template<class T>
class RC::APtr< T >

A reference counting ptr that auto-deletes what it points to when the last copy leaves scope or is otherwise destructed.

Use this for scope-controlled garbage collection. Like Ptr, dereferencing a null APtr throws ErrorMsgNull. For C++11 the reference counting is thread safe.

See also
Ptr
RevPtr

Constructor & Destructor Documentation

template<class T>
RC::APtr< T >::APtr ( T *  t_ptr = NULL)
inline

Default constructor assigning the value of the pointer.

Parameters
t_ptrThe new pointer value.
template<class T>
RC::APtr< T >::APtr ( const APtr< T > &  other)
inline

Copy constructor.

Parameters
otherThe APtr to copy.
template<class T>
template<class Tderived >
RC::APtr< T >::APtr ( const Ptr< Tderived > &  other)
inline

A conversion constructor which creates a new APtr from a Ptr of the same or a derived type.

Parameters
otherThe Ptr from which the pointer should be used to make this APtr.
template<class T>
RC::APtr< T >::~APtr ( )
inline

Destructor which decreases the shared reference count.

The object is deleted if the shared reference count reaches 0.

Member Function Documentation

template<class T>
T& RC::APtr< T >::As ( )
inline

Dereference as the default type.

See also
operator()
template<class T>
template<class Type >
Ptr<Type> RC::APtr< T >::Cast ( )
inline

Dynamically casts to an RC::Ptr of the type used as a template parameter on this function.

The Ptr is NULL if the cast fails.

template<class T>
void RC::APtr< T >::Delete ( )
inline

Delete the object pointed to and set the shared pointer for all linked APtr's to NULL.

Note: While this NULLs all the linked APtr's, it cannot affect raw pointers which have already been extracted or are in use when this is called. Be mindful of this in threading architecture design.

template<class T>
bool RC::APtr< T >::IsNull ( ) const
inline

True if the pointer is NULL.

Returns
True if the pointer is NULL.
template<class T>
bool RC::APtr< T >::IsSet ( ) const
inline

True if the pointer is non-NULL.

Returns
True if the pointer is non-NULL.
template<class T>
T& RC::APtr< T >::operator* ( )
inline

Dereferences the pointer, or throws an exception if null.

The exception thrown is RC::ErrorMsgNull.

Returns
A reference to the dereferenced object.
template<class T>
T* RC::APtr< T >::operator-> ( )
inline

Provides access to the enclosed pointer, or throws RC::ErrorMsgNull if null.

Returns
The enclosed pointer.
template<class T>
APtr& RC::APtr< T >::operator= ( const APtr< T > &  other)
inline

An assignment operator, which increases the shared reference count with the source APtr.

Parameters
otherThe source APtr to assign here.
template<class T>
T* RC::APtr< T >::Raw ( ) const
inline

Returns a direct reference to the enclosed pointer.

The reference is read/write, so it can be used as a function parameter which updates the value of this pointer.

Returns
A reference to the enclosed pointer.

The documentation for this class was generated from the following file:
email address
— (c) 2015