helib::ClonedPtr< T, Cloner > Class Template Reference

A smart pointer that clones the object it holds when it is copied. More...

#include <ClonedPtr.h>

Public Types

using value_type = T
 The type of the managed object. More...
 

Public Member Functions

 ClonedPtr (T *p=nullptr)
 Explicit constructor to create new ClonedPtr object. More...
 
 ClonedPtr (std::nullptr_t)
 Special constructor to create new ClonedPtr object promoting a nullptr. More...
 
 ~ClonedPtr ()
 The destructor deletes the managed object. More...
 
 ClonedPtr (const ClonedPtr &other)
 Copy construct by cloning the managed object based on the cloning policy. More...
 
 ClonedPtr (ClonedPtr &&other) noexcept
 Move construct by taking ownership of the managed object by the ClonedPtr object being moved and setting its pointer to nullptr. More...
 
ClonedPtroperator= (const ClonedPtr &other)
 Copy assign by cloning the managed object based on the cloning policy. More...
 
ClonedPtroperator= (ClonedPtr &&other) noexcept
 Move construct by taking ownership of the managed object by the ClonedPtr object being moved and setting its pointer to nullptr. More...
 
void reset (T *p=nullptr)
 Reset method deletes the object that it currently managed and manages the object given by a raw pointer. More...
 
T * release () noexcept
 Release the ownership of the currently managed object by returning the pointer and setting the held pointer to nullptr. More...
 
 operator bool () const noexcept
 convert ClonedPtr to bool, false if there is a managed object is else converts to true. More...
 
const T & operator* () const
 Dereference the smart pointer. More...
 
T & operator* ()
 Dereference the smart pointer. More...
 
const T * operator-> () const
 Struct dereference to access members of the managed object. More...
 
T * operator-> ()
 Struct dereference to access members of the managed object. More...
 
const T * get () const
 Get the pointer managed by ClonedPtr object. More...
 
T * get ()
 Get the pointer managed by ClonedPtr object. More...
 
bool operator== (const ClonedPtr &other) const
 Equal to another ClonedPtr object. More...
 
bool operator!= (const ClonedPtr &other) const
 Not equal to another ClonedPtr object. More...
 
bool operator< (const ClonedPtr &other) const
 Less than another ClonedPtr object. More...
 
bool operator> (const ClonedPtr &other) const
 Greater than another ClonedPtr object. More...
 
bool operator<= (const ClonedPtr &other) const
 Less than or equal to another ClonedPtr object. More...
 
bool operator>= (const ClonedPtr &other) const
 Greater than or equal to another ClonedPtr object. More...
 
void swap (ClonedPtr &other)
 Swap the managed objects of the this ClonedPtr object and another. More...
 

Detailed Description

template<typename T, typename Cloner = DeepCopy<T>>
class helib::ClonedPtr< T, Cloner >

A smart pointer that clones the object it holds when it is copied.

Template Parameters
TThe type of object managed by the pointer.
ClonerA policy of how to clone the object pointed to, either deep or shallow. The default is deep.

Member Typedef Documentation

◆ value_type

template<typename T , typename Cloner = DeepCopy<T>>
using helib::ClonedPtr< T, Cloner >::value_type = T

The type of the managed object.

Constructor & Destructor Documentation

◆ ClonedPtr() [1/4]

template<typename T , typename Cloner = DeepCopy<T>>
helib::ClonedPtr< T, Cloner >::ClonedPtr ( T *  p = nullptr)
inlineexplicit

Explicit constructor to create new ClonedPtr object.

Parameters
pThe raw pointer to the object that ClonedPtr will manage.

◆ ClonedPtr() [2/4]

template<typename T , typename Cloner = DeepCopy<T>>
helib::ClonedPtr< T, Cloner >::ClonedPtr ( std::nullptr_t  )
inline

Special constructor to create new ClonedPtr object promoting a nullptr.

◆ ~ClonedPtr()

template<typename T , typename Cloner = DeepCopy<T>>
helib::ClonedPtr< T, Cloner >::~ClonedPtr ( )
inline

The destructor deletes the managed object.

◆ ClonedPtr() [3/4]

template<typename T , typename Cloner = DeepCopy<T>>
helib::ClonedPtr< T, Cloner >::ClonedPtr ( const ClonedPtr< T, Cloner > &  other)
inline

Copy construct by cloning the managed object based on the cloning policy.

Parameters
otherThe ClonedPtr object to be cloned.

◆ ClonedPtr() [4/4]

template<typename T , typename Cloner = DeepCopy<T>>
helib::ClonedPtr< T, Cloner >::ClonedPtr ( ClonedPtr< T, Cloner > &&  other)
inlinenoexcept

Move construct by taking ownership of the managed object by the ClonedPtr object being moved and setting its pointer to nullptr.

Parameters
otherThe ClonedPtr object to be moved.

Member Function Documentation

◆ get() [1/2]

template<typename T , typename Cloner = DeepCopy<T>>
T* helib::ClonedPtr< T, Cloner >::get ( )
inline

Get the pointer managed by ClonedPtr object.

Returns
The raw pointer to the managed object.

◆ get() [2/2]

template<typename T , typename Cloner = DeepCopy<T>>
const T* helib::ClonedPtr< T, Cloner >::get ( ) const
inline

Get the pointer managed by ClonedPtr object.

