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

Detailed Description

template<class Type>
class stxxl::const_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 191 of file counting_ptr.h.

Public Types

typedef Type element_type
 contained type. More...
 

Public Member Functions

 const_counting_ptr ()
 default constructor: contains a NULL pointer. More...
 
 const_counting_ptr (const Type *ptr)
 constructor with pointer: initializes new reference to ptr. More...
 
 const_counting_ptr (const const_counting_ptr &other_ptr)
 copy-constructor: also initializes new reference to ptr. More...
 
 const_counting_ptr (const counting_ptr< Type > &other_ptr)
 constructor from non-const: also initializes new reference to ptr. More...
 
 ~const_counting_ptr ()
 destructor: decrements reference counter in ptr. More...
 
bool empty () const
 test for a NULL pointer More...
 
const Type * get () const
 return the enclosed pointer. More...
 
 operator bool () const
 cast to bool check for a NULL pointer More...
 
 operator const Type * () const
 implicit cast to the enclosed pointer. More...
 
bool operator!= (const const_counting_ptr &other_ptr) const
 test inequality of only the pointer values. More...
 
bool operator!= (const counting_ptr< Type > &other_ptr) const
 test inequality of only the pointer values. More...
 
const Type & operator* () const
 return the enclosed object as reference. More...
 
const Type * operator-> () const
 return the enclosed pointer. More...
 
const_counting_ptroperator= (const const_counting_ptr &other_ptr)
 assignment operator: dereference current object and acquire reference on new one. More...
 
const_counting_ptroperator= (const counting_ptr< Type > &other_ptr)
 assignment operator: dereference current object and acquire reference on new one. More...
 
const_counting_ptroperator= (const Type *ptr)
 assignment to pointer: dereference current and acquire reference to new ptr. More...
 
bool operator== (const const_counting_ptr &other_ptr) const
 test equality of only the pointer values. More...
 
bool operator== (const counting_ptr< Type > &other_ptr) const
 test equality of only the pointer values. More...
 
void swap (const_counting_ptr &b)
 swap enclosed object with another const_counting pointer (no reference counts need change) More...
 
bool unique () const
 if the object is referred by this const_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 (const Type *o)
 increment reference counter of other object. More...
 

Private Attributes

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

Member Typedef Documentation

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

contained type.

Definition at line 195 of file counting_ptr.h.

Constructor & Destructor Documentation

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

default constructor: contains a NULL pointer.

Definition at line 216 of file counting_ptr.h.

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

constructor with pointer: initializes new reference to ptr.

Definition at line 220 of file counting_ptr.h.

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

copy-constructor: also initializes new reference to ptr.

Definition at line 224 of file counting_ptr.h.

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

constructor from non-const: also initializes new reference to ptr.

Definition at line 228 of file counting_ptr.h.

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

destructor: decrements reference counter in ptr.

Definition at line 249 of file counting_ptr.h.

Member Function Documentation

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

decrement reference counter of current object and maybe delete it.

Definition at line 211 of file counting_ptr.h.

template<class Type>
bool stxxl::const_counting_ptr< Type >::empty ( ) const
inline

test for a NULL pointer

Definition at line 299 of file counting_ptr.h.

template<class Type>
const Type* stxxl::const_counting_ptr< Type >::get ( ) const
inline

return the enclosed pointer.

Definition at line 271 of file counting_ptr.h.

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

increment reference counter for current object.

Definition at line 203 of file counting_ptr.h.

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

increment reference counter of other object.

Definition at line 207 of file counting_ptr.h.

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

cast to bool check for a NULL pointer

Definition at line 291 of file counting_ptr.h.

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

implicit cast to the enclosed pointer.

Definition at line 267 of file counting_ptr.h.

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

test inequality of only the pointer values.

Definition at line 279 of file counting_ptr.h.

References stxxl::const_counting_ptr< Type >::m_ptr.

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

test inequality of only the pointer values.

Definition at line 287 of file counting_ptr.h.

References stxxl::counting_ptr< Type >::get().

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

return the enclosed object as reference.

Definition at line 253 of file counting_ptr.h.

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

return the enclosed pointer.

Definition at line 260 of file counting_ptr.h.

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

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

Definition at line 232 of file counting_ptr.h.

References stxxl::const_counting_ptr< Type >::m_ptr.

template<class Type>
const_counting_ptr& stxxl::const_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 236 of file counting_ptr.h.

References stxxl::counting_ptr< Type >::get().

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

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

Definition at line 240 of file counting_ptr.h.

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

test equality of only the pointer values.

Definition at line 275 of file counting_ptr.h.

References stxxl::const_counting_ptr< Type >::m_ptr.

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

test equality of only the pointer values.

Definition at line 283 of file counting_ptr.h.

References stxxl::counting_ptr< Type >::get().

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

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

Definition at line 307 of file counting_ptr.h.

References stxxl::const_counting_ptr< Type >::m_ptr.

Referenced by stxxl::swap().

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

if the object is referred by this const_counting_ptr only

Definition at line 303 of file counting_ptr.h.

template<class Type>
bool stxxl::const_counting_ptr< Type >::valid ( ) const
inline

test for a non-NULL pointer

Definition at line 295 of file counting_ptr.h.

Member Data Documentation

template<class Type>
const Type* stxxl::const_counting_ptr< Type >::m_ptr
private

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