Program Listing for File mt_vector.hpp
↰ Return to documentation for file (rcppsw/multithread/mt_vector.hpp)
#pragma once
/*******************************************************************************
 * Includes
 ******************************************************************************/
#include <boost/thread.hpp>
#include <boost/thread/locks.hpp>
#include <vector>
#include "rcppsw/rcppsw.hpp"
/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace rcppsw::multithread {
/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
template <typename T>
class mt_vector {
 public:
  using const_iterator = typename std::vector<T>::const_iterator;
  mt_vector(void) = default;
  void push_back(const T& data) {
    boost::unique_lock<boost::mutex> lock(m_mtx);
    m_v.push_back(data);
  }
 private:
  /* clang-format off */
  std::vector<T> m_v;
  boost::mutex   m_mtx;
  /* clang-format on */
 public:
  RCPPSW_WRAP_DECLDEF(size, m_v, const);
  RCPPSW_WRAP_DECLDEF(operator[], m_v);
  RCPPSW_WRAP_DECLDEF(begin, m_v, const);
  RCPPSW_WRAP_DECLDEF(end, m_v, const);
};
} /* namespace rcppsw::multithread */