Go to the documentation of this file.
9 #ifndef circular_buffer_H
10 #define circular_buffer_H
37 if (
m_size <= 2)
throw std::invalid_argument(
"size must be >2");
46 if (new_idx ==
m_size) new_idx = 0;
48 throw std::out_of_range(
"push: circular_buffer is full");
62 throw std::out_of_range(
"push: circular_buffer is full");
79 throw std::out_of_range(
"pop: circular_buffer is empty");
92 throw std::out_of_range(
"pop: circular_buffer is empty");
112 throw std::out_of_range(
"peek: circular_buffer is empty");
122 throw std::out_of_range(
"peek: seek out of range");
136 throw std::out_of_range(
"peek: circular_buffer is empty");
138 if (peek_read ==
m_size) peek_read = 0;
void peek_many(T *out_array, size_t count) const
Like peek(), for multiple elements, storing a number of elements into a user-provided array.
size_t m_size
not "const" to allow copy/move = ops.
void clear()
Delete all the stored data, if any.
T peek(size_t index) const
Like peek(), but seeking ahead in the buffer (index=0 means the immediate next element,...
void pop(T &out_val)
Retrieve an element from the buffer.
A circular buffer of fixed size (defined at construction-time), implemented with a std::vector as the...
void pop_many(T *out_array, size_t count)
Pop a number of elements into a user-provided array.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
circular_buffer(const size_t size)
size_t capacity() const
Return the maximum capacity of the buffer.
GLuint GLuint GLsizei count
size_t size() const
Return the number of elements available for read ("pop") in the buffer (this is NOT the maximum size ...
T peek() const
Peek (see without modifying) what is to be read from the buffer if pop() was to be called.
T pop()
Retrieve an element from the buffer.
void push_ref(const T &d)
Insert a reference of the given element in the buffer.
void push_many(T *array_elements, size_t count)
Insert an array of elements in the buffer.
size_t available() const
The maximum number of elements that can be written ("push") without rising an overflow error.
void push(T d)
Insert a copy of the given element in the buffer.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |