Public Member Functions | Related Functions | List of all members
aurora::CopiedPtr< T > Class Template Reference

Copyable smart pointer template. More...

Public Member Functions

 CopiedPtr ()
 Default constructor. More...
 
 CopiedPtr (std::nullptr_t)
 Construct from nullptr. More...
 
template<typename U >
 CopiedPtr (U *pointer)
 Construct from raw pointer. More...
 
template<typename U , typename C >
 CopiedPtr (U *pointer, C cloner)
 Construct from raw pointer with cloner. More...
 
template<typename U , typename C , typename D >
 CopiedPtr (U *pointer, C cloner, D deleter)
 Construct from raw pointer with cloner and deleter. More...
 
 CopiedPtr (const CopiedPtr &origin)
 Copy constructor. More...
 
template<typename U >
 CopiedPtr (const CopiedPtr< U > &origin)
 Construct from different CopiedPtr. More...
 
 CopiedPtr (CopiedPtr &&source)
 Move constructor. More...
 
template<typename U >
 CopiedPtr (CopiedPtr< U > &&source)
 Move from different CopiedPtr. More...
 
CopiedPtroperator= (const CopiedPtr &origin)
 Copy assignment operator. More...
 
template<typename U >
CopiedPtroperator= (const CopiedPtr< U > &origin)
 Copy-assign from different CopiedPtr. More...
 
CopiedPtroperator= (CopiedPtr &&source)
 Move assignment operator. More...
 
template<typename U >
CopiedPtroperator= (CopiedPtr< U > &&source)
 Move-assign from different CopiedPtr. More...
 
 ~CopiedPtr ()
 Destructor. More...
 
void swap (CopiedPtr &other)
 Exchanges the values of *this and other.
 
T & operator* () const
 Dereferences the pointer.
 
T * operator-> () const
 Dereferences the pointer for member access.
 
 operator SafeBool () const
 Checks if the smart pointer is not nullptr. More...
 
T * get () const
 Permits access to the internal pointer. Designed for rare use. More...
 
void reset ()
 Reset to null pointer. More...
 
template<typename U >
void reset (U *pointer)
 Reset to raw pointer. More...
 
template<typename U , typename C >
void reset (U *pointer, C cloner)
 Reset to raw pointer with cloner. More...
 
template<typename U , typename C , typename D >
void reset (U *pointer, C cloner, D deleter)
 Reset to raw pointer with cloner and deleter. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T >
void swap (CopiedPtr< T > &lhs, CopiedPtr< T > &rhs)
 Swaps the contents of two CopiedPtr instances.
 
template<typename T , typename... Args>
CopiedPtr< T > makeCopied (Args &&...args)
 Emplaces an object directly inside the copied pointer. More...
 

Detailed Description

template<typename T>
class aurora::CopiedPtr< T >

Copyable smart pointer template.

Template Parameters
TType of the stored pointee object. Can be void.

This class supports automatic destruction and copying. It has full value semantics, i.e. the stored object is destroyed in the smart pointer's destructor and copied in the smart pointer's copy constructor. The concept of custom cloners and deleters allows you to specify the way how destructions and copies are performed.

This smart pointer is always unique, no two CopiedPtr instances share the same object.

Every operation provides at least the strong exception guarantee: When copies of the pointee object throw an exception, the smart pointer will remain in a valid (uncommitted) state and no memory will be leaked. Move construction and move assignment from the same CopiedPtr<T> type additionally offer the nothrow guarantee; they involve neither copies nor moves of the pointee object. Operations on empty smart pointers (such as default constructor, copies/moves from null pointers) also provide the nothrow guarantee; they never involve any dynamic allocation.

Constructor & Destructor Documentation

template<typename T>
aurora::CopiedPtr< T >::CopiedPtr ( )

Default constructor.

Initializes the smart pointer with a null pointer.

template<typename T>
aurora::CopiedPtr< T >::CopiedPtr ( std::nullptr_t  )

Construct from nullptr.

Allows conversions from the nullptr literal to a CopiedPtr.

template<typename T>
template<typename U >
aurora::CopiedPtr< T >::CopiedPtr ( U *  pointer)
explicit

Construct from raw pointer.

Parameters
pointerInitial pointer value, can be nullptr. Must be convertible to T*.
template<typename T>
template<typename U , typename C >
aurora::CopiedPtr< T >::CopiedPtr ( U *  pointer,
cloner 
)

Construct from raw pointer with cloner.

Parameters
pointerInitial pointer value, can be nullptr. Must be convertible to T*.
clonerCallable with signature T*(const T*) that is invoked during CopiedPtr copies. Must return a pointer to a copy of the argument.

Uses OperatorDelete<U> as deleter. Make sure your cloner returns an object allocated with new.

template<typename T>
template<typename U , typename C , typename D >
aurora::CopiedPtr< T >::CopiedPtr ( U *  pointer,
cloner,
deleter 
)

Construct from raw pointer with cloner and deleter.

Parameters
pointerInitial pointer value, can be nullptr. Must be convertible to T*.
clonerCallable with signature T*(const T*) that is invoked during CopiedPtr copies. Must return a pointer to a copy of the argument.
deleterCallable with signature void(T*) that is invoked during CopiedPtr destruction.
template<typename T>
aurora::CopiedPtr< T >::CopiedPtr ( const CopiedPtr< T > &  origin)

Copy constructor.

Parameters
originOriginal smart pointer

If the origin's pointer is nullptr, this pointer will also be nullptr. Otherwise, this instance will hold the pointer returned by the cloner.

template<typename T>
template<typename U >
aurora::CopiedPtr< T >::CopiedPtr ( const CopiedPtr< U > &  origin)

Construct from different CopiedPtr.

Parameters
originOriginal smart pointer, where U* convertible to T*. Can refer to a derived object.

If the origin's pointer is nullptr, this pointer will also be nullptr. Otherwise, this instance will hold the pointer returned by the cloner.

template<typename T>
aurora::CopiedPtr< T >::CopiedPtr ( CopiedPtr< T > &&  source)

Move constructor.

Parameters
sourceRValue reference to object of which the ownership is taken.
template<typename T>
template<typename U >
aurora::CopiedPtr< T >::CopiedPtr ( CopiedPtr< U > &&  source)

Move from different CopiedPtr.

Parameters
sourceRValue reference to object of which the ownership is taken.

In contrast to the move constructor, this constructor does not offer the nothrow guarantee. Only strong exception guarantee is provided (because of an internal allocation; the pointee object is not copied).

template<typename T>
aurora::CopiedPtr< T >::~CopiedPtr ( )

Destructor.

Invokes the deleter with the stored pointer as argument.

Member Function Documentation

template<typename T>
T* aurora::CopiedPtr< T >::get ( ) const

Permits access to the internal pointer. Designed for rare use.

Returns
Internally used pointer, use it wisely not to upset the CopiedPtr's memory management.
template<typename T>
aurora::CopiedPtr< T >::operator SafeBool ( ) const

Checks if the smart pointer is not nullptr.

Allows expressions of the form if (ptr) or if (!ptr).

Returns
Value convertible to true, if CopiedPtr is not empty; value convertible to false otherwise
template<typename T>
CopiedPtr& aurora::CopiedPtr< T >::operator= ( const CopiedPtr< T > &  origin)

Copy assignment operator.

Parameters
originOriginal smart pointer

Can imply a copy and a destruction, invoking origin's cloner and this deleter.

template<typename T>
template<typename U >
CopiedPtr& aurora::CopiedPtr< T >::operator= ( const CopiedPtr< U > &  origin)

Copy-assign from different CopiedPtr.

Parameters
originOriginal smart pointer, where U* convertible to T*. Can refer to a derived object.

Can imply a copy and a destruction, invoking origin's cloner and this deleter.

template<typename T>
CopiedPtr& aurora::CopiedPtr< T >::operator= ( CopiedPtr< T > &&  source)

Move assignment operator.

Parameters
sourceRValue reference to object of which the ownership is taken.
template<typename T>
template<typename U >
CopiedPtr& aurora::CopiedPtr< T >::operator= ( CopiedPtr< U > &&  source)

Move-assign from different CopiedPtr.

Parameters
sourceRValue reference to object of which the ownership is taken.

In contrast to the move assignment operator, this assignment operator does not offer the nothrow guarantee. Only strong exception guarantee is provided (because of an internal allocation; the pointee object is not copied).

template<typename T>
void aurora::CopiedPtr< T >::reset ( )

Reset to null pointer.

If this instance currently holds a pointer, the old deleter is invoked.

template<typename T>
template<typename U >
void aurora::CopiedPtr< T >::reset ( U *  pointer)

Reset to raw pointer.

Parameters
pointerInitial pointer value, can be nullptr. Must be convertible to T*.

If this instance currently holds a pointer, the old deleter is invoked.

template<typename T>
template<typename U , typename C >
void aurora::CopiedPtr< T >::reset ( U *  pointer,
cloner 
)

Reset to raw pointer with cloner.

Parameters
pointerInitial pointer value, can be nullptr. Must be convertible to T*.
clonerCallable with signature T*(const T*) that is invoked during CopiedPtr copies. Must return a pointer to a copy of the argument.

If this instance currently holds a pointer, the old deleter is invoked.
Uses OperatorDelete<U> as deleter. Make sure your cloner returns an object allocated with new.

template<typename T>
template<typename U , typename C , typename D >
void aurora::CopiedPtr< T >::reset ( U *  pointer,
cloner,
deleter 
)

Reset to raw pointer with cloner and deleter.

Parameters
pointerInitial pointer value, can be nullptr. Must be convertible to T*.
clonerCallable with signature T*(const T*) that is invoked during CopiedPtr copies. Must return a pointer to a copy of the argument.
deleterCallable with signature void(T*) that is invoked during CopiedPtr destruction.

If this instance currently holds a pointer, the old deleter is invoked.


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