Cbeam
Loading...
Searching...
No Matches
cbeam::container::circular_buffer< T, S > Class Template Reference

A template class representing a circular buffer. More...

#include <circular_buffer.hpp>

Public Types

using value_type = T
 
using size_type = std::size_t
 
using reference = value_type&
 
using const_reference = const value_type&
 
using iterator = typename std::array<T, S>::iterator
 
using const_iterator = typename std::array<T, S>::const_iterator
 

Public Member Functions

 circular_buffer ()=default
 Default constructor.
 
auto begin () noexcept
 Gets an iterator to the beginning of the buffer.
 
auto end () noexcept
 Gets an iterator to the end of the buffer.
 
std::size_t size () const
 Gets the number of elements in the buffer.
 
std::size_t max_size () const
 Gets the maximum number of elements the buffer can hold.
 
void push_back (const T &t)
 Adds an element to the back of the buffer.
 
bool empty () const noexcept
 
void clear () noexcept
 
template<typename... Args>
void emplace_back (Args &&... args)
 Adds an element to the back of the buffer.
 
reference at (size_type pos)
 Accesses the element at specified location with bounds checking.
 
const_reference at (size_type pos) const
 Accesses the element at specified location with bounds checking (const version).
 
reference operator[] (size_type pos)
 Accesses the element at specified location without bounds checking.
 
const_reference operator[] (size_type pos) const
 Accesses the element at specified location without bounds checking (const version).
 
reference front ()
 Accesses the first element in the buffer.
 
const_reference front () const
 Accesses the first element in the buffer (const version).
 
reference back ()
 Accesses the last element in the buffer.
 
const_reference back () const
 Accesses the last element in the buffer (const version).
 

Detailed Description

template<typename T, std::size_t S>
class cbeam::container::circular_buffer< T, S >

A template class representing a circular buffer.

This class implements a circular buffer of fixed size. It provides basic iterator access and allows elements to be added to the back, automatically overwriting the oldest elements once the buffer is full.

Template Parameters
TThe type of elements in the buffer.
SThe fixed size of the buffer.

Member Typedef Documentation

◆ const_iterator

template<typename T, std::size_t S>
using cbeam::container::circular_buffer< T, S >::const_iterator = typename std::array<T, S>::const_iterator

◆ const_reference

template<typename T, std::size_t S>
using cbeam::container::circular_buffer< T, S >::const_reference = const value_type&

◆ iterator

template<typename T, std::size_t S>
using cbeam::container::circular_buffer< T, S >::iterator = typename std::array<T, S>::iterator

◆ reference

template<typename T, std::size_t S>
using cbeam::container::circular_buffer< T, S >::reference = value_type&

◆ size_type

template<typename T, std::size_t S>
using cbeam::container::circular_buffer< T, S >::size_type = std::size_t

◆ value_type

template<typename T, std::size_t S>
using cbeam::container::circular_buffer< T, S >::value_type = T

Constructor & Destructor Documentation

◆ circular_buffer()

template<typename T, std::size_t S>
cbeam::container::circular_buffer< T, S >::circular_buffer ( )
default

Default constructor.

Member Function Documentation

◆ at() [1/2]

template<typename T, std::size_t S>
reference cbeam::container::circular_buffer< T, S >::at ( size_type pos)
inline

Accesses the element at specified location with bounds checking.

Parameters
posThe position of the element to return.
Returns
A reference to the element at specified location.
Exceptions
cbeam::error::out_of_rangeif pos is out of range.

◆ at() [2/2]

template<typename T, std::size_t S>
const_reference cbeam::container::circular_buffer< T, S >::at ( size_type pos) const
inline

Accesses the element at specified location with bounds checking (const version).

Parameters
posThe position of the element to return.
Returns
A const reference to the element at specified location.
Exceptions
cbeam::error::out_of_rangeif pos is out of range.

◆ back() [1/2]

template<typename T, std::size_t S>
reference cbeam::container::circular_buffer< T, S >::back ( )
inline

Accesses the last element in the buffer.

Returns
A reference to the last element.

◆ back() [2/2]

template<typename T, std::size_t S>
const_reference cbeam::container::circular_buffer< T, S >::back ( ) const
inline

Accesses the last element in the buffer (const version).

Returns
A const reference to the last element.

◆ begin()

template<typename T, std::size_t S>
auto cbeam::container::circular_buffer< T, S >::begin ( )
inlinenoexcept

Gets an iterator to the beginning of the buffer.

Returns
An iterator to the first element.

◆ clear()

template<typename T, std::size_t S>
void cbeam::container::circular_buffer< T, S >::clear ( )
inlinenoexcept

◆ emplace_back()

template<typename T, std::size_t S>
template<typename... Args>
void cbeam::container::circular_buffer< T, S >::emplace_back ( Args &&... args)
inline

Adds an element to the back of the buffer.

This method adds a new element to the back of the buffer by moving it, potentially overwriting the oldest element if the buffer is full.

Parameters
argsThe element to add.

◆ empty()

template<typename T, std::size_t S>
bool cbeam::container::circular_buffer< T, S >::empty ( ) const
inlinenoexcept

◆ end()

template<typename T, std::size_t S>
auto cbeam::container::circular_buffer< T, S >::end ( )
inlinenoexcept

Gets an iterator to the end of the buffer.

Returns
An iterator to the element following the last element.

◆ front() [1/2]

template<typename T, std::size_t S>
reference cbeam::container::circular_buffer< T, S >::front ( )
inline

Accesses the first element in the buffer.

Returns
A reference to the first element.

◆ front() [2/2]

template<typename T, std::size_t S>
const_reference cbeam::container::circular_buffer< T, S >::front ( ) const
inline

Accesses the first element in the buffer (const version).

Returns
A const reference to the first element.

◆ max_size()

template<typename T, std::size_t S>
std::size_t cbeam::container::circular_buffer< T, S >::max_size ( ) const
inline

Gets the maximum number of elements the buffer can hold.

Returns
The maximum size of the buffer.

◆ operator[]() [1/2]

template<typename T, std::size_t S>
reference cbeam::container::circular_buffer< T, S >::operator[] ( size_type pos)
inline

Accesses the element at specified location without bounds checking.

Parameters
posThe position of the element to return.
Returns
A reference to the element at specified location.

◆ operator[]() [2/2]

template<typename T, std::size_t S>
const_reference cbeam::container::circular_buffer< T, S >::operator[] ( size_type pos) const
inline

Accesses the element at specified location without bounds checking (const version).

Parameters
posThe position of the element to return.
Returns
A const reference to the element at specified location.

◆ push_back()

template<typename T, std::size_t S>
void cbeam::container::circular_buffer< T, S >::push_back ( const T & t)
inline

Adds an element to the back of the buffer.

This method adds a new element to the back of the buffer, potentially overwriting the oldest element if the buffer is full.

Parameters
tThe element to add.

◆ size()

template<typename T, std::size_t S>
std::size_t cbeam::container::circular_buffer< T, S >::size ( ) const
inline

Gets the number of elements in the buffer.

Returns
The number of elements in the buffer.

The documentation for this class was generated from the following file: