casacore
|
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 . More... | |
CountedPtr (t *val, Bool delit=True) | |
This constructor sets up a reference count for the val pointer. More... | |
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*. More... | |
CountedPtr (const std::shared_ptr< t > &rep) | |
Create from a shared_ptr. More... | |
~CountedPtr () | |
This destructor only deletes the really stored data when it was initialized as deletable and the reference count is zero. More... | |
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*. More... | |
void | reset (t *val, Bool delit=True) |
Reset the pointer. More... | |
void | reset () |
t & | operator* () const |
The CountedPtr indirection operator simply returns a reference to the value being protected. More... | |
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. More... | |
t * | get () const |
Get the underlying pointer. More... | |
Bool | operator== (const CountedPtr< t > &other) const |
Equality operator which checks to see if two CountedPtr s are pointing at the same thing. More... | |
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. More... | |
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. More... | |
template<typename U > | |
CountedPtr< U > | static_ptr_cast () const |
Cast functions. More... | |
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. More... | |
Bool | null () const |
Check to see if this CountedPtr is un-initialized, null. More... | |
operator bool () const | |
Test if it contains a valid pointer. More... | |
Private Types | |
typedef std::shared_ptr< t > | PointerRep |
Private Attributes | |
PointerRep | pointerRep_p |
Friends | |
template<typename TP > | |
class | CountedPtr |
Make all types of CountedPtr a friend for the templated operator=. More... | |
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 80 of file CountedPtr.h.
|
private |
Definition at line 248 of file CountedPtr.h.
|
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 104 of file CountedPtr.h.
|
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 116 of file CountedPtr.h.
|
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 124 of file CountedPtr.h.
|
inline |
Create from a shared_ptr.
Definition at line 129 of file CountedPtr.h.
|
inline |
This destructor only deletes the really stored data when it was initialized as deletable and the reference count is zero.
Definition at line 135 of file CountedPtr.h.
|
inline |
Definition at line 222 of file CountedPtr.h.
References casacore::CountedPtr< t >::pointerRep_p.
|
inline |
Definition at line 225 of file CountedPtr.h.
References casacore::CountedPtr< t >::pointerRep_p.
|
inline |
Get the underlying pointer.
Definition at line 183 of file CountedPtr.h.
References casacore::CountedPtr< t >::pointerRep_p.
Referenced by casacore::TableExprNode::getNodeRep(), casacore::CountedPtr< t >::null(), casacore::CountedPtr< t >::operator bool(), casacore::CountedPtr< t >::operator!=(), casacore::CountedPtr< t >::operator->(), and casacore::CountedPtr< t >::operator==().
|
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 232 of file CountedPtr.h.
References casacore::CountedPtr< t >::pointerRep_p.
|
inline |
Check to see if this CountedPtr
is un-initialized, null.
Definition at line 237 of file CountedPtr.h.
References casacore::CountedPtr< t >::get().
|
inline |
Test if it contains a valid pointer.
Definition at line 241 of file CountedPtr.h.
References casacore::CountedPtr< t >::get().
|
inline |
Non-equality operator which checks to see if two CountedPtr
s are not pointing at the same thing.
Definition at line 199 of file CountedPtr.h.
References casacore::False, casacore::CountedPtr< t >::get(), and casacore::True.
|
inline |
Definition at line 203 of file CountedPtr.h.
References casacore::CountedPtr< t >::get().
|
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 164 of file CountedPtr.h.
References casacore::CountedPtr< t >::pointerRep_p.
|
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 178 of file CountedPtr.h.
References casacore::CountedPtr< t >::get().
|
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 141 of file CountedPtr.h.
References casacore::CountedPtr< t >::pointerRep_p.
|
inline |
This assignment operator allows the object to which the current CountedPtr
points to be changed.
Definition at line 210 of file CountedPtr.h.
References casacore::CountedPtr< t >::pointerRep_p.
|
inline |
Equality operator which checks to see if two CountedPtr
s are pointing at the same thing.
Definition at line 189 of file CountedPtr.h.
References casacore::CountedPtr< t >::get().
|
inline |
Definition at line 193 of file CountedPtr.h.
References casacore::CountedPtr< t >::get().
|
inline |
Definition at line 151 of file CountedPtr.h.
References casacore::CountedPtr< t >::pointerRep_p.
|
inline |
Reset the pointer.
Definition at line 149 of file CountedPtr.h.
References casacore::CountedPtr< t >::pointerRep_p.
|
inline |
Cast functions.
Definition at line 219 of file CountedPtr.h.
References casacore::CountedPtr< t >::pointerRep_p.
Make all types of CountedPtr a friend for the templated operator=.
Definition at line 246 of file CountedPtr.h.
|
private |
Definition at line 250 of file CountedPtr.h.
Referenced by casacore::CountedPtr< t >::const_ptr_cast(), casacore::CountedPtr< t >::dynamic_ptr_cast(), casacore::CountedPtr< t >::get(), casacore::CountedPtr< t >::nrefs(), casacore::CountedPtr< t >::operator*(), casacore::CountedPtr< t >::operator=(), casacore::CountedPtr< t >::reset(), and casacore::CountedPtr< t >::static_ptr_cast().