casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Types | Private Attributes | Friends | List of all members
casacore::CountedPtr< t > Class Template Reference

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 CountedPtrs to be initialized from other CountedPtrs 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 CountedPtrs to be copied from other CountedPtrs 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 CountedPtrs 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 CountedPtrs 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...
 

Detailed Description

template<class t>
class casacore::CountedPtr< t >

Referenced counted pointer for constant data.

Intended use:

Public interface

Review Status

Reviewed By:
Friso Olnon
Date Reviewed:
1995/03/15
Test programs:
tCountedPtr

Etymology

This class is Counted because it is reference counted.

Synopsis

This class implements a reference counting mechanism. It allows CountedPtrs 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.

Motivation

Reference counting

Definition at line 80 of file CountedPtr.h.

Member Typedef Documentation

template<class t>
typedef std::shared_ptr<t> casacore::CountedPtr< t >::PointerRep
private

Definition at line 248 of file CountedPtr.h.

Constructor & Destructor Documentation

template<class t>
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 104 of file CountedPtr.h.

template<class t>
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 116 of file CountedPtr.h.

template<class t>
template<typename TP >
casacore::CountedPtr< t >::CountedPtr ( const CountedPtr< TP > &  that)
inline

This copy constructor allows CountedPtrs to be initialized from other CountedPtrs for which the pointer TP* is convertible to T*.

Definition at line 124 of file CountedPtr.h.

template<class t>
casacore::CountedPtr< t >::CountedPtr ( const std::shared_ptr< t > &  rep)
inline

Create from a shared_ptr.

Definition at line 129 of file CountedPtr.h.

template<class t>
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 135 of file CountedPtr.h.

Member Function Documentation

template<class t>
template<typename U >
CountedPtr<U> casacore::CountedPtr< t >::const_ptr_cast ( ) const
inline

Definition at line 222 of file CountedPtr.h.

template<class t>
template<typename U >
CountedPtr<U> casacore::CountedPtr< t >::dynamic_ptr_cast ( ) const
inline

Definition at line 225 of file CountedPtr.h.

template<class t>
t* casacore::CountedPtr< t >::get ( ) const
inline
template<class t>
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 232 of file CountedPtr.h.

template<class t>
Bool casacore::CountedPtr< t >::null ( ) const
inline

Check to see if this CountedPtr is un-initialized, null.

Definition at line 237 of file CountedPtr.h.

Referenced by casacore::CountedPtr< casacore::DataConversion >::operator*().

template<class t>
casacore::CountedPtr< t >::operator bool ( ) const
inline

Test if it contains a valid pointer.

Definition at line 241 of file CountedPtr.h.

template<class t>
Bool casacore::CountedPtr< t >::operator!= ( const CountedPtr< t > &  other) const
inline

Non-equality operator which checks to see if two CountedPtrs are not pointing at the same thing.

Definition at line 199 of file CountedPtr.h.

template<class t>
Bool casacore::CountedPtr< t >::operator!= ( int  ptr) const
inline

Definition at line 203 of file CountedPtr.h.

template<class t>
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 164 of file CountedPtr.h.

template<class t>
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 178 of file CountedPtr.h.

template<class t>
template<typename TP >
CountedPtr<t>& casacore::CountedPtr< t >::operator= ( const CountedPtr< TP > &  that)
inline

This assignment operator allows CountedPtrs to be copied from other CountedPtrs for which the pointer TP* is convertible to t*.

Definition at line 141 of file CountedPtr.h.

template<class t>
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 210 of file CountedPtr.h.

template<class t>
Bool casacore::CountedPtr< t >::operator== ( const CountedPtr< t > &  other) const
inline

Equality operator which checks to see if two CountedPtrs are pointing at the same thing.

Definition at line 189 of file CountedPtr.h.

template<class t>
Bool casacore::CountedPtr< t >::operator== ( int  ptr) const
inline

Definition at line 193 of file CountedPtr.h.

template<class t>
void casacore::CountedPtr< t >::reset ( t *  val,
Bool  delit = True 
)
inline

Reset the pointer.

Definition at line 149 of file CountedPtr.h.

template<class t>
void casacore::CountedPtr< t >::reset ( )
inline

Definition at line 151 of file CountedPtr.h.

template<class t>
template<typename U >
CountedPtr<U> casacore::CountedPtr< t >::static_ptr_cast ( ) const
inline

Cast functions.

Definition at line 219 of file CountedPtr.h.

Friends And Related Function Documentation

template<class t>
template<typename TP >
friend class CountedPtr
friend

Make all types of CountedPtr a friend for the templated operator=.

Definition at line 246 of file CountedPtr.h.

Member Data Documentation

template<class t>
PointerRep casacore::CountedPtr< t >::pointerRep_p
private

The documentation for this class was generated from the following file: