RADLib
RADical C++ application framework
RADData::RADRingBuffer< T, Alloc > Class Template Reference

Power-of-two circular buffer with push/pop at both ends. More...

#include <RADDataStructures.h>

Classes

class  const_iterator
 Const forward iterator over logical ring order. More...
 
class  iterator
 Forward iterator over logical ring order. More...
 

Public Member Functions

 RADRingBuffer (size_t capacity=16)
 Creates a ring buffer with at least capacity slots. More...
 
 ~RADRingBuffer ()
 Destroys elements and releases storage. More...
 
 RADRingBuffer (const RADRingBuffer &other)
 Copies another ring buffer in logical order. More...
 
RADRingBufferoperator= (const RADRingBuffer &other)
 Replaces this buffer with a copy of other. More...
 
 RADRingBuffer (RADRingBuffer &&other) noexcept
 Moves another ring buffer without moving individual elements. More...
 
RADRingBufferoperator= (RADRingBuffer &&other) noexcept
 Replaces this buffer by taking other's storage. More...
 
iterator begin () noexcept
 Returns iterator to the logical first element. More...
 
iterator end () noexcept
 Returns iterator one past the logical last element. More...
 
const_iterator begin () const noexcept
 Returns const iterator to the logical first element. More...
 
const_iterator end () const noexcept
 Returns const iterator one past the logical last element. More...
 
bool empty () const noexcept
 Returns true when no elements are stored. More...
 
size_t size () const noexcept
 Returns number of stored elements. More...
 
size_t capacity () const noexcept
 Returns allocated ring capacity. More...
 
T & operator[] (size_t index) noexcept
 Returns logical element index without bounds checking. More...
 
const T & operator[] (size_t index) const noexcept
 Returns const logical element index without bounds checking. More...
 
T & front () noexcept
 Returns first logical element. More...
 
const T & front () const noexcept
 Returns first logical element. More...
 
T & back () noexcept
 Returns last logical element. More...
 
const T & back () const noexcept
 Returns last logical element. More...
 
void reserve (size_t requestedCapacity)
 Ensures capacity is at least requestedCapacity. More...
 
template<typename... Args>
T & emplace_back (Args &&... args)
 Constructs an element at the logical back. More...
 
template<typename... Args>
T & emplace_front (Args &&... args)
 Constructs an element at the logical front. More...
 
void push_back (const T &value)
 Appends a copy at the back. More...
 
void push_back (T &&value)
 Appends a moved value at the back. More...
 
void push_front (const T &value)
 Prepends a copy at the front. More...
 
void push_front (T &&value)
 Prepends a moved value at the front. More...
 
void pop_front ()
 Removes the logical first element. More...
 
void pop_back ()
 Removes the logical last element. More...
 
void clear () noexcept
 Destroys all elements while keeping storage. More...
 

Detailed Description

template<typename T, typename Alloc = std::allocator<T>>
class RADData::RADRingBuffer< T, Alloc >

Power-of-two circular buffer with push/pop at both ends.

Constructor & Destructor Documentation

◆ RADRingBuffer() [1/3]

template<typename T , typename Alloc = std::allocator<T>>
RADData::RADRingBuffer< T, Alloc >::RADRingBuffer ( size_t  capacity = 16)
inlineexplicit

Creates a ring buffer with at least capacity slots.

◆ ~RADRingBuffer()

template<typename T , typename Alloc = std::allocator<T>>
RADData::RADRingBuffer< T, Alloc >::~RADRingBuffer ( )
inline

Destroys elements and releases storage.

◆ RADRingBuffer() [2/3]

template<typename T , typename Alloc = std::allocator<T>>
RADData::RADRingBuffer< T, Alloc >::RADRingBuffer ( const RADRingBuffer< T, Alloc > &  other)
inline

Copies another ring buffer in logical order.

◆ RADRingBuffer() [3/3]

template<typename T , typename Alloc = std::allocator<T>>
RADData::RADRingBuffer< T, Alloc >::RADRingBuffer ( RADRingBuffer< T, Alloc > &&  other)
inlinenoexcept

Moves another ring buffer without moving individual elements.

Member Function Documentation

◆ back() [1/2]

template<typename T , typename Alloc = std::allocator<T>>
const T& RADData::RADRingBuffer< T, Alloc >::back ( ) const
inlinenoexcept

Returns last logical element.

◆ back() [2/2]

template<typename T , typename Alloc = std::allocator<T>>
T& RADData::RADRingBuffer< T, Alloc >::back ( )
inlinenoexcept

Returns last logical element.

◆ begin() [1/2]

template<typename T , typename Alloc = std::allocator<T>>
const_iterator RADData::RADRingBuffer< T, Alloc >::begin ( ) const
inlinenoexcept

Returns const iterator to the logical first element.

◆ begin() [2/2]

