Regina Calculation Engine
Public Member Functions | Static Public Member Functions | List of all members
regina::detail::SafeRemnant< T > Class Template Reference

A helper class for SafePtr. More...

#include <utilities/saferemnant.h>

Inheritance diagram for regina::detail::SafeRemnant< T >:

Public Member Functions

 ~SafeRemnant ()
 Destroys this remnant. More...
 
T * get () const
 Dereference this remnant. More...
 
void expire ()
 Expire the remnant so that it can no longer be dereferenced. More...
 

Static Public Member Functions

static SafeRemnant< T > * getOrCreate (T *object)
 Given an object deriving from SafePointeeBase, find or create the remnant corresponding to the object. More...
 

Detailed Description

template<class T>
class regina::detail::SafeRemnant< T >

A helper class for SafePtr.

The dereferencing of a SafePtr is indirected through this class, i.e., SafePtr is pointing to this class, which is pointing to the pointee. The pointee in turn derives from SafePointeeBase.

Each remnant is associated with at most one pointee, and each pointee is associated with at most one remnant. However, both relationships are optional:

The lifetime of a remnant is tied to the existence of SafePtr objects that point to it (through reference counting), not to that of the corresponding pointee.

Template Parameters
Tthe pointee type. This must derive from SafePointeeBase<T>.
Author
Matthias Goerner

Constructor & Destructor Documentation

◆ ~SafeRemnant()

template<class T >
regina::detail::SafeRemnant< T >::~SafeRemnant ( )

Destroys this remnant.

If the remnant is associated with a pointee, then:

  • if no other C++ object claims ownership of the pointee (as determined by T::hasOwner()), then the pointee will be deleted;
  • if some other C++ object does claim ownership of the pointee then the pointee will be left intact, but its reference to this remnant will be cleared.

Member Function Documentation

◆ expire()

template<class T >
void regina::detail::SafeRemnant< T >::expire ( )
inline

Expire the remnant so that it can no longer be dereferenced.

Any subsequent call to get() will return 0.

This routine is called by the pointee's destructor.

◆ get()

template<class T >
T * regina::detail::SafeRemnant< T >::get ( ) const
inline

Dereference this remnant.

Returns
the pointee corresponding to this remnant, or 0 if the original pointee has since been destroyed.

◆ getOrCreate()

template<class T>
SafeRemnant< T > * regina::detail::SafeRemnant< T >::getOrCreate ( T *  object)
static

Given an object deriving from SafePointeeBase, find or create the remnant corresponding to the object.

Each pointee object has at most one remnant. If it already exists, this routine returns it. If not, this routine creates a new one.

Parameters
objectthe object deriving from SafePointeeBase.
Returns
the corresponding remnant.

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

Copyright © 1999-2016, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@maths.uq.edu.au).