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 ()
 Constructs a new null pointer. More...
 
 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. More...
 
 operator bool () const
 Returns true if the pointee is non-null. More...
 
void reset (T *object=nullptr)
 Resets this to point to the given object. More...
 
SafePtr< T > & operator= (const SafePtr< T > &)=delete
 Disable the default assignment operator. 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 pointer 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:

Author
Matthias Goerner

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

Copyright © 1999-2018, 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).