DGtal  0.9.3beta
Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::CowPtr< T > Class Template Reference

#include <DGtal/base/CowPtr.h>

Inheritance diagram for DGtal::CowPtr< T >:
[legend]

Public Types

typedef T element_type
 

Public Member Functions

 CowPtr (T *p=0) throw ()
 
 CowPtr (const CowPtr &r) throw ()
 
 CowPtr (const CountedPtr< T > &r)
 
CowPtroperator= (const CowPtr &r)
 
const T & operator* () const throw ()
 
const T * operator-> () const throw ()
 
const T * get () const throw ()
 
template<typename U = T, typename std::enable_if< !std::is_const< U >::value >::type * = nullptr>
T & operator* ()
 
template<typename U = T, typename std::enable_if< !std::is_const< U >::value >::type * = nullptr>
T * operator-> ()
 
template<typename U = T, typename std::enable_if< !std::is_const< U >::value >::type * = nullptr>
T * get ()
 
bool operator== (const T *other) const
 
bool operator!= (const T *other) const
 
unsigned int count () const
 
T * drop ()
 
bool unique () const throw ()
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Private Member Functions

void copy ()
 

Private Attributes

CountedPtr< T > myPtr
 

Detailed Description

template<typename T>
class DGtal::CowPtr< T >

Aim: Copy on write shared pointer.

Description of template class 'CowPtr'

Use reference counting as long as the pointed object is not modified. When it is about to be modified, copy it and modify the copy.

Taken from http://ootips.org/yonat/4dev/smart-pointers.html

Definition at line 67 of file CowPtr.h.

Member Typedef Documentation

template<typename T>
typedef T DGtal::CowPtr< T >::element_type

Definition at line 72 of file CowPtr.h.

Constructor & Destructor Documentation

template<typename T>
DGtal::CowPtr< T >::CowPtr ( T *  p = 0)
throw (
)
inlineexplicit

Definition at line 74 of file CowPtr.h.

74 : myPtr(p) {}
CountedPtr< T > myPtr
Definition: CowPtr.h:156
template<typename T>
DGtal::CowPtr< T >::CowPtr ( const CowPtr< T > &  r)
throw (
)
inline

Definition at line 76 of file CowPtr.h.

76 : myPtr(r.myPtr) {}
CountedPtr< T > myPtr
Definition: CowPtr.h:156
template<typename T>
DGtal::CowPtr< T >::CowPtr ( const CountedPtr< T > &  r)
inline
Todo:
JOL: check this.

Definition at line 80 of file CowPtr.h.

80 : myPtr( r ) {}
CountedPtr< T > myPtr
Definition: CowPtr.h:156

Member Function Documentation

template<typename T>
void DGtal::CowPtr< T >::copy ( )
inlineprivate

Definition at line 160 of file CowPtr.h.

Referenced by DGtal::CowPtr< Domain >::get(), DGtal::CowPtr< Domain >::operator*(), and DGtal::CowPtr< Domain >::operator->().

161  {
162  if (!myPtr.unique()) {
163  T* old_p = myPtr.get();
164  myPtr = CountedPtr<T>(new T(*old_p));
165  }
166  }
CountedPtr< T > myPtr
Definition: CowPtr.h:156
template<typename T>
unsigned int DGtal::CowPtr< T >::count ( ) const
inline

For debug.

Definition at line 147 of file CowPtr.h.

147 {return myPtr.count();}
CountedPtr< T > myPtr
Definition: CowPtr.h:156
template<typename T>
T* DGtal::CowPtr< T >::drop ( )
inline

Definition at line 148 of file CowPtr.h.

148 { return myPtr.drop(); }
CountedPtr< T > myPtr
Definition: CowPtr.h:156
template<typename T>
const T* DGtal::CowPtr< T >::get ( ) const
throw (
)
inline

Definition at line 91 of file CowPtr.h.

91 {return myPtr.get();}
CountedPtr< T > myPtr
Definition: CowPtr.h:156
template<typename T>
template<typename U = T, typename std::enable_if< !std::is_const< U >::value >::type * = nullptr>
T* DGtal::CowPtr< T >::get ( )
inline

Definition at line 119 of file CowPtr.h.

119 {copy(); return myPtr.get();}
CountedPtr< T > myPtr
Definition: CowPtr.h:156
void copy()
Definition: CowPtr.h:160
template<typename T>
bool DGtal::CowPtr< T >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

Referenced by DGtal::Image< TImageContainer >::isValid().

template<typename T>
bool DGtal::CowPtr< T >::operator!= ( const T *  other) const
inline

Inequality operator !=

Parameters
otherany other pointer.
Returns
'true' if pointed address is different from other.

Definition at line 138 of file CowPtr.h.

139  {
140  return get() != other;
141  }
template<typename T>
const T& DGtal::CowPtr< T >::operator* ( ) const
throw (
)
inline

Definition at line 89 of file CowPtr.h.

89 {return *myPtr;}
CountedPtr< T > myPtr
Definition: CowPtr.h:156
template<typename T>
template<typename U = T, typename std::enable_if< !std::is_const< U >::value >::type * = nullptr>
T& DGtal::CowPtr< T >::operator* ( )
inline

Definition at line 113 of file CowPtr.h.

113 {copy(); return *myPtr;}
CountedPtr< T > myPtr
Definition: CowPtr.h:156
void copy()
Definition: CowPtr.h:160
template<typename T>
const T* DGtal::CowPtr< T >::operator-> ( ) const
throw (
)
inline

Definition at line 90 of file CowPtr.h.

90 {return myPtr.get();}
CountedPtr< T > myPtr
Definition: CowPtr.h:156
template<typename T>
template<typename U = T, typename std::enable_if< !std::is_const< U >::value >::type * = nullptr>
T* DGtal::CowPtr< T >::operator-> ( )
inline

Definition at line 116 of file CowPtr.h.

116 {copy(); return myPtr.get();}
CountedPtr< T > myPtr
Definition: CowPtr.h:156
void copy()
Definition: CowPtr.h:160
template<typename T>
CowPtr& DGtal::CowPtr< T >::operator= ( const CowPtr< T > &  r)
inline

Definition at line 81 of file CowPtr.h.

82  {
83  if (this != &r)
84  myPtr = r.myPtr;
85  return *this;
86  }
CountedPtr< T > myPtr
Definition: CowPtr.h:156
template<typename T>
bool DGtal::CowPtr< T >::operator== ( const T *  other) const
inline

Equality operator ==

Parameters
otherany other pointer.
Returns
'true' if pointed address is equal to other.

Definition at line 127 of file CowPtr.h.

128  {
129  return get() == other;
130  }
template<typename T>
void DGtal::CowPtr< T >::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.
template<typename T>
bool DGtal::CowPtr< T >::unique ( ) const
throw (
)
inline

Definition at line 149 of file CowPtr.h.

149 { return myPtr.unique(); }
CountedPtr< T > myPtr
Definition: CowPtr.h:156

Field Documentation

template<typename T>
CountedPtr<T> DGtal::CowPtr< T >::myPtr
private

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