Referenced counted pointer for constant data. More...
#include <CountedPtr.h>
Classes | |
class | Deleter |
Helper class to make deletion of object optional. More... | |
Public Member Functions | |
CountedPtr () | |
This constructor allows for the creation of a null CountedPtr . | |
CountedPtr (t *val, Bool delit=True) | |
This constructor sets up a reference count for the val pointer. | |
template<typename TP > | |
CountedPtr (const CountedPtr< TP > &that) | |
This copy constructor allows CountedPtr s to be initialized from other CountedPtr s for which the pointer TP* is convertible to T*. | |
CountedPtr (const SHARED_PTR< t > &rep) | |
Create from a shared_ptr. | |
~CountedPtr () | |
This destructor only deletes the really stored data when it was initialized as deletable and the reference count is zero. | |
template<typename TP > | |
CountedPtr< t > & | operator= (const CountedPtr< TP > &that) |
This assignment operator allows CountedPtr s to be copied from other CountedPtr s for which the pointer TP* is convertible to t*. | |
void | reset (t *val, Bool delit=True) |
Reset the pointer. | |
void | reset () |
t & | operator* () const |
The CountedPtr indirection operator simply returns a reference to the value being protected. | |
t * | operator-> () const |
This dereferencing operator behaves as expected; it returns the pointer to the value being protected, and then its dereferencing operator will be invoked as appropriate. | |
t * | get () const |
Get the underlying pointer. | |
Bool | operator== (const CountedPtr< t > &other) const |
Equality operator which checks to see if two CountedPtr s are pointing at the same thing. | |
Bool | operator== (int ptr) const |
Bool | operator!= (const CountedPtr< t > &other) const |
Non-equality operator which checks to see if two CountedPtr s are not pointing at the same thing. | |
Bool | operator!= (int ptr) const |
CountedPtr< t > & | operator= (t *v) |
This assignment operator allows the object to which the current CountedPtr points to be changed. | |
template<typename U > | |
CountedPtr< U > | static_ptr_cast () const |
Cast functions. | |
template<typename U > | |
CountedPtr< U > | const_ptr_cast () const |
template<typename U > | |
CountedPtr< U > | dynamic_ptr_cast () const |
uInt | nrefs () const |
Sometimes it is useful to know if there is more than one reference made. | |
Bool | null () const |
Check to see if this CountedPtr is un-initialized, null. | |
operator bool () const | |
Test if it contains a valid pointer. | |
Private Types | |
typedef SHARED_PTR< t > | PointerRep |
Private Attributes | |
PointerRep | pointerRep_p |
Friends | |
class | CountedPtr |
Make all types of CountedPtr a friend for the templated operator=. |
Referenced counted pointer for constant data.
Public interface
This class is Counted because it is reference counted.
This class implements a reference counting mechanism. It allows CountedPtr
s to be passed around freely, incrementing or decrementing the reference count as needed when one CountedPtr
is assigned to another. When the reference count reaches zero the internal storage is deleted by default, but this behavior can be overridden.
Internally the class uses std::shared_ptr to be thread-safe. Note that tr1 is used if the compiler does not support C++11 yet.
Reference counting
Definition at line 86 of file CountedPtr.h.
typedef SHARED_PTR<t> casacore::CountedPtr< t >::PointerRep [private] |
Definition at line 254 of file CountedPtr.h.
casacore::CountedPtr< t >::CountedPtr | ( | ) | [inline] |
This constructor allows for the creation of a null CountedPtr
.
The assignment operator can be used to assign a null CountedPtr
from another pointer.
Definition at line 110 of file CountedPtr.h.
casacore::CountedPtr< t >::CountedPtr | ( | t * | val, | |
Bool | delit = True | |||
) | [inline] |
This constructor sets up a reference count for the val
pointer.
By default, the data pointed to by val
will be deleted when it is no longer referenced. Passing in False
for delit
will prevent the data from being deleted when the reference count reaches zero.
Warning: After the counted pointer is initialized the value should no longer be manipulated by the raw pointer of type t*
;
Definition at line 122 of file CountedPtr.h.
casacore::CountedPtr< t >::CountedPtr | ( | const CountedPtr< TP > & | that | ) | [inline] |
This copy constructor allows CountedPtr
s to be initialized from other CountedPtr
s for which the pointer TP* is convertible to T*.
Definition at line 130 of file CountedPtr.h.
casacore::CountedPtr< t >::CountedPtr | ( | const SHARED_PTR< t > & | rep | ) | [inline] |
Create from a shared_ptr.
Definition at line 135 of file CountedPtr.h.
casacore::CountedPtr< t >::~CountedPtr | ( | ) | [inline] |
This destructor only deletes the really stored data when it was initialized as deletable and the reference count is zero.
Definition at line 141 of file CountedPtr.h.
CountedPtr<U> casacore::CountedPtr< t >::const_ptr_cast | ( | ) | const [inline] |
Definition at line 228 of file CountedPtr.h.
CountedPtr<U> casacore::CountedPtr< t >::dynamic_ptr_cast | ( | ) | const [inline] |
Definition at line 231 of file CountedPtr.h.
t* casacore::CountedPtr< t >::get | ( | ) | const [inline] |
Get the underlying pointer.
Definition at line 189 of file CountedPtr.h.
Referenced by casacore::CountedPtr< Block< AutoDiffA< T > > >::operator!=(), and casacore::CountedPtr< Block< AutoDiffA< T > > >::operator==().
uInt casacore::CountedPtr< t >::nrefs | ( | ) | const [inline] |
Sometimes it is useful to know if there is more than one reference made.
This is a way of getting that. Of course the point of these classes is that this information is normally not required.
Definition at line 238 of file CountedPtr.h.
Referenced by casacore::COWPtr< T >::isUnique().
Bool casacore::CountedPtr< t >::null | ( | ) | const [inline] |
Check to see if this CountedPtr
is un-initialized, null.
Definition at line 243 of file CountedPtr.h.
Referenced by casacore::ValueHolder::isNull(), casacore::COWPtr< T >::isNull(), casacore::TableMeasColumn::isNull(), casacore::LELCoordinates::isNull(), casacore::RO_LatticeIterator< Float >::isNull(), and casacore::CountedPtr< Block< AutoDiffA< T > > >::operator*().
casacore::CountedPtr< t >::operator bool | ( | ) | const [inline] |
Test if it contains a valid pointer.
Definition at line 247 of file CountedPtr.h.
Bool casacore::CountedPtr< t >::operator!= | ( | int | ptr | ) | const [inline] |
Definition at line 209 of file CountedPtr.h.
Bool casacore::CountedPtr< t >::operator!= | ( | const CountedPtr< t > & | other | ) | const [inline] |
Non-equality operator which checks to see if two CountedPtr
s are not pointing at the same thing.
Definition at line 205 of file CountedPtr.h.
t& casacore::CountedPtr< t >::operator* | ( | ) | const [inline] |
The CountedPtr
indirection operator simply returns a reference to the value being protected.
If the pointer is un-initialized (null), an exception will be thrown. The member function null () can be used to catch such a condition in time.
Tip: The address of the reference returned should not be stored for later use;
Definition at line 170 of file CountedPtr.h.
t* casacore::CountedPtr< t >::operator-> | ( | ) | const [inline] |
This dereferencing operator behaves as expected; it returns the pointer to the value being protected, and then its dereferencing operator will be invoked as appropriate.
If the pointer is un-initialized (null), an exception will be thrown. The member function null () can be used to catch such a condition in time.
Definition at line 184 of file CountedPtr.h.
CountedPtr<t>& casacore::CountedPtr< t >::operator= | ( | t * | v | ) | [inline] |
This assignment operator allows the object to which the current CountedPtr
points to be changed.
Definition at line 216 of file CountedPtr.h.
CountedPtr<t>& casacore::CountedPtr< t >::operator= | ( | const CountedPtr< TP > & | that | ) | [inline] |
This assignment operator allows CountedPtr
s to be copied from other CountedPtr
s for which the pointer TP* is convertible to t*.
Definition at line 147 of file CountedPtr.h.
Bool casacore::CountedPtr< t >::operator== | ( | int | ptr | ) | const [inline] |
Definition at line 199 of file CountedPtr.h.
Bool casacore::CountedPtr< t >::operator== | ( | const CountedPtr< t > & | other | ) | const [inline] |
Equality operator which checks to see if two CountedPtr
s are pointing at the same thing.
Definition at line 195 of file CountedPtr.h.
void casacore::CountedPtr< t >::reset | ( | ) | [inline] |
Definition at line 157 of file CountedPtr.h.
void casacore::CountedPtr< t >::reset | ( | t * | val, | |
Bool | delit = True | |||
) | [inline] |
Reset the pointer.
Definition at line 155 of file CountedPtr.h.
CountedPtr<U> casacore::CountedPtr< t >::static_ptr_cast | ( | ) | const [inline] |
Cast functions.
Definition at line 225 of file CountedPtr.h.
friend class CountedPtr [friend] |
Make all types of CountedPtr a friend for the templated operator=.
Definition at line 252 of file CountedPtr.h.
PointerRep casacore::CountedPtr< t >::pointerRep_p [private] |
Definition at line 256 of file CountedPtr.h.
Referenced by casacore::CountedPtr< Block< AutoDiffA< T > > >::const_ptr_cast(), casacore::CountedPtr< Block< AutoDiffA< T > > >::dynamic_ptr_cast(), casacore::CountedPtr< Block< AutoDiffA< T > > >::get(), casacore::CountedPtr< Block< AutoDiffA< T > > >::nrefs(), casacore::CountedPtr< Block< AutoDiffA< T > > >::operator*(), casacore::CountedPtr< Block< AutoDiffA< T > > >::operator=(), casacore::CountedPtr< Block< AutoDiffA< T > > >::reset(), and casacore::CountedPtr< Block< AutoDiffA< T > > >::static_ptr_cast().