File ring_buffer.hpp

template<typename T>
class RingBuffer : private ViewDecorator<AllocatedVector<T>>
#include <ring_buffer.hpp>

A ring buffer with fixed capacity.

Template Parameters:

T – The type of the values that are stored in the buffer

Public Types

typedef View<T>::const_iterator const_iterator

An iterator that provides read-only access to the elements in the buffer.

Public Functions

inline RingBuffer(uint32 capacity)
Parameters:

capacity – The maximum capacity of the buffer. Must be at least 1

inline const_iterator cbegin() const

Returns a const_iterator to the beginning of the buffer.

Returns:

A const_iterator to the beginning

inline const_iterator cend() const

Returns a const_iterator to the end of the buffer.

Returns:

A const_iterator to the end

inline uint32 getCapacity() const

Returns the maximum capacity of the buffer.

Returns:

The maximum capacity

inline uint32 getNumElements() const

Returns the number of values in the buffer.

Returns:

The number of values

inline bool isFull() const

Returns whether the maximum capacity of the buffer has been reached or not.

Returns:

True, if the maximum capacity has been reached, false otherwise

inline std::pair<bool, T> push(T value)

Adds a new value to the buffer. If the maximum capacity of the buffer has been reached, the oldest value will be overwritten.

Parameters:

value – The value to be added

Returns:

A std::pair, whose first value indicates whether a value has been overwritten or not. If a value has been overwritten, the pair’s second value is set to the overwritten value, otherwise it is undefined

Private Members

uint32 pos_
bool full_