DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::CowPtr< T > Class Template Reference

#include <CowPtr.h>

Inheritance diagram for DGtal::CowPtr< T >:
Inheritance graph
[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 ()
T & operator* ()
T * operator-> ()
T * get ()
unsigned int count () const
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 66 of file CowPtr.h.


Member Typedef Documentation

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

Definition at line 71 of file CowPtr.h.


Constructor & Destructor Documentation

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

Definition at line 73 of file CowPtr.h.

: myPtr(p) {}
template<typename T>
DGtal::CowPtr< T >::CowPtr ( const CowPtr< T > &  r) throw ()
inline

Definition at line 75 of file CowPtr.h.

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

Definition at line 79 of file CowPtr.h.

: myPtr( r ) {}

Member Function Documentation

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

Definition at line 110 of file CowPtr.h.

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

{
if (!myPtr.unique()) {
T* old_p = myPtr.get();
myPtr = CountedPtr<T>(new T(*old_p));
}
}
template<typename T>
unsigned int DGtal::CowPtr< T >::count ( ) const
inline

For debug.

Definition at line 99 of file CowPtr.h.

{return myPtr.count();}
template<typename T>
const T* DGtal::CowPtr< T >::get ( ) const throw ()
inline

Definition at line 90 of file CowPtr.h.

{return myPtr.get();}
template<typename T>
T* DGtal::CowPtr< T >::get ( )
inline

Definition at line 94 of file CowPtr.h.

{copy(); return myPtr.get();}
template<typename T >
bool DGtal::CowPtr< T >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 64 of file CowPtr.ih.

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

{
return myPtr->isValid();
}
template<typename T>
const T& DGtal::CowPtr< T >::operator* ( ) const throw ()
inline

Definition at line 88 of file CowPtr.h.

{return *myPtr;}
template<typename T>
T& DGtal::CowPtr< T >::operator* ( )
inline

Definition at line 92 of file CowPtr.h.

{copy(); return *myPtr;}
template<typename T>
const T* DGtal::CowPtr< T >::operator-> ( ) const throw ()
inline

Definition at line 89 of file CowPtr.h.

{return myPtr.get();}
template<typename T>
T* DGtal::CowPtr< T >::operator-> ( )
inline

Definition at line 93 of file CowPtr.h.

{copy(); return myPtr.get();}
template<typename T>
CowPtr& DGtal::CowPtr< T >::operator= ( const CowPtr< T > &  r)
inline

Definition at line 80 of file CowPtr.h.

{
if (this != &r)
myPtr = r.myPtr;
return *this;
}
template<typename T >
void DGtal::CowPtr< T >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 52 of file CowPtr.ih.

{
out << "[CowPtr " << myPtr << " ]";
}

Field Documentation

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

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