Regina Calculation Engine
|
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... | |
A reference counted smart pointer that supports alternate models of ownership.
Specifically, there are two models of ownership for the pointee (of type T):
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:
SafePointeeBase<T>
.bool hasOwner()
, which returns true
if and only if some other C++ object (which is not a SafePtr) owns the pointee.Destruction works as follows:
delete
on a raw pointer to an object of type T, unless you know (e.g., from human analysis of the program logic) that no SafePtr points to that same object.delete
, which are always safe to call regardless of whether there are SafePtr or not. For example, users should always delete packets by calling Packet::safeDelete(), not delete
.false
.