casacore::CountedPtr< t > Class Template Reference

Referenced counted pointer for constant data. More...

#include <CountedPtr.h>

List of all members.

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

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 86 of file CountedPtr.h.


Member Typedef Documentation

template<class t>
typedef SHARED_PTR<t> casacore::CountedPtr< t >::PointerRep [private]

Definition at line 254 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 110 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 122 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 130 of file CountedPtr.h.

template<class t>
casacore::CountedPtr< t >::CountedPtr ( const SHARED_PTR< t > &  rep  )  [inline]

Create from a shared_ptr.

Definition at line 135 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 141 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 228 of file CountedPtr.h.

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

Definition at line 231 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 238 of file CountedPtr.h.

Referenced by casacore::COWPtr< T >::isUnique().

template<class t>
Bool casacore::CountedPtr< t >::null (  )  const [inline]
template<class t>
casacore::CountedPtr< t >::operator bool (  )  const [inline]

Test if it contains a valid pointer.

Definition at line 247 of file CountedPtr.h.

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

Definition at line 209 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 205 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 170 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 184 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 216 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 147 of file CountedPtr.h.

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

Definition at line 199 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 195 of file CountedPtr.h.

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

Definition at line 157 of file CountedPtr.h.

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

Reset the pointer.

Definition at line 155 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 225 of file CountedPtr.h.


Friends And Related Function Documentation

template<class t>
friend class CountedPtr [friend]

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

Definition at line 252 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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1