rcolyer.net
RC Lib  Version 202403231100
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. More...
 
void AutoRevoke (bool new_auto_revoke=true)
 Set this RevPtr to revoke the pointer upon deletion or leaving scope. More...
 

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

◆ RevPtr() [1/4]

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.

◆ RevPtr() [2/4]

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

Copy constructor.

Parameters
otherThe RevPtr to copy.

◆ RevPtr() [3/4]

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

◆ RevPtr() [4/4]

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

◆ AutoRevoke()

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.

◆ Delete()

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.

◆ operator=()

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.

◆ Revoke()

template<class T >
void RC::RevPtr< T >::Revoke ( )
inline

Manually revoke the pointer, setting it equal to NULL for all shared RevPtr objects.

This does not delete the pointer.


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