rcolyer.net
RC Lib  Version 202403231100
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...
 
APtr< const T > ExtractConst ()
 Extract APtr<const T> and revokes ownership from this object.
 

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

◆ APtr() [1/3]

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.

◆ APtr() [2/3]

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

Copy constructor.

Parameters
otherThe APtr to copy.

◆ APtr() [3/3]

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.

◆ ~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

◆ Delete()

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.

◆ operator=()

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.

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