41template <
typename DataType>
class cow_ptr {
69 const DataType *
get() const noexcept {
return Data.get(); }
72 explicit operator bool() const noexcept {
return bool(
Data); }
105template <
typename DataType>
117 std::atomic_store(&Data, std::atomic_load(&A.Data));
129 if (this->Data != A) {
130 std::atomic_store(&Data, std::atomic_load(&A));
150 if (!Data.unique()) {
151 std::lock_guard<std::mutex> lock{copyMutex};
154 if (!Data.unique()) {
155 std::atomic_store(&Data, std::make_shared<DataType>(*Data));
162 std::atomic_store(&this->Data, std::move(resourceSptr));
166 std::atomic_store(&this->Data, std::atomic_load(&resourceSptr));
const std::vector< double > & rhs
Implements a copy on write data template.
bool operator!=(const cow_ptr< DataType > &A) const noexcept
Based on ptr inequality.
constexpr cow_ptr(std::nullptr_t) noexcept
Constructs a cow_ptr with no managed object, i.e. empty cow_ptr.
std::shared_ptr< DataType > ptr_type
typedef for the storage
cow_ptr< DataType > & operator=(const ptr_type &) noexcept
Assignment operator : double references the data object maybe drops the old reference.
const DataType * get() const noexcept
Returns the stored pointer.
cow_ptr< DataType > & operator=(const cow_ptr< DataType > &) noexcept
Assignment operator : double references the data object maybe drops the old reference.
DataType & access()
Access function.
const DataType * operator->() const
indirectrion dereference access
const DataType & operator*() const
Pointer dereference access.
cow_ptr(const cow_ptr< DataType > &) noexcept
Copy constructor : double references the data object.
cow_ptr(ptr_type &&resourceSptr) noexcept
cow_ptr< DataType > & operator=(cow_ptr< DataType > &&rhs) noexcept
bool unique() const noexcept
Checks if *this is the only shared_ptr instance managing the current object, i.e.
long use_count() const noexcept
Returns the number of different shared_ptr instances (this included) managing the current object.
cow_ptr()
Constructor : creates new data() object.
DataType value_type
typedef for the data type
ptr_type Data
Real object Ptr.
bool operator==(const cow_ptr< DataType > &A) const noexcept
Based on ptr equality.
cow_ptr(cow_ptr< DataType > &&other) noexcept
cow_ptr(const ptr_type &resourceSptr) noexcept
cow_ptr(DataType *resourcePtr)
Constructor : creates a new cow_ptr around the resource resource is a sink.
Helper class which provides the Collimation Length for SANS instruments.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces