Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
MutexedVectorPointer< T > Class Template Reference

This class holds a pointer onto a vector. Some of the std::vector functions are implemented for thread-safe operations. If a function is not implemented, you can retrieve the raw pointer onto the vector with the unmutexed_get_ptr method. More...

#include <mvector.hpp>

Public Member Functions

 MutexedVectorPointer ()=delete
 
 MutexedVectorPointer (std::vector< T > &vec)
 
 MutexedVectorPointer (std::vector< T > *vec)
 
std::vector< T > * unmutexed_get_ptr ()
 
void push_back (T const &item)
 

Private Attributes

std::vector< T > * m_data = nullptr
 
std::mutex m_mutex
 

Detailed Description

template<typename T>
class MutexedVectorPointer< T >

This class holds a pointer onto a vector. Some of the std::vector functions are implemented for thread-safe operations. If a function is not implemented, you can retrieve the raw pointer onto the vector with the unmutexed_get_ptr method.

Definition at line 11 of file mvector.hpp.

Constructor & Destructor Documentation

◆ MutexedVectorPointer() [1/3]

template<typename T >
MutexedVectorPointer< T >::MutexedVectorPointer ( )
delete

◆ MutexedVectorPointer() [2/3]

template<typename T >
MutexedVectorPointer< T >::MutexedVectorPointer ( std::vector< T > &  vec)
inline

Definition at line 19 of file mvector.hpp.

19  {
20  m_data = &vec;
21  }

References MutexedVectorPointer< T >::m_data.

◆ MutexedVectorPointer() [3/3]

template<typename T >
MutexedVectorPointer< T >::MutexedVectorPointer ( std::vector< T > *  vec)
inline

Definition at line 23 of file mvector.hpp.

23  {
24  m_data = vec;
25  }

References MutexedVectorPointer< T >::m_data.

Member Function Documentation

◆ push_back()

template<typename T >
void MutexedVectorPointer< T >::push_back ( T const &  item)
inline

Definition at line 31 of file mvector.hpp.

31  {
32  m_mutex.lock();
33 
34  m_data->push_back(item);
35 
36  m_mutex.unlock();
37  }

References MutexedVectorPointer< T >::m_data, and MutexedVectorPointer< T >::m_mutex.

◆ unmutexed_get_ptr()

template<typename T >
std::vector<T>* MutexedVectorPointer< T >::unmutexed_get_ptr ( )
inline

Definition at line 27 of file mvector.hpp.

27  {
28  return m_data;
29  }

References MutexedVectorPointer< T >::m_data.

Member Data Documentation

◆ m_data

template<typename T >
std::vector<T>* MutexedVectorPointer< T >::m_data = nullptr
private

◆ m_mutex

template<typename T >
std::mutex MutexedVectorPointer< T >::m_mutex
private

Definition at line 14 of file mvector.hpp.

Referenced by MutexedVectorPointer< T >::push_back().


The documentation for this class was generated from the following file:
MutexedVectorPointer::m_mutex
std::mutex m_mutex
Definition: mvector.hpp:14
MutexedVectorPointer::m_data
std::vector< T > * m_data
Definition: mvector.hpp:13