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

A reference counting pointer that revokes (NULLs) all copies when one set to AutoRevoke(true) leaves scope. More...

#include <RevPtr.h>

Public Member Functions

 RevPtr (T *t_ptr=NULL)
 Default constructor assigning the value of the pointer. More...
 
 RevPtr (const RevPtr< T > &other)
 Copy constructor. More...
 
 RevPtr (const Ptr< T > &other)
 A conversion constructor which creates a new RevPtr from a Ptr of the same or a derived type. More...
 
 RevPtr (const APtr< T > &other)
 A conversion constructor which creates a new RevPtr from an APtr of the same or a derived type. More...
 
RevPtroperator= (const RevPtr< T > &other)
 An assignment operator which joins this RevPtr to the other RevPtr. More...
 
 ~RevPtr ()
 Destructor which revokes the pointer only if AutoRevoke() was used on this object.
 
void Delete ()
 Manually delete the object pointed to by this RevPtr, and revoke the pointer for all shared RevPtr's. More...
 
void Revoke ()
 Manually revoke the pointer, setting it equal to NULL for all shared RevPtr objects.
 
void AutoRevoke (bool new_auto_revoke=true)
 Set this RevPtr to revoke the pointer upon deletion or leaving scope. 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::RevPtr< T >

A reference counting pointer that revokes (NULLs) all copies when one set to AutoRevoke(true) leaves scope.

This pointer class does not automatically delete the object pointed to, so that it can be used for self-referential purposes. For automatic deletion, use an APtr, and create a RevPtr family that refers to the Ptr of the same scope. Like Ptr and APtr, dereferencing a null RevPtr throws ErrorMsgNull. Note: Revocation is thread safe, but a previously extracted raw ptr could remain in use after revocation. Be mindful of this in threading architecture design.

See also
Ptr
APtr

Constructor & Destructor Documentation

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

Default constructor assigning the value of the pointer.

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

Copy constructor.

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

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

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

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

Parameters
otherThe APtr from which the pointer should be used to make this RevPtr

Member Function Documentation

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

Dereference as the default type.

See also
operator()
template<class T>
void RC::RevPtr< T >::AutoRevoke ( bool  new_auto_revoke = true)
inline

Set this RevPtr to revoke the pointer upon deletion or leaving scope.

Parameters
new_auto_revokeTrue if this RevPtr should automatically revoke. The recommended way to use this feature is to place the primary RevPtr in scope with the object to which it points so that they are deleted together, and then call AutoRevoke() on that RevPtr. Then all other RevPtr's which have been assigned or copy constructed from the primary RevPtr will be automatically revoked when it is destructed, and they will all return true for IsNull or throw exceptions if dereferencing is attempted.
template<class T>
template<class Type >
Ptr<Type> RC::RevPtr< 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::RevPtr< T >::Delete ( )
inline

Manually delete the object pointed to by this RevPtr, and revoke the pointer for all shared RevPtr's.

Note: While this NULLs all the linked RevPtr'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::RevPtr< T >::IsNull ( ) const
inline

True if the pointer is NULL.

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

True if the pointer is non-NULL.

Returns
True if the pointer is non-NULL.
template<class T>
T& RC::RevPtr< 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::RevPtr< T >::operator-> ( )
inline

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

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

An assignment operator which joins this RevPtr to the other RevPtr.

Parameters
otherThe source RevPtr to assign here.
template<class T>
T* RC::RevPtr< 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