Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
Public Member Functions
ext::smart_ptr< T > Class Template Reference

Managed pointer simulating value like behavior. More...

#include <memory.hpp>

Public Member Functions

 smart_ptr ()
 Default initialization to null. More...
 
 smart_ptr (T *data)
 Constructor which takes ownership of the provided pointer. More...
 
template<class R >
 smart_ptr (smart_ptr< R > other)
 Conversion constructor to simplify type casting. More...
 
 smart_ptr (const smart_ptr &other)
 Copy constructor of the smart pointer. Internally uses clone (if available) or copy constructor of the managed resource. More...
 
 smart_ptr (smart_ptr &&other) noexcept
 Move constructor of the smart pointer. Passes ownership of the managed resource from source to constructed instance. More...
 
 ~smart_ptr () noexcept
 The destructor of the shared pointer, responsible for freeing the managed resource. More...
 
smart_ptroperator= (const smart_ptr &other)
 Copy operator of assignment. Internally uses clone (if available) or copy constructor of the managed resource. More...
 
smart_ptroperator= (smart_ptr &&other) noexcept
 Copy operator of assignment. Passes ownership of the managed resource from source to this instance. More...
 
T * operator-> ()
 Operator arrow to chain dereferece to inner managed pointer. More...
 
T * operator-> () const
 Operator arrow to chain dereferece to inner managed pointer. More...
 
T & operator* ()
 Operator dereference to access the inner managed pointer. More...
 
T & operator* () const
 Operator dereference to access the inner managed pointer. More...
 
T * get ()
 Getter of the raw managed pointer. More...
 
T * get () const
 Getter of the raw managed pointer. More...
 
T * release ()
 Releases the shared resource and returns it. More...
 
 operator bool () const
 Tests the instance whether the managed pointer is valid. More...
 

Detailed Description

template<class T>
class ext::smart_ptr< T >

Managed pointer simulating value like behavior.

The class is supposed to be similar to unique_ptr but allows copying of managed instance by clone method or its copy constructor.

Template Parameters
Ttype of managed instance

Constructor & Destructor Documentation

◆ smart_ptr() [1/5]

template<class T >
ext::smart_ptr< T >::smart_ptr ( )
inlineexplicit

Default initialization to null.

◆ smart_ptr() [2/5]

template<class T >
ext::smart_ptr< T >::smart_ptr ( T *  data)
inlineexplicit

Constructor which takes ownership of the provided pointer.

◆ smart_ptr() [3/5]

template<class T >
template<class R >
ext::smart_ptr< T >::smart_ptr ( smart_ptr< R >  other)
inline

Conversion constructor to simplify type casting.

Template Parameters
Rthe type of the managed resource of the source smart pointer
Parameters
otherthe source instance

◆ smart_ptr() [4/5]

template<class T >
ext::smart_ptr< T >::smart_ptr ( const smart_ptr< T > &  other)
inline

Copy constructor of the smart pointer. Internally uses clone (if available) or copy constructor of the managed resource.

Parameters
otherthe source instance

◆ smart_ptr() [5/5]

template<class T >
ext::smart_ptr< T >::smart_ptr ( smart_ptr< T > &&  other)
inlinenoexcept

Move constructor of the smart pointer. Passes ownership of the managed resource from source to constructed instance.

Parameters
otherthe source instance

◆ ~smart_ptr()

template<class T >
ext::smart_ptr< T >::~smart_ptr ( )
inlinenoexcept

The destructor of the shared pointer, responsible for freeing the managed resource.

Member Function Documentation

◆ get() [1/2]

template<class T >
T * ext::smart_ptr< T >::get ( )
inline

Getter of the raw managed pointer.

Returns
the managed pointer
Here is the caller graph for this function:

◆ get() [2/2]

template<class T >
T * ext::smart_ptr< T >::get ( ) const
inline

Getter of the raw managed pointer.

Returns
the managed pointer

◆ operator bool()

template<class T >
ext::smart_ptr< T >::operator bool ( ) const
inlineexplicit

Tests the instance whether the managed pointer is valid.

Returns
true if the managed pointer is not null, false otherwise

◆ operator*() [1/2]

template<class T >
T & ext::smart_ptr< T >::operator* ( )
inline

Operator dereference to access the inner managed pointer.

Returns
reference to managed data

◆ operator*() [2/2]

template<class T >
T & ext::smart_ptr< T >::operator* ( ) const
inline

Operator dereference to access the inner managed pointer.

Returns
reference to managed data

◆ operator->() [1/2]

template<class T >
T * ext::smart_ptr< T >::operator-> ( )
inline

Operator arrow to chain dereferece to inner managed pointer.

Returns
the managed pointer

◆ operator->() [2/2]

template<class T >
T * ext::smart_ptr< T >::operator-> ( ) const
inline

Operator arrow to chain dereferece to inner managed pointer.

Returns
the managed pointer

◆ operator=() [1/2]

template<class T >
smart_ptr & ext::smart_ptr< T >::operator= ( const smart_ptr< T > &  other)
inline

Copy operator of assignment. Internally uses clone (if available) or copy constructor of the managed resource.

Parameters
otherthe source instance
Here is the call graph for this function:

◆ operator=() [2/2]

template<class T >
smart_ptr & ext::smart_ptr< T >::operator= ( smart_ptr< T > &&  other)
inlinenoexcept

Copy operator of assignment. Passes ownership of the managed resource from source to this instance.

Parameters
otherthe source instance
Here is the call graph for this function:

◆ release()

template<class T >
T * ext::smart_ptr< T >::release ( )
inline

Releases the shared resource and returns it.

Returns
the released shared resource

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