Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::cnt::sringbuffer< T, N > Class Template Reference

Array of elements of type. More...

#include <sringbuffer.h>

Public Types

using value_type = T
 Element value type.
 
using reference = T &
 Mutable element reference.
 
using const_reference = const T &
 Immutable element reference.
 
using pointer = T *
 Mutable element pointer.
 
using const_pointer = const T *
 Immutable element pointer.
 
using difference_type = sringbuffer_detail::size_type
 Type used for iterator distances.
 
using size_type = sringbuffer_detail::size_type
 Type used for sizes and indices.
 
using iterator = sringbuffer_iterator< T, N >
 Mutable random-access iterator.
 
using const_iterator = sringbuffer_iterator< const T, N >
 Immutable random-access iterator.
 
using iterator_category = core::random_access_iterator_tag
 Iterator category tag.
 

Public Member Functions

template<typename InputIt >
constexpr sringbuffer (InputIt first, InputIt last) noexcept
 Constructs a ring buffer from an iterator range.
 
constexpr sringbuffer (std::initializer_list< T > il) noexcept
 Constructs a ring buffer from an initializer list.
 
constexpr sringbuffer (const sringbuffer &other) noexcept
 Copy-constructs a ring buffer.
 
constexpr sringbuffer (sringbuffer &&other) noexcept
 Move-constructs a ring buffer and leaves the source empty.
 
constexpr sringbufferoperator= (std::initializer_list< T > il) noexcept
 Assigns elements from an initializer list.
 
constexpr sringbufferoperator= (const sringbuffer &other)
 Copy-assigns a ring buffer.
 
constexpr sringbufferoperator= (sringbuffer &&other) noexcept
 Move-assigns a ring buffer and leaves the source empty.
 
constexpr void push_back (const T &arg)
 Appends a copied element.
 
constexpr void push_back (T &&arg)
 Appends a moved element.
 
constexpr void pop_front (T &out)
 Removes and copies the front element.
 
constexpr void pop_front (T &&out)
 Removes and moves the front element.
 
constexpr void pop_back (T &out)
 Removes and copies the back element.
 
constexpr void pop_back (T &&out)
 Removes and moves the back element.
 
GAIA_NODISCARD constexpr size_type size () const noexcept
 Returns the number of live elements.
 
GAIA_NODISCARD constexpr bool empty () const noexcept
 Checks whether the buffer is empty.
 
GAIA_NODISCARD constexpr size_type capacity () const noexcept
 Returns the fixed capacity.
 
GAIA_NODISCARD constexpr size_type max_size () const noexcept
 Returns the maximum element count.
 
GAIA_NODISCARD constexpr reference front () noexcept
 Returns the front element.
 
GAIA_NODISCARD constexpr const_reference front () const noexcept
 Returns the front element.
 
GAIA_NODISCARD constexpr reference back () noexcept
 Returns the back element.
 
GAIA_NODISCARD constexpr const_reference back () const noexcept
 Returns the back element.
 
GAIA_NODISCARD constexpr auto begin () noexcept
 Returns an iterator to the logical front.
 
GAIA_NODISCARD constexpr auto begin () const noexcept
 Returns an iterator to the logical front.
 
GAIA_NODISCARD constexpr auto cbegin () const noexcept
 Returns an iterator to the logical front.
 
GAIA_NODISCARD constexpr auto end () noexcept
 Returns the mutable end sentinel.
 
GAIA_NODISCARD constexpr auto end () const noexcept
 Returns the immutable end sentinel.
 
GAIA_NODISCARD constexpr auto cend () const noexcept
 Returns the immutable end sentinel.
 
GAIA_NODISCARD constexpr bool operator== (const sringbuffer &other) const
 Compares corresponding physical storage positions.
 

Public Attributes

size_type m_tail {}
 Physical index of the logical front element.
 
size_type m_size {}
 Number of live elements.
 
T m_data [N]
 Physical element storage.
 

Static Public Attributes

