Mantid
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
Mantid::Kernel::cow_ptr< DataType > Class Template Reference

Implements a copy on write data template. More...

#include <cow_ptr.h>

Public Types

using ptr_type = std::shared_ptr< DataType >
 typedef for the storage More...
 
using value_type = DataType
 typedef for the data type More...
 

Public Member Functions

DataType & access ()
 Access function. More...
 
 cow_ptr ()
 Constructor : creates new data() object. More...
 
 cow_ptr (const cow_ptr< DataType > &) noexcept
 Copy constructor : double references the data object. More...
 
 cow_ptr (const ptr_type &resourceSptr) noexcept
 
 cow_ptr (cow_ptr< DataType > &&other) noexcept
 
 cow_ptr (DataType *resourcePtr)
 Constructor : creates a new cow_ptr around the resource resource is a sink. More...
 
 cow_ptr (ptr_type &&resourceSptr) noexcept
 
constexpr cow_ptr (std::nullptr_t) noexcept
 Constructs a cow_ptr with no managed object, i.e. empty cow_ptr. More...
 
const DataType * get () const noexcept
 Returns the stored pointer. More...
 
 operator bool () const noexcept
 Checks if *this stores a non-null pointer, i.e. whether get() != nullptr. More...
 
bool operator!= (const cow_ptr< DataType > &A) const noexcept
 Based on ptr inequality. More...
 
const DataType & operator* () const
 Pointer dereference access. More...
 
const DataType * operator-> () const
 indirectrion dereference access More...
 
cow_ptr< DataType > & operator= (const cow_ptr< DataType > &) noexcept
 Assignment operator : double references the data object maybe drops the old reference. More...
 
cow_ptr< DataType > & operator= (const ptr_type &) noexcept
 Assignment operator : double references the data object maybe drops the old reference. More...
 
cow_ptr< DataType > & operator= (cow_ptr< DataType > &&rhs) noexcept
 
bool operator== (const cow_ptr< DataType > &A) const noexcept
 Based on ptr equality. More...
 
bool unique () const noexcept
 Checks if *this is the only shared_ptr instance managing the current object, i.e. More...
 
long use_count () const noexcept
 Returns the number of different shared_ptr instances (this included) managing the current object. More...
 

Private Attributes

std::mutex copyMutex
 
ptr_type Data
 Real object Ptr. More...
 

Detailed Description

template<typename DataType>
class Mantid::Kernel::cow_ptr< DataType >

Implements a copy on write data template.

Version
1.0
Date
February 2006
Author
S.Ansell

This version works only on data that is created via new(). It is thread safe and works in the Standard template libraries (but appropriate functionals are needed for sorting etc.).

Renamed from RefControl on the 11/12/2007, as it was agreed that copy on write pointer better described the functionality of this class.

The underlying data can be accessed via the normal pointer semantics but call the access function if the data is required to be modified.

Definition at line 41 of file cow_ptr.h.

Member Typedef Documentation

◆ ptr_type

template<typename DataType >
using Mantid::Kernel::cow_ptr< DataType >::ptr_type = std::shared_ptr<DataType>

typedef for the storage

Definition at line 43 of file cow_ptr.h.

◆ value_type

template<typename DataType >
using Mantid::Kernel::cow_ptr< DataType >::value_type = DataType

typedef for the data type

Definition at line 44 of file cow_ptr.h.

Constructor & Destructor Documentation

◆ cow_ptr() [1/7]

template<typename DataType >
Mantid::Kernel::cow_ptr< DataType >::cow_ptr ( ptr_type &&  resourceSptr)
noexcept

Definition at line 161 of file cow_ptr.h.

◆ cow_ptr() [2/7]

template<typename DataType >
Mantid::Kernel::cow_ptr< DataType >::cow_ptr ( const ptr_type resourceSptr)
noexcept

Definition at line 165 of file cow_ptr.h.

◆ cow_ptr() [3/7]

template<typename DataType >
Mantid::Kernel::cow_ptr< DataType >::cow_ptr ( DataType *  resourcePtr)
explicit

Constructor : creates a new cow_ptr around the resource resource is a sink.

Definition at line 93 of file cow_ptr.h.

◆ cow_ptr() [4/7]

template<typename DataType >
Mantid::Kernel::cow_ptr< DataType >::cow_ptr

Constructor : creates new data() object.

Definition at line 98 of file cow_ptr.h.

◆ cow_ptr() [5/7]

template<typename DataType >
constexpr Mantid::Kernel::cow_ptr< DataType >::cow_ptr ( std::nullptr_t  )
inlineconstexprnoexcept

Constructs a cow_ptr with no managed object, i.e. empty cow_ptr.

Definition at line 56 of file cow_ptr.h.

◆ cow_ptr() [6/7]

template<typename DataType >
Mantid::Kernel::cow_ptr< DataType >::cow_ptr ( const cow_ptr< DataType > &  A)
noexcept

Copy constructor : double references the data object.

Parameters
A:: object to copy

