DGtal
1.5.beta
|
Aim: Smart or simple const 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/CountedConstPtrOrConstPtr.h>
Public Types | |
typedef CountedPtr< T >::Counter | Counter |
The counter is the same as CountedPtr. More... | |
Public Member Functions | |
CountedConstPtrOrConstPtr (const T *p=0, bool isCountedPtr=true) | |
~CountedConstPtrOrConstPtr () | |
CountedConstPtrOrConstPtr (const CountedPtr< T > &r) noexcept | |
CountedConstPtrOrConstPtr (const CountedConstPtrOrConstPtr &r) noexcept | |
CountedConstPtrOrConstPtr (const CountedPtrOrPtr< T > &r) noexcept | |
CountedConstPtrOrConstPtr & | operator= (const CountedConstPtrOrConstPtr &r) |
CountedConstPtrOrConstPtr & | operator= (const CountedPtrOrPtr< T > &r) |
CountedConstPtrOrConstPtr & | operator= (const CountedPtr< T > &r) |
bool | isSmart () const |
bool | isSimple () const |
bool | operator== (const T *other) const |
bool | operator!= (const T *other) const |
const T & | operator* () const noexcept |
const T * | operator-> () const noexcept |
const T * | get () const noexcept |
bool | unique () const noexcept |
unsigned int | count () const |
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... | |
Aim: Smart or simple const 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 'CountedConstPtrOrConstPtr'
This object is useful when instantiating from a ConstAlias<T> object, letting the user specifies 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 const-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 a ConstAlias parameter.
T | any data type. |
Definition at line 94 of file CountedConstPtrOrConstPtr.h.
typedef CountedPtr<T>::Counter DGtal::CountedConstPtrOrConstPtr< T >::Counter |
The counter is the same as CountedPtr.
Definition at line 102 of file CountedConstPtrOrConstPtr.h.
|
inlineexplicit |
Default Constructor and constructor from pointer. The created object is either a simple const pointer on p (not acquired) if isCountedPtr is false
, or a smart const 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 119 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< 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 135 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr, and DGtal::CountedConstPtrOrConstPtr< 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 147 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< 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 162 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::acquire(), DGtal::CountedConstPtrOrConstPtr< T >::myAny, and DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr.
|
inlinenoexcept |
Constructor from CountedPtrOrPtr. 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 180 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::acquire(), DGtal::CountedConstPtrOrConstPtr< T >::myAny, and DGtal::CountedConstPtrOrConstPtr< 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 420 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::myAny, and DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr.
Referenced by DGtal::CountedConstPtrOrConstPtr< T >::CountedConstPtrOrConstPtr(), and DGtal::CountedConstPtrOrConstPtr< T >::operator=().
|
inline |
Definition at line 351 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedPtr< T >::Counter::count, DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), and DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr.
Referenced by testCountedConstPtrOrConstPtrMemory().
|
inlineprivate |
Definition at line 394 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::myAny, and DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr.
Referenced by DGtal::CountedConstPtrOrConstPtr< T >::count(), DGtal::CountedConstPtrOrConstPtr< T >::drop(), DGtal::CountedConstPtrOrConstPtr< T >::get(), DGtal::CountedConstPtrOrConstPtr< T >::operator!=(), DGtal::CountedConstPtrOrConstPtr< T >::operator*(), DGtal::CountedConstPtrOrConstPtr< T >::operator->(), DGtal::CountedConstPtrOrConstPtr< T >::operator==(), DGtal::CountedConstPtrOrConstPtr< T >::release(), and DGtal::CountedConstPtrOrConstPtr< T >::unique().
|
inline |
Gives back the pointer without deleting him. Deletes only the Counter if 'this' was smart.
Definition at line 366 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), DGtal::CountedConstPtrOrConstPtr< T >::isValid(), DGtal::CountedConstPtrOrConstPtr< T >::myAny, DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr, DGtal::CountedConstPtrOrConstPtr< T >::ptr(), DGtal::CountedPtr< T >::Counter::ptr, and DGtal::CountedConstPtrOrConstPtr< T >::unique().
|
inlinenoexcept |
Secured member access operator.
Definition at line 327 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), DGtal::CountedConstPtrOrConstPtr< T >::myAny, DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr, DGtal::CountedConstPtrOrConstPtr< T >::ptr(), and DGtal::CountedPtr< T >::Counter::ptr.
Referenced by testCountedConstPtrOrConstPtrMemory().
|
inline |
Definition at line 262 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr.
Referenced by testCountedConstPtrOrConstPtrMemory().
|
inline |
Definition at line 254 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr.
Referenced by testCountedConstPtrOrConstPtrMemory().
bool DGtal::CountedConstPtrOrConstPtr< T >::isValid | ( | ) | const |
Checks the validity/consistency of the object.
Referenced by DGtal::CountedConstPtrOrConstPtr< T >::drop(), DGtal::CountedConstPtrOrConstPtr< T >::operator*(), and DGtal::CountedConstPtrOrConstPtr< T >::operator->().
|
inline |
Inequality operator !=
other | any other pointer. |
Definition at line 284 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), DGtal::CountedConstPtrOrConstPtr< T >::myAny, DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr, DGtal::CountedConstPtrOrConstPtr< T >::ptr(), and DGtal::CountedPtr< T >::Counter::ptr.
|
inlinenoexcept |
Dereferencing operator.
Definition at line 297 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), DGtal::CountedConstPtrOrConstPtr< T >::isValid(), DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr, DGtal::CountedConstPtrOrConstPtr< T >::ptr(), and DGtal::CountedPtr< T >::Counter::ptr.
|
inlinenoexcept |
Member access operator.
Definition at line 313 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), DGtal::CountedConstPtrOrConstPtr< T >::isValid(), DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr, DGtal::CountedConstPtrOrConstPtr< T >::ptr(), and DGtal::CountedPtr< T >::Counter::ptr.
|
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 201 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::acquire(), DGtal::CountedConstPtrOrConstPtr< T >::myAny, DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr, and DGtal::CountedConstPtrOrConstPtr< T >::release().
|
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 243 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::acquire(), DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr, and DGtal::CountedConstPtrOrConstPtr< T >::release().
|
inline |
Assignment with CountedPtrOrPtr. 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 224 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::acquire(), DGtal::CountedConstPtrOrConstPtr< T >::myAny, DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr, and DGtal::CountedConstPtrOrConstPtr< T >::release().
|
inline |
Equality operator ==
other | any other pointer. |
Definition at line 273 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), DGtal::CountedConstPtrOrConstPtr< T >::myAny, DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr, DGtal::CountedConstPtrOrConstPtr< T >::ptr(), and DGtal::CountedPtr< T >::Counter::ptr.
|
inlineprivate |
Definition at line 406 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::myAny, and DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr.
Referenced by DGtal::CountedConstPtrOrConstPtr< T >::drop(), DGtal::CountedConstPtrOrConstPtr< T >::get(), DGtal::CountedConstPtrOrConstPtr< T >::operator!=(), DGtal::CountedConstPtrOrConstPtr< T >::operator*(), DGtal::CountedConstPtrOrConstPtr< T >::operator->(), and DGtal::CountedConstPtrOrConstPtr< 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 436 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), DGtal::CountedConstPtrOrConstPtr< T >::myAny, and DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr.
Referenced by DGtal::CountedConstPtrOrConstPtr< T >::operator=(), and DGtal::CountedConstPtrOrConstPtr< T >::~CountedConstPtrOrConstPtr().
void DGtal::CountedConstPtrOrConstPtr< 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 337 of file CountedConstPtrOrConstPtr.h.
References DGtal::CountedPtr< T >::Counter::count, DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), DGtal::CountedConstPtrOrConstPtr< T >::myAny, and DGtal::CountedConstPtrOrConstPtr< T >::myIsCountedPtr.
Referenced by DGtal::CountedConstPtrOrConstPtr< T >::drop().
|
private |
If smart, the counter object pointed by 'this', or if simple, the address of the object pointed by 'this'.
Definition at line 384 of file CountedConstPtrOrConstPtr.h.
Referenced by DGtal::CountedConstPtrOrConstPtr< T >::acquire(), DGtal::CountedConstPtrOrConstPtr< T >::CountedConstPtrOrConstPtr(), DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), DGtal::CountedConstPtrOrConstPtr< T >::drop(), DGtal::CountedConstPtrOrConstPtr< T >::get(), DGtal::CountedConstPtrOrConstPtr< T >::operator!=(), DGtal::CountedConstPtrOrConstPtr< T >::operator=(), DGtal::CountedConstPtrOrConstPtr< T >::operator==(), DGtal::CountedConstPtrOrConstPtr< T >::ptr(), DGtal::CountedConstPtrOrConstPtr< T >::release(), and DGtal::CountedConstPtrOrConstPtr< T >::unique().
|
private |
If true
, 'this' pointer object is smart, otherwise it is simple.
Definition at line 386 of file CountedConstPtrOrConstPtr.h.
Referenced by DGtal::CountedConstPtrOrConstPtr< T >::acquire(), DGtal::CountedConstPtrOrConstPtr< T >::count(), DGtal::CountedConstPtrOrConstPtr< T >::CountedConstPtrOrConstPtr(), DGtal::CountedConstPtrOrConstPtr< T >::counterPtr(), DGtal::CountedConstPtrOrConstPtr< T >::drop(), DGtal::CountedConstPtrOrConstPtr< T >::get(), DGtal::CountedConstPtrOrConstPtr< T >::isSimple(), DGtal::CountedConstPtrOrConstPtr< T >::isSmart(), DGtal::CountedConstPtrOrConstPtr< T >::operator!=(), DGtal::CountedConstPtrOrConstPtr< T >::operator*(), DGtal::CountedConstPtrOrConstPtr< T >::operator->(), DGtal::CountedConstPtrOrConstPtr< T >::operator=(), DGtal::CountedConstPtrOrConstPtr< T >::operator==(), DGtal::CountedConstPtrOrConstPtr< T >::ptr(), DGtal::CountedConstPtrOrConstPtr< T >::release(), DGtal::CountedConstPtrOrConstPtr< T >::unique(), and DGtal::CountedConstPtrOrConstPtr< T >::~CountedConstPtrOrConstPtr().