template<typename T , typename Alloc = std::allocator<T>>
iterator RADData::RADRingBuffer< T, Alloc >::begin ( )
inlinenoexcept

Returns iterator to the logical first element.

◆ capacity()

template<typename T , typename Alloc = std::allocator<T>>
size_t RADData::RADRingBuffer< T, Alloc >::capacity ( ) const
inlinenoexcept

Returns allocated ring capacity.

◆ clear()

template<typename T , typename Alloc = std::allocator<T>>
void RADData::RADRingBuffer< T, Alloc >::clear ( )
inlinenoexcept

Destroys all elements while keeping storage.

◆ emplace_back()

template<typename T , typename Alloc = std::allocator<T>>
template<typename... Args>
T& RADData::RADRingBuffer< T, Alloc >::emplace_back ( Args &&...  args)
inline

Constructs an element at the logical back.

◆ emplace_front()

template<typename T , typename Alloc = std::allocator<T>>
template<typename... Args>
T& RADData::RADRingBuffer< T, Alloc >::emplace_front ( Args &&...  args)
inline

Constructs an element at the logical front.

◆ empty()

template<typename T , typename Alloc = std::allocator<T>>
bool RADData::RADRingBuffer< T, Alloc >::empty ( ) const
inlinenoexcept

Returns true when no elements are stored.

◆ end() [1/2]

template<typename T , typename Alloc = std::allocator<T>>
const_iterator RADData::RADRingBuffer< T, Alloc >::end ( ) const
inlinenoexcept

Returns const iterator one past the logical last element.

◆ end() [2/2]

template<typename T , typename Alloc = std::allocator<T>>
iterator RADData::RADRingBuffer< T, Alloc >::end ( )
inlinenoexcept

Returns iterator one past the logical last element.

◆ front() [1/2]

template<typename T , typename Alloc = std::allocator<T>>
const T& RADData::RADRingBuffer< T, Alloc >::front ( ) const
inlinenoexcept

Returns first logical element.

◆ front() [2/2]

template<typename T , typename Alloc = std::allocator<T>>
T& RADData::RADRingBuffer< T, Alloc >::front ( )
inlinenoexcept

Returns first logical element.

◆ operator=() [1/2]

template<typename T , typename Alloc = std::allocator<T>>
RADRingBuffer& RADData::RADRingBuffer< T, Alloc >::operator= ( const RADRingBuffer< T, Alloc > &  other)
inline

Replaces this buffer with a copy of other.

◆ operator=() [2/2]

template<typename T , typename Alloc = std::allocator<T>>
RADRingBuffer& RADData::RADRingBuffer< T, Alloc >::operator= ( RADRingBuffer< T, Alloc > &&  other)
inlinenoexcept

Replaces this buffer by taking other's storage.

◆ operator[]() [1/2]

template<typename T , typename Alloc = std::allocator<T>>
const T& RADData::RADRingBuffer< T, Alloc >::operator[] ( size_t  index) const
inlinenoexcept

Returns const logical element index without bounds checking.

◆ operator[]() [2/2]

template<typename T , typename Alloc = std::allocator<T>>
T& RADData::RADRingBuffer< T, Alloc >::operator[] ( size_t  index)
inlinenoexcept

Returns logical element index without bounds checking.

◆ pop_back()

template<typename T , typename Alloc = std::allocator<T>>
void RADData::RADRingBuffer< T, Alloc >::pop_back ( )
inline

Removes the logical last element.

◆ pop_front()

template<typename T , typename Alloc = std::allocator<T>>
void RADData::RADRingBuffer< T, Alloc >::pop_front ( )
inline

Removes the logical first element.

◆ push_back() [1/2]

template<typename T , typename Alloc = std::allocator<T>>
void RADData::RADRingBuffer< T, Alloc >::push_back ( const T &  value)
inline

Appends a copy at the back.

◆ push_back() [2/2]

template<typename T , typename Alloc = std::allocator<T>>
void RADData::RADRingBuffer< T, Alloc >::push_back ( T &&  value)
inline

Appends a moved value at the back.

◆ push_front() [1/2]

template<typename T , typename Alloc = std::allocator<T>>
void RADData::RADRingBuffer< T, Alloc >::push_front ( const T &  value)
inline

Prepends a copy at the front.

◆ push_front() [2/2]

template<typename T , typename Alloc = std::allocator<T>>
void RADData::RADRingBuffer< T, Alloc >::push_front ( T &&  value)
inline

Prepends a moved value at the front.

◆ reserve()

template<typename T , typename Alloc = std::allocator<T>>
void RADData::RADRingBuffer< T, Alloc >::reserve ( size_t  requestedCapacity)
inline

Ensures capacity is at least requestedCapacity.

◆ size()

template<typename T , typename Alloc = std::allocator<T>>
size_t RADData::RADRingBuffer< T, Alloc >::size ( ) const
inlinenoexcept

Returns number of stored elements.


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