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

Specialisation of copy on write pointer for classes based with copy on write pointer base. More...

#include <memory.hpp>

Inheritance diagram for ext::cow_shared_ptr< T >:
[legend]
Collaboration diagram for ext::cow_shared_ptr< T >:
[legend]

Public Member Functions

 cow_shared_ptr (const cow_shared_ptr &other)=default
 Copy constructor to create new instance of shared pointer reffering the same data. More...
 
 cow_shared_ptr (cow_shared_ptr &&other) noexcept=default
 Move constructor to create new instance of shared pointer reffering the same data. More...
 
 ~cow_shared_ptr () noexcept=default
 The destructor of the shared pointer. More...
 
cow_shared_ptroperator= (const cow_shared_ptr &other)=default
 Copy assignment operator to change reffered instace to source one. More...
 
cow_shared_ptroperator= (cow_shared_ptr &&other) noexcept=default
 Move assignment operator to change reffered instace to source one. More...
 
void reset () noexcept
 Sets the shared pointer to nullptr. More...
 
template<class Y >
void reset (Y *ptr)
 Sets the shared pointer to value. More...
 
T * operator-> ()
 Operator arrow to chain dereferece to inner managed pointer. More...
 
T const * operator-> () const
 Operator arrow to chain dereferece to inner managed pointer. More...
 
T & operator* ()
 Operator dereference to access the inner managed pointer. More...
 
T const & operator* () const
 Operator dereference to access the inner managed pointer. More...
 
T * get ()
 
T const * get () const
 
bool unique () const
 Tests whether the managed pointer is referenced from one location only (or the class stores null pointer). More...
 
unsigned use_count () const
 Getter of the number how many times the managed pointer is referenced. More...
 
 operator bool () const
 

Friends

void swap (cow_shared_ptr &first, cow_shared_ptr &second)
 Specialisation of swap method to copy on write shared pointers. More...
 

Detailed Description

template<class T>
class ext::cow_shared_ptr< T >

Specialisation of copy on write pointer for classes based with copy on write pointer base.

The class is essentially mimicking the behavior of shared_ptr. Additionaly the use of dereference (either through operator* or operator->) in non-constant context causes the managed pointer to ensure the referenced object is referenced from this class only.

The class also uniques the referenced instances when they are equal.

Template Parameters
Tthe type of managed objects

Constructor & Destructor Documentation

◆ cow_shared_ptr() [1/2]

template<class T >
ext::cow_shared_ptr< T >::cow_shared_ptr ( const cow_shared_ptr< T > &  other)
default

Copy constructor to create new instance of shared pointer reffering the same data.

Parameters
otherthe source instance

◆ cow_shared_ptr() [2/2]

template<class T >
ext::cow_shared_ptr< T >::cow_shared_ptr ( cow_shared_ptr< T > &&  other)
defaultnoexcept

Move constructor to create new instance of shared pointer reffering the same data.

Parameters
otherthe source instance

◆ ~cow_shared_ptr()

template<class T >
ext::cow_shared_ptr< T >::~cow_shared_ptr ( )
defaultnoexcept

The destructor of the shared pointer.

Member Function Documentation

◆ get() [1/2]

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

Getter of the raw managed pointer.

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

◆ get() [2/2]

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

Getter of the raw managed pointer.

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

◆ operator bool()

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

Tests the instance whether the managed pointer is valid

Returns
true if the managed pointer is not null and the use count is nonzero, false otherwise
Here is the call graph for this function:

◆ operator*() [1/2]

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

Operator dereference to access the inner managed pointer.

Returns
reference to managed data
Here is the call graph for this function:

◆ operator*() [2/2]

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

Operator dereference to access the inner managed pointer.

Returns
reference to managed data
Here is the call graph for this function:

◆ operator->() [1/2]

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

Operator arrow to chain dereferece to inner managed pointer.

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

◆ operator->() [2/2]

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

Operator arrow to chain dereferece to inner managed pointer.

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

◆ operator=() [1/2]

template<class T >
cow_shared_ptr & ext::cow_shared_ptr< T >::operator= ( const cow_shared_ptr< T > &  other)
default

Copy assignment operator to change reffered instace to source one.

Parameters
otherthe source instance

◆ operator=() [2/2]

template<class T >
cow_shared_ptr & ext::cow_shared_ptr< T >::operator= ( cow_shared_ptr< T > &&  other)
defaultnoexcept

Move assignment operator to change reffered instace to source one.

Parameters
otherthe source instance

◆ reset() [1/2]

template<class T >
void ext::cow_shared_ptr< T >::reset ( )
inlinenoexcept

Sets the shared pointer to nullptr.

Here is the call graph for this function:

◆ reset() [2/2]

template<class T >
template<class Y >
void ext::cow_shared_ptr< T >::reset ( Y *  ptr)
inline

Sets the shared pointer to value.

Parameters
ptrthe value to store
Here is the call graph for this function:

◆ unique()

template<class T >
bool ext::cow_shared_ptr< T >::unique ( ) const
inline

Tests whether the managed pointer is referenced from one location only (or the class stores null pointer).

Returns
bool true if the managed pointer is referenced from one location only, false otherwise
Here is the call graph for this function:

◆ use_count()

template<class T >
unsigned ext::cow_shared_ptr< T >::use_count ( ) const
inline

Getter of the number how many times the managed pointer is referenced.

Returns
the use count
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ swap

template<class T >
void swap ( cow_shared_ptr< T > &  first,
cow_shared_ptr< T > &  second 
)
friend

Specialisation of swap method to copy on write shared pointers.

Parameters
firstthe first instance
secondthe second instance

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