static constexpr size_type extent = N
 Compile-time buffer capacity.
 

Detailed Description

template<typename T, sringbuffer_detail::size_type N>
class gaia::cnt::sringbuffer< T, N >

Array of elements of type.

Template Parameters
Twith fixed size and capacity
Nallocated on stack working as a ring buffer. That means the element at position N-1 is followed by the element at the position 0. Interface compatiblity with std::array where it matters.

Constructor & Destructor Documentation

◆ sringbuffer() [1/4]

template<typename T , sringbuffer_detail::size_type N>
template<typename InputIt >
constexpr gaia::cnt::sringbuffer< T, N >::sringbuffer ( InputIt  first,
InputIt  last 
)
inlineconstexprnoexcept

Constructs a ring buffer from an iterator range.

Template Parameters
InputItInput iterator type.
Parameters
firstFirst element to copy.
lastSentinel following the last element to copy.

◆ sringbuffer() [2/4]

template<typename T , sringbuffer_detail::size_type N>
constexpr gaia::cnt::sringbuffer< T, N >::sringbuffer ( std::initializer_list< T il)
inlineconstexprnoexcept

Constructs a ring buffer from an initializer list.

Parameters
ilElements to copy in logical order.

◆ sringbuffer() [3/4]

template<typename T , sringbuffer_detail::size_type N>
constexpr gaia::cnt::sringbuffer< T, N >::sringbuffer ( const sringbuffer< T, N > &  other)
inlineconstexprnoexcept

Copy-constructs a ring buffer.

Parameters
otherRing buffer to copy.

◆ sringbuffer() [4/4]

template<typename T , sringbuffer_detail::size_type N>
constexpr gaia::cnt::sringbuffer< T, N >::sringbuffer ( sringbuffer< T, N > &&  other)
inlineconstexprnoexcept

Move-constructs a ring buffer and leaves the source empty.

Parameters
otherRing buffer whose elements are transferred.

Member Function Documentation

◆ back() [1/2]

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr const_reference gaia::cnt::sringbuffer< T, N >::back ( ) const
inlineconstexprnoexcept

Returns the back element.

Returns
Immutable reference to the logical back element.

◆ back() [2/2]

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr reference gaia::cnt::sringbuffer< T, N >::back ( )
inlineconstexprnoexcept

Returns the back element.

Returns
Mutable reference to the logical back element.

◆ begin() [1/2]

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sringbuffer< T, N >::begin ( ) const
inlineconstexprnoexcept

Returns an iterator to the logical front.

Returns
Immutable iterator to the first element.

◆ begin() [2/2]

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sringbuffer< T, N >::begin ( )
inlineconstexprnoexcept

Returns an iterator to the logical front.

Returns
Mutable iterator to the first element.

◆ capacity()

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr size_type gaia::cnt::sringbuffer< T, N >::capacity ( ) const
inlineconstexprnoexcept

Returns the fixed capacity.

Returns
N.

◆ cbegin()

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sringbuffer< T, N >::cbegin ( ) const
inlineconstexprnoexcept

Returns an iterator to the logical front.

Returns
Immutable iterator to the first element.

◆ cend()

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sringbuffer< T, N >::cend ( ) const
inlineconstexprnoexcept

Returns the immutable end sentinel.

Returns
Iterator following the last logical element.

◆ empty()

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr bool gaia::cnt::sringbuffer< T, N >::empty ( ) const
inlineconstexprnoexcept

Checks whether the buffer is empty.

Returns
True when size() is zero. False otherwise.

◆ end() [1/2]

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sringbuffer< T, N >::end ( ) const
inlineconstexprnoexcept

Returns the immutable end sentinel.

Returns
Iterator following the last logical element.

◆ end() [2/2]

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr auto gaia::cnt::sringbuffer< T, N >::end ( )
inlineconstexprnoexcept

Returns the mutable end sentinel.

Returns
Iterator following the last logical element.