Returns
The const raw pointer to the managed object.

◆ operator bool()

template<typename T , typename Cloner = DeepCopy<T>>
helib::ClonedPtr< T, Cloner >::operator bool ( ) const
inlineexplicitnoexcept

convert ClonedPtr to bool, false if there is a managed object is else converts to true.

◆ operator!=()

template<typename T , typename Cloner = DeepCopy<T>>
bool helib::ClonedPtr< T, Cloner >::operator!= ( const ClonedPtr< T, Cloner > &  other) const
inline

Not equal to another ClonedPtr object.

Parameters
otherClonedPtr object to compare to.
Returns
true if this ClonedPtr does not manage the same object as other else false.

◆ operator*() [1/2]

template<typename T , typename Cloner = DeepCopy<T>>
T& helib::ClonedPtr< T, Cloner >::operator* ( )
inline

Dereference the smart pointer.

Returns
Reference to managed object.

◆ operator*() [2/2]

template<typename T , typename Cloner = DeepCopy<T>>
const T& helib::ClonedPtr< T, Cloner >::operator* ( ) const
inline

Dereference the smart pointer.

Returns
const reference to manged object.

◆ operator->() [1/2]

template<typename T , typename Cloner = DeepCopy<T>>
T* helib::ClonedPtr< T, Cloner >::operator-> ( )
inline

Struct dereference to access members of the managed object.

Returns
The raw pointer to the managed object.

◆ operator->() [2/2]

template<typename T , typename Cloner = DeepCopy<T>>
const T* helib::ClonedPtr< T, Cloner >::operator-> ( ) const
inline

Struct dereference to access members of the managed object.

Returns
The const raw pointer to the managed object.

◆ operator<()

template<typename T , typename Cloner = DeepCopy<T>>
bool helib::ClonedPtr< T, Cloner >::operator< ( const ClonedPtr< T, Cloner > &  other) const
inline

Less than another ClonedPtr object.

Parameters
otherClonedPtr object to compare to.
Returns
true if the address of the managed object is less than that of the object managed by other else false.

◆ operator<=()

template<typename T , typename Cloner = DeepCopy<T>>
bool helib::ClonedPtr< T, Cloner >::operator<= ( const ClonedPtr< T, Cloner > &  other) const
inline

Less than or equal to another ClonedPtr object.

Parameters
otherClonedPtr object to compare to.
Returns
true if the address of the managed object is less than or equal to that of the object managed by other else false.

◆ operator=() [1/2]

template<typename T , typename Cloner = DeepCopy<T>>
ClonedPtr& helib::ClonedPtr< T, Cloner >::operator= ( ClonedPtr< T, Cloner > &&  other)
inlinenoexcept

Move construct by taking ownership of the managed object by the ClonedPtr object being moved and setting its pointer to nullptr.

Parameters
otherThe ClonedPtr object to be moved.
Returns
Reference to *this.

◆ operator=() [2/2]

template<typename T , typename Cloner = DeepCopy<T>>
ClonedPtr& helib::ClonedPtr< T, Cloner >::operator= ( const ClonedPtr< T, Cloner > &  other)
inline

Copy assign by cloning the managed object based on the cloning policy.

Parameters
otherThe ClonedPtr object to be cloned.
Returns
Reference to *this.

◆ operator==()

template<typename T , typename Cloner = DeepCopy<T>>
bool helib::ClonedPtr< T, Cloner >::operator== ( const ClonedPtr< T, Cloner > &  other) const
inline

Equal to another ClonedPtr object.

Parameters
otherClonedPtr object to compare to.
Returns
true if this ClonedPtr manages the same object as other else false.

◆ operator>()

template<typename T , typename Cloner = DeepCopy<T>>
bool helib::ClonedPtr< T, Cloner >::operator> ( const ClonedPtr< T, Cloner > &  other) const
inline

Greater than another ClonedPtr object.

Parameters
otherClonedPtr object to compare to.
Returns
true if the address of the managed object is greater than that of the object managed by other else false.

◆ operator>=()

template<typename T , typename Cloner = DeepCopy<T>>
bool helib::ClonedPtr< T, Cloner >::operator>= ( const ClonedPtr< T, Cloner > &  other) const
inline

Greater than or equal to another ClonedPtr object.

Parameters
otherClonedPtr object to compare to.
Returns
true if the address of the managed object is greater than or equal to that of the object managed by other else false.

◆ release()

template<typename T , typename Cloner = DeepCopy<T>>
T* helib::ClonedPtr< T, Cloner >::release ( )
inlinenoexcept

Release the ownership of the currently managed object by returning the pointer and setting the held pointer to nullptr.

Returns
the pointer currently held by the ClonedPtr object.

◆ reset()

template<typename T , typename Cloner = DeepCopy<T>>
void helib::ClonedPtr< T, Cloner >::reset ( T *  p = nullptr)
inline

Reset method deletes the object that it currently managed and manages the object given by a raw pointer.

Parameters
pThe raw pointer to replace the raw pointer currently managed by the ClonedPtr object. The default is nullptr.

◆ swap()

template<typename T , typename Cloner = DeepCopy<T>>
void helib::ClonedPtr< T, Cloner >::swap ( ClonedPtr< T, Cloner > &  other)
inline

Swap the managed objects of the this ClonedPtr object and another.

Parameters
otherClonedPtr object to swap managed object with.