STXXL
1.4-dev
|
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_ptr & | operator= (const const_counting_ptr &other_ptr) |
assignment operator: dereference current object and acquire reference on new one. More... | |
const_counting_ptr & | operator= (const counting_ptr< Type > &other_ptr) |
assignment operator: dereference current object and acquire reference on new one. More... | |
const_counting_ptr & | operator= (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... | |
typedef Type stxxl::const_counting_ptr< Type >::element_type |
contained type.
Definition at line 195 of file counting_ptr.h.
|
inline |
default constructor: contains a NULL pointer.
Definition at line 216 of file counting_ptr.h.
|
inline |
constructor with pointer: initializes new reference to ptr.
Definition at line 220 of file counting_ptr.h.
|
inline |
copy-constructor: also initializes new reference to ptr.
Definition at line 224 of file counting_ptr.h.
|
inline |
constructor from non-const: also initializes new reference to ptr.
Definition at line 228 of file counting_ptr.h.
|
inline |
destructor: decrements reference counter in ptr.
Definition at line 249 of file counting_ptr.h.
|
inlineprotected |
decrement reference counter of current object and maybe delete it.
Definition at line 211 of file counting_ptr.h.
|
inline |
test for a NULL pointer
Definition at line 299 of file counting_ptr.h.
|
inline |
return the enclosed pointer.
Definition at line 271 of file counting_ptr.h.
|
inlineprotected |
increment reference counter for current object.
Definition at line 203 of file counting_ptr.h.
|
inlineprotected |
increment reference counter of other object.
Definition at line 207 of file counting_ptr.h.
|
inline |
cast to bool check for a NULL pointer
Definition at line 291 of file counting_ptr.h.
|
inline |
implicit cast to the enclosed pointer.
Definition at line 267 of file counting_ptr.h.
|
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.
|
inline |
test inequality of only the pointer values.
Definition at line 287 of file counting_ptr.h.
References stxxl::counting_ptr< Type >::get().
|
inline |
return the enclosed object as reference.
Definition at line 253 of file counting_ptr.h.
|
inline |
return the enclosed pointer.
Definition at line 260 of file counting_ptr.h.
|
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.
|
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().
|
inline |
assignment to pointer: dereference current and acquire reference to new ptr.
Definition at line 240 of file counting_ptr.h.
|
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.
|
inline |
test equality of only the pointer values.
Definition at line 283 of file counting_ptr.h.
References stxxl::counting_ptr< Type >::get().
|
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().
|
inline |
if the object is referred by this const_counting_ptr only
Definition at line 303 of file counting_ptr.h.
|
inline |
test for a non-NULL pointer
Definition at line 295 of file counting_ptr.h.
|
private |
the pointer to the currently referenced object.
Definition at line 199 of file counting_ptr.h.
Referenced by stxxl::const_counting_ptr< Type >::operator!=(), stxxl::const_counting_ptr< Type >::operator=(), stxxl::const_counting_ptr< Type >::operator==(), and stxxl::const_counting_ptr< Type >::swap().