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

Manages a thread safe STL vector. More...

#include <ThreadSafeVector.h>

Public Member Functions

 ThreadSafeVector (const std::vector< T > &rhs)
 Copy constructor. More...
 
 ThreadSafeVector (const ThreadSafeVector &rhs)
 Copy constructor. More...
 
 ThreadSafeVector (void)
 Constructor. More...
 
virtual ~ThreadSafeVector (void)
 Destructor. More...
 
void acquire (void) const
 Locks the mutex. More...
 
T & back (void)
 Returns the last element of the vector. More...
 
const T & back (void) const
 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 std::vector< T > &rhs)
 Assignment operator. More...
 
void operator= (const ThreadSafeVector &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

◆ ThreadSafeVector() [1/3]

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

Constructor.

Definition at line 8 of file ThreadSafeVector.cpp.

◆ ThreadSafeVector() [2/3]

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.

◆ ThreadSafeVector() [3/3]

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.

◆ ~ThreadSafeVector()

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

Destructor.

Definition at line 21 of file ThreadSafeVector.cpp.

Member Function Documentation

◆ acquire()

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

Locks the mutex.

Definition at line 155 of file ThreadSafeVector.cpp.

◆ back() [1/2]

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 107 of file ThreadSafeVector.cpp.

◆ back() [2/2]

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 79 of file ThreadSafeVector.cpp.

◆ clear()

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

Clears the vector.

Definition at line 142 of file ThreadSafeVector.cpp.

◆ erase()

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 96 of file ThreadSafeVector.cpp.

◆ lock()

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

Locks the mutex.

Definition at line 149 of file ThreadSafeVector.cpp.

◆ max_size()

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 135 of file ThreadSafeVector.cpp.

◆ operator=() [1/2]

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

Assignment operator.

Parameters
rhsa vector to copy

Definition at line 47 of file ThreadSafeVector.cpp.

◆ operator=() [2/2]

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

Assignment operator.

Parameters
rhsa vector to copy

Definition at line 34 of file ThreadSafeVector.cpp.

◆ operator[]() [1/2]

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 58 of file ThreadSafeVector.cpp.

◆ operator[]() [2/2]

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 65 of file ThreadSafeVector.cpp.

◆ pop_back()

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 86 of file ThreadSafeVector.cpp.

◆ push_back()

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 72 of file ThreadSafeVector.cpp.

◆ release()

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

Unlocks the mutex.

Definition at line 167 of file ThreadSafeVector.cpp.

◆ reserve()

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 121 of file ThreadSafeVector.cpp.

◆ resize()

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 114 of file ThreadSafeVector.cpp.

◆ size()

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 128 of file ThreadSafeVector.cpp.

◆ unlock()

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

Unlocks the mutex.

Definition at line 161 of file ThreadSafeVector.cpp.

Member Data Documentation

◆ mutex_

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

mutex for updating refcount_

Definition at line 150 of file ThreadSafeVector.h.

◆ vector_

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

the encapsulated vector

Definition at line 153 of file ThreadSafeVector.h.


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