33 #ifndef xmmCircularbuffer_h 34 #define xmmCircularbuffer_h 48 template <
typename T,
unsigned int channels = 1>
57 for (
int c = 0; c < channels; c++) {
68 T
operator()(
unsigned int channel,
unsigned int index)
const {
69 if (channel >= channels)
70 throw std::out_of_range(
"CircularBuffer: channel out of bounds");
73 throw std::out_of_range(
"CircularBuffer: index out of bounds");
74 return data_[channel][index];
92 throw std::invalid_argument(
"You must pass a vector or array");
104 for (
int c = 0; c < channels; c++) {
116 void push(std::vector<T>
const &value) {
117 for (
int c = 0; c < channels; c++) {
151 for (
int c = 0; c < channels; c++) {
161 std::vector<T> _mean(channels, 0.0);
163 for (
int c = 0; c < channels; c++) {
164 for (
int i = 0; i <
size; i++) {
165 _mean[c] +=
data_[c][i];
unsigned int size_t() const
Get the actual size of the CircularBuffer (< size() if the buffer is not full)
Definition: xmmCircularbuffer.hpp:136
void push(T const *value)
Add an element to the buffer (multi-channel method)
Definition: xmmCircularbuffer.hpp:103
Simple CircularBuffer Class.
Definition: xmmCircularbuffer.hpp:49
T operator()(unsigned int channel, unsigned int index) const
Access data by index & channel.
Definition: xmmCircularbuffer.hpp:68
void push(std::vector< T > const &value)
Add an element to the buffer (multi-channel method)
Definition: xmmCircularbuffer.hpp:116
unsigned int length_
length of the buffer
Definition: xmmCircularbuffer.hpp:181
void clear()
Clear the content of the buffer.
Definition: xmmCircularbuffer.hpp:80
std::vector< T > mean() const
Compute the mean of the buffer.
Definition: xmmCircularbuffer.hpp:160
void push(T const value)
Add an element to the buffer (single-channel method)
Definition: xmmCircularbuffer.hpp:90
std::vector< T > data_[channels]
buffer data
Definition: xmmCircularbuffer.hpp:176
unsigned int current_index_
current index in the buffer
Definition: xmmCircularbuffer.hpp:186
CircularBuffer(unsigned int length=1)
Constructor.
Definition: xmmCircularbuffer.hpp:55
Definition: xmmAttribute.hpp:42
void resize(unsigned int length)
Resize the buffer to a specific length.
Definition: xmmCircularbuffer.hpp:142
bool full_
Defines if the CircularBuffer is already full.
Definition: xmmCircularbuffer.hpp:191
unsigned int size() const
Get the size of the CircularBuffer.
Definition: xmmCircularbuffer.hpp:129