KaRL  3.0.0
madara::utility::ThreadSafeRefcounter< T > Class Template Reference

This template class provides transparent reference counting of its template parameter T. More...

#include <ThreadSafeRefcounter.h>

Collaboration diagram for madara::utility::ThreadSafeRefcounter< T >:

Classes

struct  Shim
 A shim class that keeps track of the reference count and a pointer to the type T that's reference counted. More...
 

Public Member Functions

 ThreadSafeRefcounter (void)
 default Ctor More...
 
 ThreadSafeRefcounter (T *ptr, bool increase_count=false, bool manage=true)
 Ctor with refcounting functionality. More...
 
 ThreadSafeRefcounter (const ThreadSafeRefcounter &rhs)
 copy Ctor More...
 
virtual ~ThreadSafeRefcounter (void)
 Dtor will delete pointer if refcount becomes 0. More...
 
T * get (void)
 get the underlying pointer More...
 
const T * get (void) const
 get the underlying pointer More...
 
T * get_ptr (void)
 get the underlying pointer More...
 
const T * get_ptr (void) const
 get the underlying pointer More...
 
bool is_valid (void) const
 checks to see if the underlying pointer is valid More...
 
T & operator* (void)
 dereference operator More...
 
const T & operator* (void) const
 dereference operator More...
 
T * operator-> (void)
 mimic pointer dereferencing More...
 
const T * operator-> (void) const
 mimic pointer dereferencing More...
 
void operator= (T *ptr)
 assignment operator for times when you don't want the reference increased for incoming ptr More...
 
void operator= (const ThreadSafeRefcounter &rhs)
 assignment operator More...
 

Private Member Functions

void decrement (void)
 implementation of the decrement operation More...
 
void increment (void)
 implementation of the increment operation More...
 

Private Attributes

Shimptr_
 Pointer to the Shim. More...
 

Detailed Description

template<typename T>
class madara::utility::ThreadSafeRefcounter< T >

This template class provides transparent reference counting of its template parameter T.

This differs from ScopedArray in the type of memory it is meant to manage. ThreadSafeRefcounter manages single object instances. ScopedArray manages an array of instances,

This class can be used to automate the implementation of the Bridge pattern in C++.

Definition at line 25 of file ThreadSafeRefcounter.h.

Constructor & Destructor Documentation

template<typename T >
madara::utility::ThreadSafeRefcounter< T >::ThreadSafeRefcounter ( void  )

default Ctor

Definition at line 9 of file ThreadSafeRefcounter.cpp.

template<typename T>
madara::utility::ThreadSafeRefcounter< T >::ThreadSafeRefcounter ( T *  ptr,
bool  increase_count = false,
bool  manage = true 
)

Ctor with refcounting functionality.

Definition at line 16 of file ThreadSafeRefcounter.cpp.

template<typename T>
madara::utility::ThreadSafeRefcounter< T >::ThreadSafeRefcounter ( const ThreadSafeRefcounter< T > &  rhs)

copy Ctor

Definition at line 26 of file ThreadSafeRefcounter.cpp.

template<typename T >
madara::utility::ThreadSafeRefcounter< T >::~ThreadSafeRefcounter ( void  )
virtual

Dtor will delete pointer if refcount becomes 0.

Definition at line 35 of file ThreadSafeRefcounter.cpp.

Member Function Documentation

template<typename T >
void madara::utility::ThreadSafeRefcounter< T >::decrement ( void  )
inlineprivate

implementation of the decrement operation

Definition at line 193 of file ThreadSafeRefcounter.cpp.

template<typename T >
T * madara::utility::ThreadSafeRefcounter< T >::get ( void  )

get the underlying pointer

Definition at line 104 of file ThreadSafeRefcounter.cpp.

template<typename T >
const T * madara::utility::ThreadSafeRefcounter< T >::get ( void  ) const

get the underlying pointer

Definition at line 119 of file ThreadSafeRefcounter.cpp.

template<typename T >
T * madara::utility::ThreadSafeRefcounter< T >::get_ptr ( void  )

get the underlying pointer

Definition at line 66 of file ThreadSafeRefcounter.cpp.

template<typename T >
const T * madara::utility::ThreadSafeRefcounter< T >::get_ptr ( void  ) const

get the underlying pointer

Definition at line 81 of file ThreadSafeRefcounter.cpp.

template<typename T >
void madara::utility::ThreadSafeRefcounter< T >::increment ( void  )
inlineprivate

implementation of the increment operation

Definition at line 181 of file ThreadSafeRefcounter.cpp.

template<typename T >
bool madara::utility::ThreadSafeRefcounter< T >::is_valid ( void  ) const

checks to see if the underlying pointer is valid

get the underlying pointer

Definition at line 96 of file ThreadSafeRefcounter.cpp.

template<typename T >
T & madara::utility::ThreadSafeRefcounter< T >::operator* ( void  )
inline

dereference operator

Definition at line 134 of file ThreadSafeRefcounter.cpp.

template<typename T >
const T & madara::utility::ThreadSafeRefcounter< T >::operator* ( void  ) const
inline

dereference operator

Definition at line 143 of file ThreadSafeRefcounter.cpp.

template<typename T >
T * madara::utility::ThreadSafeRefcounter< T >::operator-> ( void  )
inline

mimic pointer dereferencing

Definition at line 151 of file ThreadSafeRefcounter.cpp.

template<typename T >
const T * madara::utility::ThreadSafeRefcounter< T >::operator-> ( void  ) const
inline

mimic pointer dereferencing

Definition at line 166 of file ThreadSafeRefcounter.cpp.

template<typename T>
void madara::utility::ThreadSafeRefcounter< T >::operator= ( T *  ptr)

assignment operator for times when you don't want the reference increased for incoming ptr

assignment operator for times when you don't want the reference increased for incoming ptr.

Definition at line 44 of file ThreadSafeRefcounter.cpp.

template<typename T>
void madara::utility::ThreadSafeRefcounter< T >::operator= ( const ThreadSafeRefcounter< T > &  rhs)

assignment operator

Definition at line 53 of file ThreadSafeRefcounter.cpp.

Member Data Documentation

template<typename T>
Shim* madara::utility::ThreadSafeRefcounter< T >::ptr_
private

Pointer to the Shim.

Definition at line 108 of file ThreadSafeRefcounter.h.


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