14#include <lagrange/utils/assert.h>
16#include <lagrange/Logger.h>
18#include <lagrange/internal/shared_ptr.h>
19#include <lagrange/utils/build.h>
41 using const_pointer =
typename std::add_const<T>::type*;
43 using const_reference =
typename std::add_const<T>::type&;
44 using element_type = T;
49 : m_data(std::move(ptr))
63 template <
typename Derived>
65 : m_data{std::move(ptr.m_data)}
75 explicit operator bool()
const {
return bool(m_data); }
78 const T*
read()
const {
return m_data.get(); }
81 template <
typename Derived>
84 return static_cast<const Derived*
>(m_data.get());
88 template <
typename Derived>
91 ensure_unique_owner<Derived>();
92 return static_cast<Derived*
>(m_data.get());
96 template <
typename Derived>
99 ensure_unique_owner<Derived>();
100 auto ptr =
static_cast<Derived*
>(m_data.get());
101#if LAGRANGE_TARGET_FEATURE(RTTI)
104 auto ret = std::make_shared<Derived>(std::move(*ptr));
131 template <
typename Derived>
136 if (m_data.use_count() != 1) {
143 auto ptr =
static_cast<const Derived*
>(m_data.get());
144#if LAGRANGE_TARGET_FEATURE(RTTI)
147 m_data = ::lagrange::internal::make_shared<Derived>(*ptr);
A handle type with copy-on-write semantics.
Definition: copy_on_write_ptr.h:38
copy_on_write_ptr(const copy_on_write_ptr &)=default
Default copy constructor.
::lagrange::internal::weak_ptr< T > _get_weak_ptr()
Return a weak pointer to the data.
Definition: copy_on_write_ptr.h:122
::lagrange::internal::weak_ptr< const T > _get_weak_ptr() const
Return a weak pointer to the data.
Definition: copy_on_write_ptr.h:115
const T * read() const
Returns a const pointer to the data. Does not require ownership and will not lead to any copy.
Definition: copy_on_write_ptr.h:78
copy_on_write_ptr & operator=(const copy_on_write_ptr &)=default
Default copy assignment operator.
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.
std::shared_ptr< Derived > release_ptr()
Returns a writable smart pointer to the data. Will cause a copy if ownership is shared.
Definition: copy_on_write_ptr.h:97
Derived * static_write()
Returns a writable pointer to the data. Will cause a copy if ownership is shared.
Definition: copy_on_write_ptr.h:89
const Derived * static_read() const
Returns a const pointer to the data. Does not require ownership and will not lead to any copy.
Definition: copy_on_write_ptr.h:82
copy_on_write_ptr(::lagrange::internal::shared_ptr< T > &&ptr=nullptr)
Construct a copy-on-write ptr from a shared-pointer.
Definition: copy_on_write_ptr.h:48
void ensure_unique_owner()
Protect from data races when acquiring ownership to the same object from multiple threads.
Definition: copy_on_write_ptr.h:132
copy_on_write_ptr(copy_on_write_ptr< Derived > &&ptr)
Move-construct from a derived type.
Definition: copy_on_write_ptr.h:64
NOT implemented: custom allocator support.
Definition: shared_ptr.h:110
Definition: weak_ptr.h:26
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
#define la_debug_assert(...)
Debug assertion check.
Definition: assert.h:189
Main namespace for Lagrange.
Definition: AABBIGL.h:30