DGtal
1.5.beta
|
Aim: Smart or simple pointer on T. It can be a smart pointer based on reference counts or a simple pointer on T depending either on a boolean value given at construction or on the constructor used. In the first case, we will call this pointer object smart, otherwise we will call it simple. More...
#include <DGtal/base/CountedPtrOrPtr.h>
Public Types | |
typedef CountedPtr< T >::Counter | Counter |
The counter is the same as CountedPtr. More... | |
Public Member Functions | |
CountedPtrOrPtr (T *p=0, bool isCountedPtr=true) | |
~CountedPtrOrPtr () | |
CountedPtrOrPtr (const CountedPtr< T > &r) noexcept | |
CountedPtrOrPtr (const CountedPtrOrPtr &r) noexcept | |
CountedPtrOrPtr & | operator= (const CountedPtrOrPtr &r) |
CountedPtrOrPtr & | operator= (const CountedPtr< T > &r) |
bool | isSmart () const |
bool | isSimple () const |
bool | operator== (const T *other) const |
bool | operator!= (const T *other) const |
T & | operator* () const noexcept |
T * | operator-> () const noexcept |
T * | get () const noexcept |
bool | unique () const noexcept |
unsigned int | count () const |
T * | drop () |
void | selfDisplay (std::ostream &out) const |
bool | isValid () const |
Private Member Functions | |
Counter * | counterPtr () const |
T * | ptr () const |
void | acquire (Counter *c) noexcept |
void | release () |
Private Attributes | |
void * | myAny |
bool | myIsCountedPtr |
If true , 'this' pointer object is smart, otherwise it is simple. More... | |
Friends | |
class | CountedConstPtrOrConstPtr< T > |
Aim: Smart or simple pointer on T. It can be a smart pointer based on reference counts or a simple pointer on T depending either on a boolean value given at construction or on the constructor used. In the first case, we will call this pointer object smart, otherwise we will call it simple.
Description of template class 'CountedPtrOrPtr'
This object is useful when instantiating from an Alias<T> object, letting the user specify if it uses smart pointers or simply pointers. This class should be used as a meta-type for data members, when the programmer wants to hold a reference to some object during some period, but also wants to let the user decides whether the class should keep a smart reference or non-smart reference to the object. How and where to use such smart pointers is explained in User passing an argument to an Alias parameter.
T | any data type. |
Definition at line 95 of file CountedPtrOrPtr.h.
typedef CountedPtr<T>::Counter DGtal::CountedPtrOrPtr< T >::Counter |
The counter is the same as CountedPtr.
Definition at line 104 of file CountedPtrOrPtr.h.
|
inlineexplicit |
Default Constructor and constructor from pointer. The created object is either a simple pointer on p (not acquired) if isCountedPtr is false
, or a smart pointer based on reference counts (CountedPtr).
p | is a pointer to some object T. If isCountedPtr is true , then pointer p should point to some dynamically allocated object T, and the pointer is acquired. If isCountedPtr is false , then this object holds only the pointer p, without acquiring it. |
isCountedPtr | when 'true', stores p as a smart (counted) pointer, otherwise stores p directly. |
Definition at line 121 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::myAny.
|
inline |
Destructor. If this pointer object was smart, the pointed object is released (and possibly freed if the reference count was 1), otherwise, if this pointer object was simple, the destructor does nothing.
Definition at line 137 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::myIsCountedPtr, and DGtal::CountedPtrOrPtr< T >::release().
|
inlinenoexcept |
Constructor from smart pointer (CountedPtr) r. In this case, this pointer object is smart and acquire the given smart pointer.
r | the smart pointer to acquire. |
Definition at line 149 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::acquire().
|
inlinenoexcept |
Copy constructor. If r is smart, then this pointer object is also smart and acquires r (no duplication). Otherwise, if r is simple, then this pointer object only points at the same place.
r | the other pointer to clone, which may be smart or simple. |
Definition at line 164 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::acquire(), DGtal::CountedPtrOrPtr< T >::myAny, and DGtal::CountedPtrOrPtr< T >::myIsCountedPtr.
|
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 382 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::myAny, and DGtal::CountedPtrOrPtr< T >::myIsCountedPtr.
Referenced by DGtal::CountedPtrOrPtr< T >::CountedPtrOrPtr(), and DGtal::CountedPtrOrPtr< T >::operator=().
|
inline |
Definition at line 314 of file CountedPtrOrPtr.h.
References DGtal::CountedPtr< T >::Counter::count, DGtal::CountedPtrOrPtr< T >::counterPtr(), and DGtal::CountedPtrOrPtr< T >::myIsCountedPtr.
Referenced by testCountedConstPtrOrConstPtrMemory(), and testCountedPtrOrPtrMemory().
|
inlineprivate |
Definition at line 356 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::myAny, and DGtal::CountedPtrOrPtr< T >::myIsCountedPtr.
Referenced by DGtal::CountedPtrOrPtr< T >::count(), DGtal::CountedPtrOrPtr< T >::drop(), DGtal::CountedPtrOrPtr< T >::get(), DGtal::CountedPtrOrPtr< T >::operator!=(), DGtal::CountedPtrOrPtr< T >::operator*(), DGtal::CountedPtrOrPtr< T >::operator->(), DGtal::CountedPtrOrPtr< T >::operator==(), DGtal::CountedPtrOrPtr< T >::release(), and DGtal::CountedPtrOrPtr< T >::unique().
|
inline |
Gives back the pointer without deleting him. Deletes only the Counter if 'this' was smart.
Definition at line 329 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::counterPtr(), DGtal::CountedPtrOrPtr< T >::isValid(), DGtal::CountedPtrOrPtr< T >::myAny, DGtal::CountedPtrOrPtr< T >::myIsCountedPtr, DGtal::CountedPtr< T >::Counter::ptr, DGtal::CountedPtrOrPtr< T >::ptr(), and DGtal::CountedPtrOrPtr< T >::unique().
|
inlinenoexcept |
Secured member access operator.
Definition at line 290 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::counterPtr(), DGtal::CountedPtrOrPtr< T >::myAny, DGtal::CountedPtrOrPtr< T >::myIsCountedPtr, DGtal::CountedPtr< T >::Counter::ptr, and DGtal::CountedPtrOrPtr< T >::ptr().
Referenced by testCountedConstPtrOrConstPtrMemory(), and testCountedPtrOrPtrMemory().
|
inline |
Definition at line 225 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::myIsCountedPtr.
Referenced by testCountedPtrOrPtrMemory().
|
inline |
Definition at line 217 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::myIsCountedPtr.
Referenced by testCountedPtrOrPtrMemory().
bool DGtal::CountedPtrOrPtr< T >::isValid | ( | ) | const |
Checks the validity/consistency of the object.
Referenced by DGtal::CountedPtrOrPtr< T >::drop(), DGtal::CountedPtrOrPtr< T >::operator*(), and DGtal::CountedPtrOrPtr< T >::operator->().
|
inline |
Inequality operator !=
other | any other pointer. |
Definition at line 247 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::counterPtr(), DGtal::CountedPtrOrPtr< T >::myAny, DGtal::CountedPtrOrPtr< T >::myIsCountedPtr, DGtal::CountedPtr< T >::Counter::ptr, and DGtal::CountedPtrOrPtr< T >::ptr().
|
inlinenoexcept |
Dereferencing operator.
Definition at line 260 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::counterPtr(), DGtal::CountedPtrOrPtr< T >::isValid(), DGtal::CountedPtrOrPtr< T >::myIsCountedPtr, DGtal::CountedPtr< T >::Counter::ptr, and DGtal::CountedPtrOrPtr< T >::ptr().
|
inlinenoexcept |
Member access operator.
Definition at line 276 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::counterPtr(), DGtal::CountedPtrOrPtr< T >::isValid(), DGtal::CountedPtrOrPtr< T >::myIsCountedPtr, DGtal::CountedPtr< T >::Counter::ptr, and DGtal::CountedPtrOrPtr< T >::ptr().
|
inline |
Assignment with smart pointer (CountedPtr). If 'this' was smart, then the shared pointer is released. Then this pointer object becomes also smart and acquires r (no duplication).
r | the other smart pointer to clone. |
Definition at line 206 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::acquire(), DGtal::CountedPtrOrPtr< T >::myIsCountedPtr, and DGtal::CountedPtrOrPtr< T >::release().
|
inline |
Assignment. If 'this' was smart, then the shared pointer is released. Then, if r is smart, then this pointer object is also smart and acquires r (no duplication). Otherwise, if r is simple, then this pointer object only points at the same place.
r | the other pointer to clone, which may be smart or simple. |
Definition at line 185 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::acquire(), DGtal::CountedPtrOrPtr< T >::myAny, DGtal::CountedPtrOrPtr< T >::myIsCountedPtr, and DGtal::CountedPtrOrPtr< T >::release().
|
inline |
Equality operator ==
other | any other pointer. |
Definition at line 236 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::counterPtr(), DGtal::CountedPtrOrPtr< T >::myAny, DGtal::CountedPtrOrPtr< T >::myIsCountedPtr, DGtal::CountedPtr< T >::Counter::ptr, and DGtal::CountedPtrOrPtr< T >::ptr().
|
inlineprivate |
Definition at line 368 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::myAny, and DGtal::CountedPtrOrPtr< T >::myIsCountedPtr.
Referenced by DGtal::CountedPtrOrPtr< T >::drop(), DGtal::CountedPtrOrPtr< T >::get(), DGtal::CountedPtrOrPtr< T >::operator!=(), DGtal::CountedPtrOrPtr< T >::operator*(), DGtal::CountedPtrOrPtr< T >::operator->(), and DGtal::CountedPtrOrPtr< T >::operator==().
|
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 398 of file CountedPtrOrPtr.h.
References DGtal::CountedPtrOrPtr< T >::counterPtr(), DGtal::CountedPtrOrPtr< T >::myAny, and DGtal::CountedPtrOrPtr< T >::myIsCountedPtr.
Referenced by DGtal::CountedPtrOrPtr< T >::operator=(), and DGtal::CountedPtrOrPtr< T >::~CountedPtrOrPtr().
void DGtal::CountedPtrOrPtr< 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 300 of file CountedPtrOrPtr.h.
References DGtal::CountedPtr< T >::Counter::count, DGtal::CountedPtrOrPtr< T >::counterPtr(), DGtal::CountedPtrOrPtr< T >::myAny, and DGtal::CountedPtrOrPtr< T >::myIsCountedPtr.
Referenced by DGtal::CountedPtrOrPtr< T >::drop().
|
friend |
Definition at line 450 of file CountedPtrOrPtr.h.
|
private |
If smart, the counter object pointed by 'this', or if simple, the address of the object pointed by 'this'.
Definition at line 347 of file CountedPtrOrPtr.h.
Referenced by DGtal::CountedPtrOrPtr< T >::acquire(), DGtal::CountedPtrOrPtr< T >::CountedPtrOrPtr(), DGtal::CountedPtrOrPtr< T >::counterPtr(), DGtal::CountedPtrOrPtr< T >::drop(), DGtal::CountedPtrOrPtr< T >::get(), DGtal::CountedPtrOrPtr< T >::operator!=(), DGtal::CountedPtrOrPtr< T >::operator=(), DGtal::CountedPtrOrPtr< T >::operator==(), DGtal::CountedPtrOrPtr< T >::ptr(), DGtal::CountedPtrOrPtr< T >::release(), and DGtal::CountedPtrOrPtr< T >::unique().
|
private |
If true
, 'this' pointer object is smart, otherwise it is simple.
Definition at line 349 of file CountedPtrOrPtr.h.
Referenced by DGtal::CountedPtrOrPtr< T >::acquire(), DGtal::CountedPtrOrPtr< T >::count(), DGtal::CountedPtrOrPtr< T >::CountedPtrOrPtr(), DGtal::CountedPtrOrPtr< T >::counterPtr(), DGtal::CountedPtrOrPtr< T >::drop(), DGtal::CountedPtrOrPtr< T >::get(), DGtal::CountedPtrOrPtr< T >::isSimple(), DGtal::CountedPtrOrPtr< T >::isSmart(), DGtal::CountedPtrOrPtr< T >::operator!=(), DGtal::CountedPtrOrPtr< T >::operator*(), DGtal::CountedPtrOrPtr< T >::operator->(), DGtal::CountedPtrOrPtr< T >::operator=(), DGtal::CountedPtrOrPtr< T >::operator==(), DGtal::CountedPtrOrPtr< T >::ptr(), DGtal::CountedPtrOrPtr< T >::release(), DGtal::CountedPtrOrPtr< T >::unique(), and DGtal::CountedPtrOrPtr< T >::~CountedPtrOrPtr().