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

#include <CountedPtr.h>

Inheritance diagram for DGtal::CountedPtr< T >:
Inheritance graph
[legend]
Collaboration diagram for DGtal::CountedPtr< T >:
Collaboration graph
[legend]

Data Structures

struct  counter

Public Types

typedef T element_type

Public Member Functions

 CountedPtr (T *p=0)
 ~CountedPtr ()
 CountedPtr (const CountedPtr &r) throw ()
CountedPtroperator= (const CountedPtr &r)
T & operator* () const throw ()
T * operator-> () const throw ()
T * get () const throw ()
bool unique () const throw ()
unsigned int count () const
void selfDisplay (std::ostream &out) const
bool isValid () const

Private Member Functions

void acquire (counter *c) throw ()
void release ()

Private Attributes

struct DGtal::CountedPtr::countermyCounter

Detailed Description

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

Aim: Smart pointer based on reference counts.

Description of template class 'CountedPtr'

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

Definition at line 61 of file CountedPtr.h.


Member Typedef Documentation

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

Definition at line 66 of file CountedPtr.h.


Constructor & Destructor Documentation

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

Definition at line 68 of file CountedPtr.h.

: myCounter(0) { if (p) myCounter = new counter(p);}
template<typename T>
DGtal::CountedPtr< T >::~CountedPtr ( )
inline

Definition at line 70 of file CountedPtr.h.

{release();}
template<typename T>
DGtal::CountedPtr< T >::CountedPtr ( const CountedPtr< T > &  r) throw ()
inline

Definition at line 72 of file CountedPtr.h.


Member Function Documentation

template<typename T>
void DGtal::CountedPtr< T >::acquire ( counter c) throw ()
inlineprivate

Definition at line 101 of file CountedPtr.h.

Referenced by DGtal::CountedPtr< TImageContainer >::CountedPtr(), and DGtal::CountedPtr< TImageContainer >::operator=().

{ // increment the count
myCounter = c;
if (c) ++c->count;
}
template<typename T>
unsigned int DGtal::CountedPtr< T >::count ( ) const
inline

For debug.

Definition at line 92 of file CountedPtr.h.

{return myCounter->count;}
template<typename T>
T* DGtal::CountedPtr< T >::get ( ) const throw ()
inline
template<typename T >
bool DGtal::CountedPtr< T >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 67 of file CountedPtr.ih.

{
return myCounter;
}
template<typename T>
T& DGtal::CountedPtr< T >::operator* ( ) const throw ()
inline

Definition at line 83 of file CountedPtr.h.

{return *myCounter->ptr;}
template<typename T>
T* DGtal::CountedPtr< T >::operator-> ( ) const throw ()
inline

Definition at line 84 of file CountedPtr.h.

{return myCounter->ptr;}
template<typename T>
CountedPtr& DGtal::CountedPtr< T >::operator= ( const CountedPtr< T > &  r)
inline

Definition at line 74 of file CountedPtr.h.

{
if (this != &r) {
}
return *this;
}
template<typename T>
void DGtal::CountedPtr< T >::release ( )
inlineprivate

Definition at line 107 of file CountedPtr.h.

Referenced by DGtal::CountedPtr< TImageContainer >::operator=(), and DGtal::CountedPtr< TImageContainer >::~CountedPtr().

{ // decrement the count, delete if it is 0
if (myCounter) {
if (--myCounter->count == 0) {
delete myCounter->ptr;
delete myCounter;
}
myCounter = 0;
}
}
template<typename T >
void DGtal::CountedPtr< 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 CountedPtr.ih.

{
if (isValid())
out << "[CountedPtr nbcounts=" << myCounter->count << "]";
else
out << "[CountedPtr to NULL]";
}
template<typename T>
bool DGtal::CountedPtr< T >::unique ( ) const throw ()
inline

Definition at line 86 of file CountedPtr.h.

{return (myCounter ? myCounter->count == 1 : true);}

Field Documentation

template<typename T>
struct DGtal::CountedPtr::counter* DGtal::CountedPtr< T >::myCounter
private

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