MADARA  3.4.1
madara::utility::ScopedArray< T > Class Template Reference

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

#include <ScopedArray.h>

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

 ScopedArray (const ScopedArray &rhs)
 copy Ctor More...
 
 ScopedArray (T *ptr, bool increase_count=false)
 Ctor with refcounting functionality. More...
 
 ScopedArray (void)
 default Ctor More...
 
virtual ~ScopedArray (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...
 
void operator= (const ScopedArray &rhs)
 assignment operator More...
 
void operator= (T *ptr)
 assignment operator for times when you don't want the reference increased for incoming ptr 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::ScopedArray< T >

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

This differs from Refcounter in the members available and the deletion of memory. Refcounter deletes a single T memory location when the last instance of the pointer goes out of scope. ScopedArray deletes an array of T objects when the pointer goes out of scope.

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

Definition at line 22 of file ScopedArray.h.

Constructor & Destructor Documentation

◆ ScopedArray() [1/3]

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

default Ctor

Definition at line 9 of file ScopedArray.inl.

◆ ScopedArray() [2/3]

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

Ctor with refcounting functionality.

Definition at line 15 of file ScopedArray.inl.

◆ ScopedArray() [3/3]

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

copy Ctor

Definition at line 24 of file ScopedArray.inl.

◆ ~ScopedArray()

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

Dtor will delete pointer if refcount becomes 0.

Definition at line 24 of file ScopedArray.inl.

Member Function Documentation

◆ decrement()

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

implementation of the decrement operation

Definition at line 100 of file ScopedArray.inl.

◆ get() [1/2]

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

get the underlying pointer

Definition at line 78 of file ScopedArray.inl.

◆ get() [2/2]

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

get the underlying pointer

Definition at line 85 of file ScopedArray.inl.

◆ get_ptr() [1/2]

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

get the underlying pointer

Definition at line 64 of file ScopedArray.inl.

◆ get_ptr() [2/2]

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

get the underlying pointer

Definition at line 71 of file ScopedArray.inl.

◆ increment()

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

implementation of the increment operation

Definition at line 92 of file ScopedArray.inl.

◆ operator=() [1/2]

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

assignment operator

Definition at line 52 of file ScopedArray.inl.

◆ operator=() [2/2]

template<typename T >
void madara::utility::ScopedArray< 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 40 of file ScopedArray.inl.

Member Data Documentation

◆ ptr_

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

Pointer to the Shim.

Definition at line 81 of file ScopedArray.h.


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