Template Class StaticCircularBuffer

Class Documentation

template<typename T, typename Allocator = std::allocator<T>>
class StaticCircularBuffer

CircularBuffer implementation that does not perform allocations/deallocations outside of the constructor, destructor and resize methods.

The Buffer can only be used by reading/writing to the existing elements

Cannot use boost::circular_buffer because popping a vector destroys it and deallocates memory

Public Types

typedef std::vector<T, Allocator> VectorType

Public Functions

inline StaticCircularBuffer(size_t max_size, const T &val, const Allocator &alloc = Allocator())
inline StaticCircularBuffer()
inline void clear()

clear Change the size of the buffer to 0 (not capacity) Only modifies internal iterators

inline void set_capacity(size_t max_size, const T &val)

set_capacity Allocates memory for max_size copies of val

Parameters:

Resets – the beginning and end iterators, which reduces the size of the buffer to zero

inline size_t capacity() const
inline size_t size() const
inline T &front()
inline T &push_back()

push_back Increases the buffer size (not capacity) by one, and returns a reference to the last item in the buffer. This item may have been used in the past

If the buffer becomes full, the returned reference already contains an item

inline void pop_front()

pop_front Reduces buffer size by one, advancing the begin iterator

inline VectorType &getBuffer()

getBuffer Provides a reference to the internal data structure, use at your own risk.

Returns: