STXXL
1.4.0
|
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 48 of file counting_ptr.h.
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_ptr & | operator= (const counting_ptr &other_ptr) |
assignment operator: dereference current object and acquire reference on new one. More... | |
counting_ptr & | operator= (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... | |
typedef Type stxxl::counting_ptr< Type >::element_type |
contained type.
Definition at line 52 of file counting_ptr.h.
|
inline |
default constructor: contains a NULL pointer.
Definition at line 73 of file counting_ptr.h.
|
inline |
constructor with pointer: initializes new reference to ptr.
Definition at line 77 of file counting_ptr.h.
|
inline |
copy-constructor: also initializes new reference to ptr.
Definition at line 81 of file counting_ptr.h.
|
inline |
destructor: decrements reference counter in ptr.
Definition at line 98 of file counting_ptr.h.
|
inlineprotected |
decrement reference counter of current object and maybe delete it.
Definition at line 68 of file counting_ptr.h.
|
inline |
test for a NULL pointer
Definition at line 140 of file counting_ptr.h.
Referenced by stxxl::request_queue_impl_1q::add_request(), stxxl::request_queue_impl_qwqr::add_request(), stxxl::request_queue_impl_1q::cancel_request(), and stxxl::request_queue_impl_qwqr::cancel_request().
|
inline |
return the enclosed pointer.
Definition at line 120 of file counting_ptr.h.
Referenced by stxxl::request_queue_impl_qwqr::add_request(), stxxl::request_queue_impl_qwqr::cancel_request(), stxxl::const_counting_ptr< Type >::operator!=(), stxxl::const_counting_ptr< Type >::operator=(), and stxxl::const_counting_ptr< Type >::operator==().
|
inlineprotected |
increment reference counter for current object.
Definition at line 60 of file counting_ptr.h.
|
inlineprotected |
increment reference counter of other object.
Definition at line 64 of file counting_ptr.h.
|
inline |
cast to bool check for a NULL pointer
Definition at line 132 of file counting_ptr.h.
|
inline |
implicit cast to the enclosed pointer.
Definition at line 116 of file counting_ptr.h.
|
inline |
test inequality of only the pointer values.
Definition at line 128 of file counting_ptr.h.
|
inline |
return the enclosed object as reference.
Definition at line 102 of file counting_ptr.h.
|
inline |
return the enclosed pointer.
Definition at line 109 of file counting_ptr.h.
|
inline |
assignment operator: dereference current object and acquire reference on new one.
Definition at line 85 of file counting_ptr.h.
|
inline |
assignment to pointer: dereference current and acquire reference to new ptr.
Definition at line 89 of file counting_ptr.h.
|
inline |
test equality of only the pointer values.
Definition at line 124 of file counting_ptr.h.
|
inline |
swap enclosed object with another counting pointer (no reference counts need change)
Definition at line 155 of file counting_ptr.h.
Referenced by stxxl::swap().
|
inline |
make and refer a copy if the original object was shared.
Definition at line 148 of file counting_ptr.h.
|
inline |
if the object is referred by this counting_ptr only
Definition at line 144 of file counting_ptr.h.
|
inline |
test for a non-NULL pointer
Definition at line 136 of file counting_ptr.h.
Referenced by stxxl::swappable_block< ValueType, BlockSideLength *BlockSideLength >::clean_sync(), stxxl::block_scheduler< SwappableBlockType >::flush(), and stxxl::block_scheduler_algorithm_offline_lru_prefetching< SwappableBlockType >::schedule_write().
|
private |
the pointer to the currently referenced object.
Definition at line 56 of file counting_ptr.h.
Referenced by stxxl::counting_ptr< sorted_runs_data_type >::operator!=(), stxxl::counting_ptr< sorted_runs_data_type >::operator=(), stxxl::counting_ptr< sorted_runs_data_type >::operator==(), and stxxl::counting_ptr< sorted_runs_data_type >::swap().