MADARA  3.2.3
madara::utility::ThreadSafeVector< T > Class Template Reference

Manages a thread safe STL vector. More...

#include <ThreadSafeVector.h>

Public Member Functions

 ThreadSafeVector (void)
 Constructor. More...
 
 ThreadSafeVector (const ThreadSafeVector &rhs)
 Copy constructor. More...
 
 ThreadSafeVector (const std::vector< T > &rhs)
 Copy constructor. More...
 
virtual ~ThreadSafeVector (void)
 Destructor. More...
 
void acquire (void) const
 Locks the mutex. More...
 
const T & back (void) const
 Returns the last element of the vector. More...
 
T & back (void)
 Returns the last element of the vector. More...
 
void clear (void)
 Clears the vector. More...
 
size_t erase (size_t index)
 Erases an element. More...
 
void lock (void) const
 Locks the mutex. More...
 
size_t max_size (void) const
 returns the max size of the vector More...
 
void operator= (const ThreadSafeVector &rhs)
 Assignment operator. More...
 
void operator= (const std::vector< T > &rhs)
 Assignment operator. More...
 
T & operator[] (size_t index)
 Accesses an element of the vector. More...
 
const T & operator[] (size_t index) const
 Accesses an element of the vector. More...
 
pop_back (void)
 Returns the last element before removing it. More...
 
void push_back (T &value)
 Pushes a value onto the end of the vector. More...
 
void release (void) const
 Unlocks the mutex. More...
 
void reserve (size_t new_size) const
 Reserves a number of elements the vector. More...
 
void resize (size_t new_size) const
 Resizes the vector. More...
 
size_t size (void) const
 returns the current size of the vector More...
 
void unlock (void) const
 Unlocks the mutex. More...
 

Private Attributes

MADARA_LOCK_TYPE mutex_
 mutex for updating refcount_ More...
 
std::vector< T > vector_
 the encapsulated vector More...
 

Detailed Description

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

Manages a thread safe STL vector.

Definition at line 17 of file ThreadSafeVector.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 8 of file ThreadSafeVector.cpp.

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

Copy constructor.

Parameters
rhsthe vector to copy

Definition at line 13 of file ThreadSafeVector.cpp.

template<typename T >
madara::utility::ThreadSafeVector< T >::ThreadSafeVector ( const std::vector< T > &  rhs)

Copy constructor.

Parameters
rhsthe vector to copy

Definition at line 21 of file ThreadSafeVector.cpp.

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

Destructor.

Definition at line 28 of file ThreadSafeVector.cpp.

Member Function Documentation

template<typename T >
void madara::utility::ThreadSafeVector< T >::acquire ( void  ) const
inline

Locks the mutex.

Definition at line 156 of file ThreadSafeVector.cpp.

template<typename T >
const T & madara::utility::ThreadSafeVector< T >::back ( void  ) const
inline

Returns the last element of the vector.

Returns
the last element of the vector

Definition at line 80 of file ThreadSafeVector.cpp.

template<typename T >
T & madara::utility::ThreadSafeVector< T >::back ( void  )
inline

Returns the last element of the vector.

Returns
the last element of the vector

Definition at line 108 of file ThreadSafeVector.cpp.

template<typename T >
void madara::utility::ThreadSafeVector< T >::clear ( void  )
inline

Clears the vector.

Definition at line 143 of file ThreadSafeVector.cpp.

template<typename T >
size_t madara::utility::ThreadSafeVector< T >::erase ( size_t  index)
inline

Erases an element.

Parameters
indexindex of element to erase
Returns
the new size of the vector

Definition at line 97 of file ThreadSafeVector.cpp.

template<typename T >
void madara::utility::ThreadSafeVector< T >::lock ( void  ) const
inline

Locks the mutex.

Definition at line 150 of file ThreadSafeVector.cpp.

template<typename T >
size_t madara::utility::ThreadSafeVector< T >::max_size ( void  ) const
inline

returns the max size of the vector

Returns
the max size

Definition at line 136 of file ThreadSafeVector.cpp.

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

Assignment operator.

Parameters
rhsa vector to copy

Definition at line 35 of file ThreadSafeVector.cpp.

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

Assignment operator.

Parameters
rhsa vector to copy

Definition at line 48 of file ThreadSafeVector.cpp.

template<typename T >
T & madara::utility::ThreadSafeVector< T >::operator[] ( size_t  index)
inline

Accesses an element of the vector.

Parameters
indexindex to access
Returns
the element at the index

Definition at line 59 of file ThreadSafeVector.cpp.

template<typename T >
const T & madara::utility::ThreadSafeVector< T >::operator[] ( size_t  index) const
inline

Accesses an element of the vector.

Parameters
indexindex to access
Returns
the element at the index

Definition at line 66 of file ThreadSafeVector.cpp.

template<typename T >
T madara::utility::ThreadSafeVector< T >::pop_back ( void  )
inline

Returns the last element before removing it.

Returns
the deleted element of the vector

Definition at line 87 of file ThreadSafeVector.cpp.

template<typename T >
void madara::utility::ThreadSafeVector< T >::push_back ( T &  value)
inline

Pushes a value onto the end of the vector.

Parameters
valuea value to add to the end of the vector

Definition at line 73 of file ThreadSafeVector.cpp.

template<typename T >
void madara::utility::ThreadSafeVector< T >::release ( void  ) const
inline

Unlocks the mutex.

Definition at line 168 of file ThreadSafeVector.cpp.

template<typename T >
void madara::utility::ThreadSafeVector< T >::reserve ( size_t  new_size) const
inline

Reserves a number of elements the vector.

Parameters
new_sizethe new size

Definition at line 122 of file ThreadSafeVector.cpp.

template<typename T >
void madara::utility::ThreadSafeVector< T >::resize ( size_t  new_size) const
inline

Resizes the vector.

Parameters
new_sizethe new size

Definition at line 115 of file ThreadSafeVector.cpp.

template<typename T >
size_t madara::utility::ThreadSafeVector< T >::size ( void  ) const
inline

returns the current size of the vector

Returns
the current size

Definition at line 129 of file ThreadSafeVector.cpp.

template<typename T >
void madara::utility::ThreadSafeVector< T >::unlock ( void  ) const
inline

Unlocks the mutex.

Definition at line 162 of file ThreadSafeVector.cpp.

Member Data Documentation

template<typename T>
MADARA_LOCK_TYPE madara::utility::ThreadSafeVector< T >::mutex_
mutableprivate

mutex for updating refcount_

Definition at line 153 of file ThreadSafeVector.h.

template<typename T>
std::vector<T> madara::utility::ThreadSafeVector< T >::vector_
private

the encapsulated vector

Definition at line 156 of file ThreadSafeVector.h.


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