Lagrange
|
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_ptr & | operator= (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_ptr & | operator= (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 |
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.
T | Pointee type. |
|
inline |
Return a weak pointer to the data.
|
inline |
Return a weak pointer to the data.
|
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