Definition at line 106 of file cow_ptr.h.

◆ cow_ptr() [7/7]

template<typename DataType >
Mantid::Kernel::cow_ptr< DataType >::cow_ptr ( cow_ptr< DataType > &&  other)
inlinenoexcept

Definition at line 59 of file cow_ptr.h.

Member Function Documentation

◆ access()

template<typename DataType >
DataType & Mantid::Kernel::cow_ptr< DataType >::access

Access function.

If data is shared, creates a copy of Data so that it can be modified.

In certain situations this function is not thread safe. Specifically it is not thread safe in the presence of a simultaneous cow_ptr copy. Copies of the underlying data are only made when the reference count > 1.

Returns
new copy of *this, if required

Definition at line 147 of file cow_ptr.h.

Referenced by Mantid::Algorithms::RebinByTimeBase::exec(), Mantid::Algorithms::Transpose::exec(), and Mantid::Algorithms::XDataConverter::exec().

◆ get()

template<typename DataType >
const DataType * Mantid::Kernel::cow_ptr< DataType >::get ( ) const
inlinenoexcept

Returns the stored pointer.

Definition at line 69 of file cow_ptr.h.

References Mantid::Kernel::cow_ptr< DataType >::Data.

◆ operator bool()

template<typename DataType >
Mantid::Kernel::cow_ptr< DataType >::operator bool ( ) const
inlineexplicitnoexcept

Checks if *this stores a non-null pointer, i.e. whether get() != nullptr.

Definition at line 72 of file cow_ptr.h.

References Mantid::Kernel::cow_ptr< DataType >::Data.

◆ operator!=()

template<typename DataType >
bool Mantid::Kernel::cow_ptr< DataType >::operator!= ( const cow_ptr< DataType > &  A) const
inlinenoexcept

Based on ptr inequality.

Definition at line 85 of file cow_ptr.h.

References Mantid::Kernel::cow_ptr< DataType >::Data.

◆ operator*()

template<typename DataType >
const DataType & Mantid::Kernel::cow_ptr< DataType >::operator* ( ) const
inline

Pointer dereference access.

Definition at line 82 of file cow_ptr.h.

References Mantid::Kernel::cow_ptr< DataType >::Data.

◆ operator->()

template<typename DataType >
const DataType * Mantid::Kernel::cow_ptr< DataType >::operator-> ( ) const
inline

indirectrion dereference access

Definition at line 83 of file cow_ptr.h.

References Mantid::Kernel::cow_ptr< DataType >::Data.

◆ operator=() [1/3]

template<typename DataType >
cow_ptr< DataType > & Mantid::Kernel::cow_ptr< DataType >::operator= ( const cow_ptr< DataType > &  A)
noexcept

Assignment operator : double references the data object maybe drops the old reference.

Parameters
A:: object to copy
Returns
*this

Definition at line 115 of file cow_ptr.h.

◆ operator=() [2/3]

template<typename DataType >
cow_ptr< DataType > & Mantid::Kernel::cow_ptr< DataType >::operator= ( const ptr_type A)
noexcept

Assignment operator : double references the data object maybe drops the old reference.

Parameters
A:: object to copy
Returns
*this

Definition at line 128 of file cow_ptr.h.

◆ operator=() [3/3]

template<typename DataType >
cow_ptr< DataType > & Mantid::Kernel::cow_ptr< DataType >::operator= ( cow_ptr< DataType > &&  rhs)
inlinenoexcept

Definition at line 62 of file cow_ptr.h.

References Mantid::Kernel::cow_ptr< DataType >::Data, and rhs.

◆ operator==()

template<typename DataType >
bool Mantid::Kernel::cow_ptr< DataType >::operator== ( const cow_ptr< DataType > &  A) const
inlinenoexcept

Based on ptr equality.

Definition at line 84 of file cow_ptr.h.

References Mantid::Kernel::cow_ptr< DataType >::Data.

◆ unique()

template<typename DataType >
bool Mantid::Kernel::cow_ptr< DataType >::unique ( ) const
inlinenoexcept

Checks if *this is the only shared_ptr instance managing the current object, i.e.

whether use_count() == 1.

Definition at line 80 of file cow_ptr.h.

References Mantid::Kernel::cow_ptr< DataType >::Data.

◆ use_count()

template<typename DataType >
long Mantid::Kernel::cow_ptr< DataType >::use_count ( ) const
inlinenoexcept

Returns the number of different shared_ptr instances (this included) managing the current object.

If there is no managed object, 0 is returned.

Definition at line 76 of file cow_ptr.h.

References Mantid::Kernel::cow_ptr< DataType >::Data.

Member Data Documentation

◆ copyMutex

template<typename DataType >
std::mutex Mantid::Kernel::cow_ptr< DataType >::copyMutex
private

Definition at line 48 of file cow_ptr.h.

◆ Data

template<typename DataType >
ptr_type Mantid::Kernel::cow_ptr< DataType >::Data
private

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