STXXL
1.4.1
|
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.
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 54 of file counting_ptr.h.
|
inline |
default constructor: contains a NULL pointer.
Definition at line 75 of file counting_ptr.h.
|
inline |
constructor with pointer: initializes new reference to ptr.
Definition at line 79 of file counting_ptr.h.
|
inline |
copy-constructor: also initializes new reference to ptr.
Definition at line 83 of file counting_ptr.h.
|
inline |
destructor: decrements reference counter in ptr.
Definition at line 100 of file counting_ptr.h.
|
inlineprotected |
decrement reference counter of current object and maybe delete it.
Definition at line 70 of file counting_ptr.h.
|
inline |
test for a NULL pointer
Definition at line 142 of file counting_ptr.h.
Referenced by stxxl::request_queue_impl_1q::add_request(), stxxl::request_queue_impl_qwqr::add_request(), stxxl::linuxaio_queue::add_request(), stxxl::request_queue_impl_1q::cancel_request(), stxxl::request_queue_impl_qwqr::cancel_request(), and stxxl::linuxaio_queue::cancel_request().
|
inline |
return the enclosed pointer.
Definition at line 122 of file counting_ptr.h.
Referenced by stxxl::disk_queues::add_request(), stxxl::request_queue_impl_1q::add_request(), stxxl::request_queue_impl_qwqr::add_request(), stxxl::linuxaio_queue::add_request(), stxxl::request_queue_impl_1q::cancel_request(), stxxl::request_queue_impl_qwqr::cancel_request(), stxxl::linuxaio_queue::cancel_request(), stxxl::const_counting_ptr< Type >::operator!=(), stxxl::const_counting_ptr< Type >::operator=(), stxxl::const_counting_ptr< Type >::operator==(), stxxl::linuxaio_queue::post_requests(), stxxl::request_queue_impl_1q::worker(), and stxxl::request_queue_impl_qwqr::worker().
|
inlineprotected |
increment reference counter for current object.
Definition at line 62 of file counting_ptr.h.
|
inlineprotected |
increment reference counter of other object.
Definition at line 66 of file counting_ptr.h.
|
inline |
cast to bool check for a NULL pointer
Definition at line 134 of file counting_ptr.h.
|
inline |
implicit cast to the enclosed pointer.
Definition at line 118 of file counting_ptr.h.
|
inline |
test inequality of only the pointer values.
Definition at line 130 of file counting_ptr.h.
|
inline |
return the enclosed object as reference.
Definition at line 104 of file counting_ptr.h.
|
inline |
return the enclosed pointer.
Definition at line 111 of file counting_ptr.h.
|
inline |
assignment operator: dereference current object and acquire reference on new one.
Definition at line 87 of file counting_ptr.h.
|
inline |
assignment to pointer: dereference current and acquire reference to new ptr.
Definition at line 91 of file counting_ptr.h.
|
inline |
test equality of only the pointer values.
Definition at line 126 of file counting_ptr.h.
|
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().
|
inline |
make and refer a copy if the original object was shared.
Definition at line 150 of file counting_ptr.h.
|
inline |
if the object is referred by this counting_ptr only
Definition at line 146 of file counting_ptr.h.
|
inline |
test for a non-NULL pointer
Definition at line 138 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 58 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().