Lagrange
copy_on_write_ptr< T > Class Template Reference

A handle type with copy-on-write semantics. More...

#include <lagrange/utils/copy_on_write_ptr.h>

Public Types

using pointer = T *
 
using const_pointer = typename std::add_const< T >::type *
 
using reference = T &
 
using const_reference = typename std::add_const< T >::type &
 
using element_type = T
 

Public Member Functions

 copy_on_write_ptr (::lagrange::internal::shared_ptr< T > &&ptr=nullptr)
 Construct a copy-on-write ptr from a shared-pointer.
 
 copy_on_write_ptr (copy_on_write_ptr &&)=default
 Default move constructor.
 
copy_on_write_ptroperator= (copy_on_write_ptr &&)=default
 Default move assignment operator.
 
template<typename Derived >
 copy_on_write_ptr (copy_on_write_ptr< Derived > &&ptr)
 Move-construct from a derived type.
 
 copy_on_write_ptr (const copy_on_write_ptr &)=default
 Default copy constructor.
 
copy_on_write_ptroperator= (const copy_on_write_ptr &)=default
 Default copy assignment operator.
 
 operator bool () const
 Check if this copy-on-write ptr is nullptr.
 
const T * read () const
 Returns a const pointer to the data. Does not require ownership and will not lead to any copy.
 
template<typename Derived >
const Derived * static_read () const
 Returns a const pointer to the data. Does not require ownership and will not lead to any copy.
 
template<typename Derived >
Derived * static_write ()
 Returns a writable pointer to the data. Will cause a copy if ownership is shared.
 
template<typename Derived >
std::shared_ptr< Derived > release_ptr ()
 Returns a writable smart pointer to the data. Will cause a copy if ownership is shared.
 
::lagrange::internal::weak_ptr< const T > _get_weak_ptr () const
 Return a weak pointer to the data. More...
 
::lagrange::internal::weak_ptr< T > _get_weak_ptr ()
 Return a weak pointer to the data. More...
 

Protected Member Functions

template<typename Derived >
void ensure_unique_owner ()
 Protect from data races when acquiring ownership to the same object from multiple threads. More...
 

Protected Attributes

::lagrange::internal::shared_ptr< T > m_data
 

Detailed Description

template<typename T>
class lagrange::copy_on_write_ptr< T >

A handle type with copy-on-write semantics.

Any copy of the handle will share data ownership, causing potential copies of the data on write access.

Template Parameters
TPointee type.

Member Function Documentation

◆ _get_weak_ptr() [1/2]

::lagrange::internal::weak_ptr< const T > _get_weak_ptr ( ) const
inline

Return a weak pointer to the data.

Warning
This method is for internal usage purposes.
See also
read() for preferred way of accessing data.

◆ _get_weak_ptr() [2/2]

::lagrange::internal::weak_ptr< T > _get_weak_ptr ( )
inline

Return a weak pointer to the data.

Warning
This method is for internal usage purposes.
See also
read() for preferred way of accessing data.

◆ ensure_unique_owner()

void ensure_unique_owner ( )
inlineprotected

Protect from data races when acquiring ownership to the same object from multiple threads.

If we are not the owner of the shared object, make a private copy of it


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