The Pedigree Project  0.1
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
SharedPointer< T > Class Template Reference

#include <SharedPointer.h>

+ Inheritance diagram for SharedPointer< T >:
+ Collaboration diagram for SharedPointer< T >:

Classes

struct  Control
 

Public Member Functions

 SharedPointer ()
 
 SharedPointer (T *ptr)
 
 SharedPointer (SharedPointer< T > &&other)
 
virtual ~SharedPointer ()
 
 SharedPointer (const SharedPointer< T > &p)
 
void reset ()
 
void reset (T *ptr)
 
T * get () const
 
T * operator-> () const
 
T & operator* () const
 
SharedPointer< T > & operator= (const SharedPointer< T > &p)
 
SharedPointer< T > & operator= (SharedPointer< T > &&p)
 
 operator bool () const
 
bool unique () const
 
size_t refcount () const
 
bool operator== (const SharedPointer &p) const
 
bool operator!= (const SharedPointer &p) const
 
bool operator< (const SharedPointer &p) const
 
bool operator<= (const SharedPointer &p) const
 
bool operator> (const SharedPointer &p) const
 
bool operator>= (const SharedPointer &p) const
 

Static Public Member Functions

template<class... Args>
static SharedPointer< T > allocate (Args...)
 

Private Member Functions

void release ()
 

Private Attributes

struct SharedPointer::Controlm_Control
 

Detailed Description

template<class T>
class SharedPointer< T >

Provides a reference-counted pointer that can be freely shared, and is automatically destroyed when the last owner's instance is destructed.

Definition at line 31 of file SharedPointer.h.

Constructor & Destructor Documentation

template<class T >
SharedPointer< T >::SharedPointer ( )

Default instantiation, without an associated pointer object.

Definition at line 147 of file SharedPointer.h.

template<class T>
SharedPointer< T >::SharedPointer ( T *  ptr)

Instantiate, owning the given memory region.

Definition at line 152 of file SharedPointer.h.

References SharedPointer< T >::reset().

template<class T>
SharedPointer< T >::SharedPointer ( SharedPointer< T > &&  other)

Move into the given SharedPointer object (no refcount increase). When moving out of a SharedPointer, the previous instance becomes invalid and must be re-initialized.

Definition at line 158 of file SharedPointer.h.

template<class T >
SharedPointer< T >::~SharedPointer ( )
virtual

Destruction, which automatically frees the pointer if no owners remain.

Definition at line 166 of file SharedPointer.h.

References SharedPointer< T >::release().

template<class T>
SharedPointer< T >::SharedPointer ( const SharedPointer< T > &  p)

Create another reference to the given SharedPointer.

Definition at line 172 of file SharedPointer.h.

References SharedPointer< T >::release().

Member Function Documentation

template<class T >
template<class... Args>
SharedPointer< T > SharedPointer< T >::allocate ( Args...  args)
static

Creates a SharedPointer with a default allocation.

Definition at line 273 of file SharedPointer.h.

References SharedPointer< T >::reset().

Referenced by Thread::detach(), and SymbolTable::getOrInsertTree().

+ Here is the caller graph for this function:

template<class T >
T * SharedPointer< T >::get ( ) const

Retrieve the internal pointer, or null if no object is held.

Definition at line 201 of file SharedPointer.h.

Referenced by SharedPointer< T >::operator==().

+ Here is the caller graph for this function:

template<class T >
SharedPointer< T >::operator bool ( ) const
explicit

Whether or not this pointer is valid.

Definition at line 251 of file SharedPointer.h.

template<class T >
T & SharedPointer< T >::operator* ( ) const

Dereference the internal pointer (dangerous if no object held).

Definition at line 216 of file SharedPointer.h.

template<class T >
T * SharedPointer< T >::operator-> ( ) const

Dereference the internal pointer (null if no object is held).

Definition at line 210 of file SharedPointer.h.

template<class T>
SharedPointer< T > & SharedPointer< T >::operator= ( const SharedPointer< T > &  p)

Release any currently held object, and then reference that held by the given SharedPointer.

Definition at line 222 of file SharedPointer.h.

References SharedPointer< T >::release().

template<class T>
SharedPointer< T > & SharedPointer< T >::operator= ( SharedPointer< T > &&  p)

Move the other SharedPointer instance into this one.

Definition at line 241 of file SharedPointer.h.

References SharedPointer< T >::release().

template<class T >
bool SharedPointer< T >::operator== ( const SharedPointer< T > &  p) const
Note
No operator is provided for comparison with raw pointer types: if that comparison were to ever succeed, it would indicate that the SharedPointer could not safely free memory after the refcount falls to zero.

Definition at line 302 of file SharedPointer.h.

References SharedPointer< T >::get().

template<class T >
size_t SharedPointer< T >::refcount ( ) const

Indicates this SharedPointer's current reference count.

Definition at line 263 of file SharedPointer.h.

Referenced by SharedPointer< T >::unique().

+ Here is the caller graph for this function:

template<class T >
void SharedPointer< T >::release ( )
private

Internal do-er to release a reference to the held object.

Todo:
allow specifying a custom function to handle deletion

Definition at line 281 of file SharedPointer.h.

Referenced by SharedPointer< T >::operator=(), SharedPointer< T >::reset(), SharedPointer< T >::SharedPointer(), and SharedPointer< T >::~SharedPointer().

+ Here is the caller graph for this function:

template<class T >
void SharedPointer< T >::reset ( )

Reset this SharedPointer, reducing the refcount on any held object.

Definition at line 185 of file SharedPointer.h.

References SharedPointer< T >::release().

Referenced by SharedPointer< T >::allocate(), Thread::cleanStateLevel(), and SharedPointer< T >::SharedPointer().

+ Here is the caller graph for this function:

template<class T>
void SharedPointer< T >::reset ( T *  ptr)

Reset this SharedPointer, reducing the refcount on any held object, and then set this SharedPointer to track the given memory.

Definition at line 191 of file SharedPointer.h.

References SharedPointer< T >::release().

template<class T >
bool SharedPointer< T >::unique ( ) const

Indicates whether this SharedPointer is only held by one owner.

Definition at line 257 of file SharedPointer.h.

References SharedPointer< T >::refcount().


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