◆ front() [1/2]

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr const_reference gaia::cnt::sringbuffer< T, N >::front ( ) const
inlineconstexprnoexcept

Returns the front element.

Returns
Immutable reference to the logical front element.

◆ front() [2/2]

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr reference gaia::cnt::sringbuffer< T, N >::front ( )
inlineconstexprnoexcept

Returns the front element.

Returns
Mutable reference to the logical front element.

◆ max_size()

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr size_type gaia::cnt::sringbuffer< T, N >::max_size ( ) const
inlineconstexprnoexcept

Returns the maximum element count.

Returns
N.

◆ operator=() [1/3]

template<typename T , sringbuffer_detail::size_type N>
constexpr sringbuffer & gaia::cnt::sringbuffer< T, N >::operator= ( const sringbuffer< T, N > &  other)
inlineconstexpr

Copy-assigns a ring buffer.

Parameters
otherRing buffer to copy.
Returns
This ring buffer.

◆ operator=() [2/3]

template<typename T , sringbuffer_detail::size_type N>
constexpr sringbuffer & gaia::cnt::sringbuffer< T, N >::operator= ( sringbuffer< T, N > &&  other)
inlineconstexprnoexcept

Move-assigns a ring buffer and leaves the source empty.

Parameters
otherRing buffer whose elements are transferred.
Returns
This ring buffer.

◆ operator=() [3/3]

template<typename T , sringbuffer_detail::size_type N>
constexpr sringbuffer & gaia::cnt::sringbuffer< T, N >::operator= ( std::initializer_list< T il)
inlineconstexprnoexcept

Assigns elements from an initializer list.

Parameters
ilElements to copy in logical order.
Returns
This ring buffer.

◆ operator==()

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr bool gaia::cnt::sringbuffer< T, N >::operator== ( const sringbuffer< T, N > &  other) const
inlineconstexpr

Compares corresponding physical storage positions.

Parameters
otherRing buffer to compare with.
Returns
True when every corresponding physical element differs. False otherwise.

◆ pop_back() [1/2]

template<typename T , sringbuffer_detail::size_type N>
constexpr void gaia::cnt::sringbuffer< T, N >::pop_back ( T &&  out)
inlineconstexpr

Removes and moves the back element.

Parameters
outDestination receiving the removed element.

◆ pop_back() [2/2]

template<typename T , sringbuffer_detail::size_type N>
constexpr void gaia::cnt::sringbuffer< T, N >::pop_back ( T out)
inlineconstexpr

Removes and copies the back element.

Parameters
outDestination receiving the removed element.

◆ pop_front() [1/2]

template<typename T , sringbuffer_detail::size_type N>
constexpr void gaia::cnt::sringbuffer< T, N >::pop_front ( T &&  out)
inlineconstexpr

Removes and moves the front element.

Parameters
outDestination receiving the removed element.

◆ pop_front() [2/2]

template<typename T , sringbuffer_detail::size_type N>
constexpr void gaia::cnt::sringbuffer< T, N >::pop_front ( T out)
inlineconstexpr

Removes and copies the front element.

Parameters
outDestination receiving the removed element.

◆ push_back() [1/2]

template<typename T , sringbuffer_detail::size_type N>
constexpr void gaia::cnt::sringbuffer< T, N >::push_back ( const T arg)
inlineconstexpr

Appends a copied element.

Parameters
argElement to append. The buffer must not be full.

◆ push_back() [2/2]

template<typename T , sringbuffer_detail::size_type N>
constexpr void gaia::cnt::sringbuffer< T, N >::push_back ( T &&  arg)
inlineconstexpr

Appends a moved element.

Parameters
argElement to move into the buffer. The buffer must not be full.

◆ size()

template<typename T , sringbuffer_detail::size_type N>
GAIA_NODISCARD constexpr size_type gaia::cnt::sringbuffer< T, N >::size ( ) const
inlineconstexprnoexcept

Returns the number of live elements.

Returns
Current element count.

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