Template Class circular_buffer

Class Documentation

template<typename T>
class circular_buffer

A circular buffer of fixed size (defined at construction-time), implemented with a std::vector as the underlying storage.

Note

Defined in #include <mrpt/containers/circular_buffer.h>

Public Functions

inline circular_buffer(size_t size)
inline void push(T d)

Insert a copy of the given element in the buffer.

Throws:

std::out_of_range – If the buffer run out of space.

inline void push_ref(const T &d)

Insert a reference of the given element in the buffer.

Throws:

std::out_of_range – If the buffer run out of space.

inline void push_many(T *array_elements, size_t count)

Insert an array of elements in the buffer.

Throws:

std::out_of_range – If the buffer run out of space.

inline T pop()

Retrieve an element from the buffer.

Throws:

std::out_of_range – If the buffer is empty.

inline void pop(T &out_val)

Retrieve an element from the buffer.

Throws:

std::out_of_range – If the buffer is empty.

inline void pop_many(T *out_array, size_t count)

Pop a number of elements into a user-provided array.

Throws:

std::out_of_range – If the buffer has less elements than requested.

inline T peek() const

Peek (see without modifying) what is to be read from the buffer if pop() was to be called.

Throws:

std::out_of_range – If the buffer is empty.

inline T peek(size_t index) const

Like peek(), but seeking ahead in the buffer (index=0 means the immediate next element, index=1 the following one, etc.)

Throws:

std::out_of_range – If trying to read passing the number of available elements.

inline 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.

Throws:

std::out_of_range – If the buffer has less elements than requested.

inline size_t size() const

Return the number of elements available for read (“pop”) in the buffer (this is NOT the maximum size of the internal buffer)

See also

capacity

inline size_t capacity() const

Return the maximum capacity of the buffer.

See also

size

inline size_t available() const

The maximum number of elements that can be written (“push”) without rising an overflow error.

inline void clear()

Delete all the stored data, if any.