DGtal
1.5.beta
|
Aim: Smart pointer based on reference counts. More...
#include <DGtal/base/CountedPtr.h>
Data Structures | |
struct | Counter |
Public Member Functions | |
CountedPtr (T *p=0) | |
~CountedPtr () | |
CountedPtr (const CountedPtr &r) noexcept | |
CountedPtr & | operator= (const CountedPtr &r) |
T & | operator* () const noexcept |
T * | operator-> () const noexcept |
T * | get () const noexcept |
bool | unique () const noexcept |
bool | operator== (const T *other) const |
bool | operator!= (const T *other) const |
unsigned int | count () const |
T * | drop () |
void | selfDisplay (std::ostream &out) const |
bool | isValid () const |
Private Member Functions | |
void | acquire (Counter *c) noexcept |
void | release () |
Private Attributes | |
Counter * | myCounter |
The counter object pointed by this smart pointer. More... | |
Friends | |
class | CountedPtrOrPtr< T > |
Friend class which needs to access to CountedPtr.myCounter. More... | |
class | CountedConstPtrOrConstPtr< T > |
Friend class which needs to access to CountedPtr.myCounter. More... | |
Aim: Smart pointer based on reference counts.
Description of template class 'CountedPtr'
It is a standard smart pointer by reference counts. Of course, only dynamically allocated objects may be pointed by a smart pointer. The CountedPtr<T> holds a pointer to a CountedPtr::Counter object. This Counter object holds the pointer to the dynamically allocated object and an integer representing the number of smart pointers currently pointing to this Counter.
T | any data type. |
Taken from http://ootips.org/yonat/4dev/smart-pointers.html
Definition at line 79 of file CountedPtr.h.
|
inlineexplicit |
Default Constructor and constructor from pointer.
Creates a new CountedPtr, either null if p is 0 or pointing to the given address p.
p | either 0 or a pointer on a dynamically allocated object of type T. |
Definition at line 119 of file CountedPtr.h.
References DGtal::CountedPtr< T >::myCounter.
|
inline |
Destructor. If it was the last CountedPtr pointing on the object, delete it.
Definition at line 128 of file CountedPtr.h.
References DGtal::CountedPtr< T >::release().
|
inlinenoexcept |
Copy Constructor.
Performs a smart copy. The CountedPtr only references the same object as r. There is now one more reference on the same object.
r | the object to copy. |
Definition at line 142 of file CountedPtr.h.
References DGtal::CountedPtr< T >::acquire().
|
inlineprivatenoexcept |
Tells this smart pointer that it should reference the counter c. If c is not null, the number of reference counts is incremented.
c | any counter (except this.myCounter). |
Definition at line 265 of file CountedPtr.h.
References DGtal::CountedPtr< T >::Counter::count, and DGtal::CountedPtr< T >::myCounter.
Referenced by DGtal::CountedPtr< T >::CountedPtr(), and DGtal::CountedPtr< T >::operator=().
|
inline |
Definition at line 236 of file CountedPtr.h.
References DGtal::CountedPtr< T >::Counter::count, and DGtal::CountedPtr< T >::myCounter.
Referenced by testCountedConstPtrOrConstPtrMemory(), testCountedPtrMemory(), and testCountedPtrOrPtrMemory().
|
inline |
Gives back the pointer without deleting him. Deletes only the Counter.
Definition at line 249 of file CountedPtr.h.
References DGtal::CountedPtr< T >::isValid(), DGtal::CountedPtr< T >::myCounter, DGtal::CountedPtr< T >::Counter::ptr, and DGtal::CountedPtr< T >::unique().
|
inlinenoexcept |
Secured member access operator.
Definition at line 195 of file CountedPtr.h.
References DGtal::CountedPtr< T >::myCounter, and DGtal::CountedPtr< T >::Counter::ptr.
Referenced by DGtal::CountedPtr< T >::operator!=(), DGtal::GraphVisitorRange< TGraphVisitor >::GenericConstIterator< TAccessor >::operator*(), DGtal::GraphVisitorRange< TGraphVisitor >::GenericConstIterator< TAccessor >::operator->(), DGtal::GraphVisitorRange< TGraphVisitor >::GenericConstIterator< TAccessor >::operator==(), DGtal::CountedPtr< T >::operator==(), testCountedConstPtrOrConstPtrMemory(), testCountedPtrMemory(), and testCountedPtrOrPtrMemory().
bool DGtal::CountedPtr< T >::isValid | ( | ) | const |
Checks the validity/consistency of the object.
Referenced by DGtal::CountedPtr< T >::drop().
|
inline |
Inequality operator !=
other | any other pointer. |
Definition at line 226 of file CountedPtr.h.
References DGtal::CountedPtr< T >::get().
|
inlinenoexcept |
Dereferencing operator.
Definition at line 174 of file CountedPtr.h.
References DGtal::CountedPtr< T >::myCounter, and DGtal::CountedPtr< T >::Counter::ptr.
|
inlinenoexcept |
Member access operator.
Definition at line 184 of file CountedPtr.h.
References DGtal::CountedPtr< T >::myCounter, and DGtal::CountedPtr< T >::Counter::ptr.
|
inline |
Assignment.
Performs a smart assignment. The current referenced object is dropped (and possibly freed if it was the last smart pointer pointing on it). Then, this CountedPtr only references the same object as r. There is now one more reference on the same object.
r | the object to copy. |
Definition at line 159 of file CountedPtr.h.
References DGtal::CountedPtr< T >::acquire(), and DGtal::CountedPtr< T >::release().
|
inline |
Equality operator ==
other | any other pointer. |
Definition at line 215 of file CountedPtr.h.
References DGtal::CountedPtr< T >::get().
|
inlineprivate |
Tells this smart pointer to that it should release its current counter. If this counter was shared then the number of reference counts is decremented, else both the object pointed by the counter and the counter are freed. In all cases, this smart pointer becomes invalid.
Definition at line 278 of file CountedPtr.h.
References DGtal::CountedPtr< T >::Counter::count, DGtal::CountedPtr< T >::myCounter, and DGtal::CountedPtr< T >::Counter::ptr.
Referenced by DGtal::CountedPtr< T >::operator=(), and DGtal::CountedPtr< T >::~CountedPtr().
void DGtal::CountedPtr< T >::selfDisplay | ( | std::ostream & | out | ) | const |
Writes/Displays the object on an output stream.
out | the output stream where the object is written. |
|
inlinenoexcept |
Definition at line 204 of file CountedPtr.h.
References DGtal::CountedPtr< T >::Counter::count, and DGtal::CountedPtr< T >::myCounter.
Referenced by DGtal::CountedPtr< T >::drop().
|
friend |
Friend class which needs to access to CountedPtr.myCounter.
Definition at line 330 of file CountedPtr.h.
|
friend |
Friend class which needs to access to CountedPtr.myCounter.
Definition at line 330 of file CountedPtr.h.
|
private |
The counter object pointed by this smart pointer.
Definition at line 308 of file CountedPtr.h.
Referenced by DGtal::CountedPtr< T >::acquire(), DGtal::CountedPtr< T >::count(), DGtal::CountedPtr< T >::CountedPtr(), DGtal::CountedPtr< T >::drop(), DGtal::CountedPtr< T >::get(), DGtal::CountedPtr< T >::operator*(), DGtal::CountedPtr< T >::operator->(), DGtal::CountedPtr< T >::release(), and DGtal::CountedPtr< T >::unique().