template class mrpt::containers::circular_buffer

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

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

#include <mrpt/containers/circular_buffer.h>

template <typename T>
class circular_buffer
{
public:
    // construction

    circular_buffer(const size_t size);

    //
methods

    void push(T d);
    void push_ref(const T& d);
    void push_many(T* array_elements, size_t count);
    T pop();
    void pop(T& out_val);
    void pop_many(T* out_array, size_t count);
    T peek() const;
    T peek(size_t index) const;
    void peek_many(T* out_array, size_t count) const;
    size_t size() const;
    size_t capacity() const;
    size_t available() const;
    void clear();
};

Methods

void push(T d)

Insert a copy of the given element in the buffer.

Parameters:

std::out_of_range

If the buffer run out of space.

void push_ref(const T& d)

Insert a reference of the given element in the buffer.

Parameters:

std::out_of_range

If the buffer run out of space.

void push_many(T* array_elements, size_t count)

Insert an array of elements in the buffer.

Parameters:

std::out_of_range

If the buffer run out of space.

T pop()

Retrieve an element from the buffer.

Parameters:

std::out_of_range

If the buffer is empty.

void pop(T& out_val)

Retrieve an element from the buffer.

Parameters:

std::out_of_range

If the buffer is empty.

void pop_many(T* out_array, size_t count)

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

Parameters:

std::out_of_range

If the buffer has less elements than requested.

T peek() const

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

Parameters:

std::out_of_range

If the buffer is empty.

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

Parameters:

std::out_of_range

If trying to read passing the number of available elements.

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.

Parameters:

std::out_of_range

If the buffer has less elements than requested.

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

size_t capacity() const

Return the maximum capacity of the buffer.

See also:

size

size_t available() const

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

void clear()

Delete all the stored data, if any.