Regina Calculation Engine
Public Types | Public Member Functions | List of all members
regina::SafePtr< T > Class Template Reference

A reference counted smart pointer that supports alternate models of ownership. More...

#include <utilities/safeptr.h>

Public Types

typedef T element_type
 The pointee type. More...
 

Public Member Functions

 SafePtr (T *object)
 Constructs a new safe pointer that points to the given object. More...
 
template<class Y >
 SafePtr (const SafePtr< Y > &other)
 Copy constructor. More...
 
T * get () const
 Returns a raw pointer to the pointee, or null if the pointee has already been destroyed. More...
 

Detailed Description

template<class T>
class regina::SafePtr< T >

A reference counted smart pointer that supports alternate models of ownership.

Specifically, there are two models of ownership for the pointee (of type T):

  1. The pointee may be owned by the smart pointer(s), in which case it will be destroyed when the last smart pointer to it is destroyed.
  2. Alternatively, the pointee may be owned by some other C++ object not using this smart pointer class. In this case, even when the last smart point to it is destroyed, the pointee itself will not be destroyed.

The pointee can indicate at runtime which model of ownership is in effect, through the return value of the function T::hasOwner().

The requirements for the pointee type T are as follows:

Destruction works as follows:

Under the hood, SafePtr uses SafeRemnant to achieve this.

Author
Matthias Goerner

Member Typedef Documentation

§ element_type

template<class T >
typedef T regina::SafePtr< T >::element_type

The pointee type.

This typedef is used by the boost infrastructure.

Constructor & Destructor Documentation

§ SafePtr() [1/2]

template<class T >
regina::SafePtr< T >::SafePtr ( T *  object)
inline

Constructs a new safe pointer that points to the given object.

Parameters
objectthe pointee. This may be null.

§ SafePtr() [2/2]

template<class T >
template<class Y >
regina::SafePtr< T >::SafePtr ( const SafePtr< Y > &  other)
inline

Copy constructor.

This constructor can also be used to cast a SafePtr for a derived class Y to a SafePtr for a base class T.

Precondition
the class T (whose constructor is called) is a base class of Y.
Parameters
otherthe pointer to copy.

Member Function Documentation

§ get()

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

Returns a raw pointer to the pointee, or null if the pointee has already been destroyed.

Returns
the pointee.

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

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).