STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stxxl::counting_ptr< Type > Class Template Reference

Detailed Description

template<class Type>
class stxxl::counting_ptr< Type >

High-performance smart pointer used as a wrapping reference counting pointer.

This smart pointer class requires two functions in the templated type: void inc_reference() and void dec_reference(). These must increment and decrement a reference counter inside the templated object. When initialized, the type must have reference count zero. It is not immediately called with add_reference(). Each new object referencing the data calls add_reference() and each destroying holder calls del_reference(). When the data object determines that it's internal counter is zero, then it must destroy itself.

Accompanying the counting_ptr is a const_counting_ptr and a class counted_object, from which reference counted classes must be derive from. The class counted_object implement all methods required for reference counting.

The whole method is more similar to boost' instrusive_ptr, but also yields something resembling shared_ptr.

Definition at line 50 of file counting_ptr.h.

+ Inheritance diagram for stxxl::counting_ptr< Type >:

Public Types

typedef Type element_type
 contained type. More...
 

Public Member Functions

 counting_ptr ()
 default constructor: contains a NULL pointer. More...
 
 counting_ptr (Type *ptr)
 constructor with pointer: initializes new reference to ptr. More...
 
 counting_ptr (const counting_ptr &other_ptr)
 copy-constructor: also initializes new reference to ptr. More...
 
 ~counting_ptr ()
 destructor: decrements reference counter in ptr. More...
 
bool empty () const
 test for a NULL pointer More...
 
Type * get () const
 return the enclosed pointer. More...
 
 operator bool () const
 cast to bool check for a NULL pointer More...
 
 operator Type * () const
 implicit cast to the enclosed pointer. More...
 
bool operator!= (const counting_ptr &other_ptr) const
 test inequality of only the pointer values. More...
 
Type & operator* () const
 return the enclosed object as reference. More...
 
Type * operator-> () const
 return the enclosed pointer. More...
 
counting_ptroperator= (const counting_ptr &other_ptr)
 assignment operator: dereference current object and acquire reference on new one. More...
 
counting_ptroperator= (Type *ptr)
 assignment to pointer: dereference current and acquire reference to new ptr. More...
 
bool operator== (const counting_ptr &other_ptr) const
 test equality of only the pointer values. More...
 
void swap (counting_ptr &b)
 swap enclosed object with another counting pointer (no reference counts need change) More...
 
void unify ()
 make and refer a copy if the original object was shared. More...
 
bool unique () const
 if the object is referred by this counting_ptr only More...
 
bool valid () const
 test for a non-NULL pointer More...
 

Protected Member Functions

void dec_reference ()
 decrement reference counter of current object and maybe delete it. More...
 
void inc_reference ()
 increment reference counter for current object. More...
 
void inc_reference (Type *o)
 increment reference counter of other object. More...
 

Private Attributes

Type * m_ptr
 the pointer to the currently referenced object. More...
 

Member Typedef Documentation

template<class Type>
typedef Type stxxl::counting_ptr< Type >::element_type

contained type.

Definition at line 54 of file counting_ptr.h.

Constructor & Destructor Documentation

template<class Type>
stxxl::counting_ptr< Type >::counting_ptr ( )
inline

default constructor: contains a NULL pointer.

Definition at line 75 of file counting_ptr.h.

template<class Type>
stxxl::counting_ptr< Type >::counting_ptr ( Type *  ptr)
inline

constructor with pointer: initializes new reference to ptr.

Definition at line 79 of file counting_ptr.h.

template<class Type>
stxxl::counting_ptr< Type >::counting_ptr ( const counting_ptr< Type > &  other_ptr)
inline

copy-constructor: also initializes new reference to ptr.

Definition at line 83 of file counting_ptr.h.

template<class Type>
stxxl::counting_ptr< Type >::~counting_ptr ( )
inline

destructor: decrements reference counter in ptr.

Definition at line 100 of file counting_ptr.h.

Member Function Documentation

template<class Type>
void stxxl::counting_ptr< Type >::dec_reference ( )
inlineprotected

decrement reference counter of current object and maybe delete it.

Definition at line 70 of file counting_ptr.h.

template<class Type>
void stxxl::counting_ptr< Type >::inc_reference ( )
inlineprotected

increment reference counter for current object.

Definition at line 62 of file counting_ptr.h.

template<class Type>
void stxxl::counting_ptr< Type >::inc_reference ( Type *  o)
inlineprotected

increment reference counter of other object.

Definition at line 66 of file counting_ptr.h.

template<class Type>
stxxl::counting_ptr< Type >::operator bool ( ) const
inline

cast to bool check for a NULL pointer

Definition at line 134 of file counting_ptr.h.

template<class Type>
stxxl::counting_ptr< Type >::operator Type * ( ) const
inline

implicit cast to the enclosed pointer.

Definition at line 118 of file counting_ptr.h.

template<class Type>
bool stxxl::counting_ptr< Type >::operator!= ( const counting_ptr< Type > &  other_ptr) const
inline

test inequality of only the pointer values.

Definition at line 130 of file counting_ptr.h.

template<class Type>
Type& stxxl::counting_ptr< Type >::operator* ( ) const
inline

return the enclosed object as reference.

Definition at line 104 of file counting_ptr.h.

template<class Type>
Type* stxxl::counting_ptr< Type >::operator-> ( ) const
inline

return the enclosed pointer.

Definition at line 111 of file counting_ptr.h.

template<class Type>
counting_ptr& stxxl::counting_ptr< Type >::operator= ( const counting_ptr< Type > &  other_ptr)
inline

assignment operator: dereference current object and acquire reference on new one.

Definition at line 87 of file counting_ptr.h.

template<class Type>
counting_ptr& stxxl::counting_ptr< Type >::operator= ( Type *  ptr)
inline

assignment to pointer: dereference current and acquire reference to new ptr.

Definition at line 91 of file counting_ptr.h.

template<class Type>
bool stxxl::counting_ptr< Type >::operator== ( const counting_ptr< Type > &  other_ptr) const
inline

test equality of only the pointer values.

Definition at line 126 of file counting_ptr.h.

template<class Type>
void stxxl::counting_ptr< Type >::swap ( counting_ptr< Type > &  b)
inline

swap enclosed object with another counting pointer (no reference counts need change)

Definition at line 157 of file counting_ptr.h.

Referenced by stxxl::swap().

template<class Type>
void stxxl::counting_ptr< Type >::unify ( )
inline

make and refer a copy if the original object was shared.

Definition at line 150 of file counting_ptr.h.

template<class Type>
bool stxxl::counting_ptr< Type >::unique ( ) const
inline

if the object is referred by this counting_ptr only

Definition at line 146 of file counting_ptr.h.

Member Data Documentation


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