3#ifndef MSD_CHANNEL_STORAGE_HPP_
4#define MSD_CHANNEL_STORAGE_HPP_
38 template <
typename Type>
41 queue_.push(std::forward<Type>(value));
52 out = std::move(queue_.front());
90 template <
typename Type>
93 vector_.push_back(std::forward<Type>(value));
104 out = std::move(vector_.front());
105 vector_.erase(vector_.begin());
116 std::vector<T> vector_;
126template <
typename T, std::
size_t N>
129 static_assert(
N > 0,
"Capacity must be greater than zero.");
145 template <
typename Type>
148 array_[(front_ + size_) %
N] = std::forward<Type>(value);
160 out = std::move(array_[front_]);
161 front_ = (front_ + 1) %
N;
173 std::array<T, N> array_{};
174 std::size_t size_{0};
175 std::size_t front_{0};
178template <
typename T, std::
size_t N>
A fixed-size circular buffer using std::array.
Definition storage.hpp:127
static constexpr std::size_t capacity
The storage capacity.
Definition storage.hpp:136
void pop_front(T &out)
Marks the front element as removed and moves it to the output.
Definition storage.hpp:158
void push_back(Type &&value)
Adds an element to the back of the array.
Definition storage.hpp:146
NODISCARD std::size_t size() const noexcept
Returns the number of elements currently stored.
Definition storage.hpp:170
Thread-safe container for sharing data between threads.
Definition channel.hpp:87
A FIFO queue storage using std::queue.
Definition storage.hpp:23
NODISCARD std::size_t size() const noexcept
Returns the number of elements currently stored.
Definition storage.hpp:61
void push_back(Type &&value)
Adds an element to the back of the queue.
Definition storage.hpp:39
queue_storage(std::size_t)
Constructs the queue storage (parameter ignored, required for interface compatibility).
Definition storage.hpp:30
void pop_front(T &out)
Removes the front element from the queue and moves it to the output.
Definition storage.hpp:50
A FIFO queue storage using std::vector.
Definition storage.hpp:73
void push_back(Type &&value)
Adds an element to the back of the vector.
Definition storage.hpp:91
void pop_front(T &out)
Removes the front element from the vector and moves it to the output.
Definition storage.hpp:102
vector_storage(std::size_t capacity)
Constructs a queue storage with a given capacity.
Definition storage.hpp:82
NODISCARD std::size_t size() const noexcept
Returns the number of elements currently stored.
Definition storage.hpp:113