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>

+ Collaboration diagram for SharedPointer< T >:

Classes

struct  Control
 

Public Member Functions

 SharedPointer ()
 
 SharedPointer (T *ptr)
 
 SharedPointer (SharedPointer< T > &&other) noexcept
 
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) noexcept
 
 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...)
 
template<class... Args>
static SharedPointer< T > tryAllocate (Args...)
 
static SharedPointer< T > tryAdopt (T *ptr)
 

Private Member Functions

void release () noexcept
 

Private Attributes

struct SharedPointer::Control * m_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

◆ SharedPointer() [1/4]

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

Default instantiation, without an associated pointer object.

Definition at line 152 of file SharedPointer.h.

◆ SharedPointer() [2/4]

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

Instantiate, owning the given memory region.

Definition at line 155 of file SharedPointer.h.

References SharedPointer< T >::reset().

◆ SharedPointer() [3/4]

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

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 160 of file SharedPointer.h.

◆ ~SharedPointer()

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

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

Definition at line 167 of file SharedPointer.h.

◆ SharedPointer() [4/4]

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.

Member Function Documentation

◆ allocate()

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

Creates a SharedPointer with a default allocation.

Definition at line 264 of file SharedPointer.h.

References SharedPointer< T >::reset().

Referenced by SymbolTable::getOrInsertTree().

+ Here is the caller graph for this function:

◆ get()

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

◆ operator bool()

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

Whether or not this pointer is valid.

Definition at line 245 of file SharedPointer.h.

◆ operator!=()

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

Definition at line 321 of file SharedPointer.h.

◆ operator*()

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

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

Definition at line 210 of file SharedPointer.h.

◆ operator->()

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

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

Definition at line 205 of file SharedPointer.h.

◆ operator<()

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

Definition at line 326 of file SharedPointer.h.

◆ operator<=()

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

Definition at line 331 of file SharedPointer.h.

◆ operator=() [1/2]

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 215 of file SharedPointer.h.

◆ operator=() [2/2]

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

Move the other SharedPointer instance into this one.

Definition at line 236 of file SharedPointer.h.

◆ operator==()

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 316 of file SharedPointer.h.

References SharedPointer< T >::get().

◆ operator>()

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

Definition at line 336 of file SharedPointer.h.

◆ operator>=()

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

Definition at line 341 of file SharedPointer.h.

◆ refcount()

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

Indicates this SharedPointer's current reference count.

Definition at line 255 of file SharedPointer.h.

◆ release()

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

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

Todo:
allow specifying a custom function to handle deletion

Definition at line 297 of file SharedPointer.h.

◆ reset() [1/2]

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

◆ reset() [2/2]

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 184 of file SharedPointer.h.

◆ tryAdopt()

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

Takes ownership, deleting ptr if its control allocation fails.

Definition at line 286 of file SharedPointer.h.

Referenced by Process::setCtty().

+ Here is the caller graph for this function:

◆ tryAllocate()

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

Returns empty if the kernel allocator cannot provide either allocation.

Definition at line 272 of file SharedPointer.h.

References SharedPointer< T >::reset().

Referenced by Process::addThread(), and VFS::syncFilesystem().

+ Here is the caller graph for this function:

◆ unique()

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

Indicates whether this SharedPointer is only held by one owner.

Definition at line 250 of file SharedPointer.h.


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