Skip to content

Commit

Permalink
Expand RingBufferImplementation beyond shared_ptr and unique_ptr
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
  • Loading branch information
jefferyyjhsu committed Nov 13, 2023
1 parent a88a02a commit 8931c49
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ class RingBufferImplementation : public BufferImplementationBase<BufferT>
*
* \return a vector containing all the elements from the ring buffer
*/
template<typename T = BufferT, std::enable_if_t<is_std_unique_ptr<T>::value, void> * = nullptr>
template<typename T = BufferT, std::enable_if_t<is_std_unique_ptr<T>::value &&
std::is_copy_constructible<
typename is_std_unique_ptr<T>::Ptr_type
>::value,
void> * = nullptr>
std::vector<BufferT> get_all_data_impl()
{
std::lock_guard<std::mutex> lock(mutex_);
Expand All @@ -258,7 +262,8 @@ class RingBufferImplementation : public BufferImplementationBase<BufferT>
return result_vtr;
}

template<typename T = BufferT, std::enable_if_t<!is_std_unique_ptr<T>::value, void> * = nullptr>
template<typename T = BufferT, std::enable_if_t<
std::is_copy_constructible<T>::value, void> * = nullptr>
std::vector<BufferT> get_all_data_impl()
{
std::lock_guard<std::mutex> lock(mutex_);
Expand All @@ -270,6 +275,23 @@ class RingBufferImplementation : public BufferImplementationBase<BufferT>
return result_vtr;
}

template<typename T = BufferT, std::enable_if_t<!is_std_unique_ptr<T>::value &&
!std::is_copy_constructible<T>::value, void> * = nullptr>
std::vector<BufferT> get_all_data_impl()
{
throw std::logic_error("Underlined type results in invalid get_all_data_impl()");
return {};
}

template<typename T = BufferT, std::enable_if_t<is_std_unique_ptr<T>::value &&
!std::is_copy_constructible<typename is_std_unique_ptr<T>::Ptr_type>::value,
void> * = nullptr>
std::vector<BufferT> get_all_data_impl()
{
throw std::logic_error("Underlined type in unique_ptr results in invalid get_all_data_impl()");
return {};
}

size_t capacity_;

std::vector<BufferT> ring_buffer_;
Expand Down

0 comments on commit 8931c49

Please sign in to comment.