casa  5.7.0-16
 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 <VisModelData.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 42 of file VisModelData.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
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 ( void  )
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 files: