PIDUINO
Loading...
Searching...
No Matches
Piduino::RingBuffer< T, A >

STL-style circular buffer. More...

#include <ringbuffer.h>

Collaboration diagram for Piduino::RingBuffer< T, A >:

Classes

class  iterator_
 RingBuffer iterator class template. More...
 

Public Types

typedef RingBuffer< T, A > self_type
 
typedef A allocator_type
 
typedef allocator_type::value_type value_type
 
typedef allocator_type::pointer pointer
 
typedef allocator_type::const_pointer const_pointer
 
typedef allocator_type::reference reference
 
typedef allocator_type::const_reference const_reference
 
typedef allocator_type::size_type size_type
 
typedef allocator_type::difference_type difference_type
 
typedef iterator_< value_type, value_typeiterator
 
typedef iterator_< const value_type, value_typeconst_iterator
 
typedef std::reverse_iterator< iteratorreverse_iterator
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 

Public Member Functions

 RingBuffer (size_type const capacity=1, allocator_type const &allocator=allocator_type())
 Default constructor.
 
 RingBuffer (self_type const &other)
 Copy constructor.
 
template<typename II >
 RingBuffer (II const from, II const to)
 ??
 
 ~RingBuffer ()
 Destructor.
 
RingBufferoperator= (self_type other)
 copy-swap idiom using value parameter
 
void swap (self_type &other)
 
allocator_type get_allocator () const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
reverse_iterator rbegin ()
 
reverse_iterator rend ()
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator rend () const
 
bool empty () const
 
size_type capacity () const
 
size_type size () const
 
size_type max_size () const
 
void reserve (size_type const new_size)
 reserve shrinks or expands the internal buffer to the size given
 
reference front ()
 access the first element
 
reference back ()
 access the last element
 
const_reference front () const
 access the first element
 
const_reference back () const
 access the last element
 
const_reference operator[] (size_type const n) const
 
const_reference at (size_type const n) const
 
void clear ()
 
void push_back (value_type const &item)
 Appends the given item to the end of the container.
 
void push_front (value_type const &item)
 Insert a new element at the beginning of the container.
 
void pop_front ()
 Removes the first element of the container.
 
void pop_back ()
 Remove the last element from the container.
 
void skip (size_type len)
 
void chop (size_type len)
 
reference operator[] (size_type const n)
 
reference at (size_type const n)
 
pointer getimpl ()
 

Private Member Functions

reference at_unchecked (size_type const index) const
 
reference at_checked (size_type const index) const
 
size_type normalise (size_type const n) const
 
size_type index_to_subscript (size_type const index) const
 
void increment_tail ()
 
void decrement_tail ()
 
size_type next_tail ()
 
size_type previous_tail ()
 
size_type previous_head ()
 
void increment_head ()
 
void decrement_head ()
 
template<typename I >
void assign_into (I from, I const to)
 

Private Attributes

size_type m_capacity
 
allocator_type m_allocator
 
pointer m_array
 
size_type m_head
 
size_type m_tail
 
size_type m_contents_size
 

Detailed Description

template<typename T, typename A = std::allocator<T>>
class Piduino::RingBuffer< T, A >

STL-style circular buffer.

Definition at line 67 of file ringbuffer.h.

Member Typedef Documentation

◆ allocator_type

template<typename T , typename A = std::allocator<T>>
typedef A Piduino::RingBuffer< T, A >::allocator_type

Definition at line 71 of file ringbuffer.h.

◆ const_iterator

template<typename T , typename A = std::allocator<T>>
typedef iterator_<const value_type, value_type> Piduino::RingBuffer< T, A >::const_iterator

Definition at line 350 of file ringbuffer.h.

◆ const_pointer

template<typename T , typename A = std::allocator<T>>
typedef allocator_type::const_pointer Piduino::RingBuffer< T, A >::const_pointer

Definition at line 74 of file ringbuffer.h.

◆ const_reference

template<typename T , typename A = std::allocator<T>>
typedef allocator_type::const_reference Piduino::RingBuffer< T, A >::const_reference

Definition at line 76 of file ringbuffer.h.

◆ const_reverse_iterator

template<typename T , typename A = std::allocator<T>>
typedef std::reverse_iterator<const_iterator> Piduino::RingBuffer< T, A >::const_reverse_iterator

Definition at line 353 of file ringbuffer.h.

◆ difference_type

template<typename T , typename A = std::allocator<T>>
typedef allocator_type::difference_type Piduino::RingBuffer< T, A >::difference_type

Definition at line 78 of file ringbuffer.h.

◆ iterator

template<typename T , typename A = std::allocator<T>>
typedef iterator_<value_type, value_type> Piduino::RingBuffer< T, A >::iterator

Definition at line 349 of file ringbuffer.h.

◆ pointer

template<typename T , typename A = std::allocator<T>>
typedef allocator_type::pointer Piduino::RingBuffer< T, A >::pointer

Definition at line 73 of file ringbuffer.h.

◆ reference

template<typename T , typename A = std::allocator<T>>
typedef allocator_type::reference Piduino::RingBuffer< T, A >::reference

Definition at line 75 of file ringbuffer.h.

◆ reverse_iterator

template<typename T , typename A = std::allocator<T>>
typedef std::reverse_iterator<iterator> Piduino::RingBuffer< T, A >::reverse_iterator

Definition at line 352 of file ringbuffer.h.

◆ self_type

template<typename T , typename A = std::allocator<T>>
typedef RingBuffer<T, A> Piduino::RingBuffer< T, A >::self_type

Definition at line 70 of file ringbuffer.h.

◆ size_type

template<typename T , typename A = std::allocator<T>>
typedef allocator_type::size_type Piduino::RingBuffer< T, A >::size_type

Definition at line 77 of file ringbuffer.h.

◆ value_type

template<typename T , typename A = std::allocator<T>>
typedef allocator_type::value_type Piduino::RingBuffer< T, A >::value_type

Definition at line 72 of file ringbuffer.h.

Constructor & Destructor Documentation

◆ RingBuffer() [1/3]

template<typename T , typename A = std::allocator<T>>
Piduino::RingBuffer< T, A >::RingBuffer ( size_type const  capacity = 1,
allocator_type const &  allocator = allocator_type() 
)
inlineexplicit

Default constructor.

Parameters
capacity
allocator

Definition at line 88 of file ringbuffer.h.

◆ RingBuffer() [2/3]

template<typename T , typename A = std::allocator<T>>
Piduino::RingBuffer< T, A >::RingBuffer ( self_type const &  other)
inline

Copy constructor.

copy-initialiser constructor must be non-explicit for operator=()

Parameters
other
Returns

Definition at line 104 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::assign_into(), Piduino::RingBuffer< T, A >::begin(), Piduino::RingBuffer< T, A >::clear(), Piduino::RingBuffer< T, A >::end(), Piduino::RingBuffer< T, A >::m_allocator, Piduino::RingBuffer< T, A >::m_array, and Piduino::RingBuffer< T, A >::m_capacity.

Here is the call graph for this function:

◆ RingBuffer() [3/3]

template<typename T , typename A = std::allocator<T>>
template<typename II >
Piduino::RingBuffer< T, A >::RingBuffer ( II const  from,
II const  to 
)
inline

??

Parameters
from
to

Definition at line 129 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::assign_into(), and Piduino::RingBuffer< T, A >::swap().

Here is the call graph for this function:

◆ ~RingBuffer()

template<typename T , typename A = std::allocator<T>>
Piduino::RingBuffer< T, A >::~RingBuffer ( )
inline

Destructor.

Definition at line 145 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::clear(), Piduino::RingBuffer< T, A >::m_allocator, Piduino::RingBuffer< T, A >::m_array, and Piduino::RingBuffer< T, A >::m_capacity.

Here is the call graph for this function:

Member Function Documentation

◆ assign_into()

template<typename T , typename A = std::allocator<T>>
template<typename I >
void Piduino::RingBuffer< T, A >::assign_into ( from,
I const  to 
)
inlineprivate

Definition at line 753 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::clear(), Piduino::RingBuffer< T, A >::m_contents_size, and Piduino::RingBuffer< T, A >::push_back().

Referenced by Piduino::RingBuffer< T, A >::reserve(), Piduino::RingBuffer< T, A >::RingBuffer(), and Piduino::RingBuffer< T, A >::RingBuffer().

Here is the call graph for this function:

◆ at() [1/2]

template<typename T , typename A = std::allocator<T>>
reference Piduino::RingBuffer< T, A >::at ( size_type const  n)
inline
Parameters
n
Returns

Definition at line 675 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::at_checked().

Here is the call graph for this function:

◆ at() [2/2]

template<typename T , typename A = std::allocator<T>>
const_reference Piduino::RingBuffer< T, A >::at ( size_type const  n) const
inline
Parameters
n
Returns

Definition at line 544 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::at_checked().

Here is the call graph for this function:

◆ at_checked()

template<typename T , typename A = std::allocator<T>>
reference Piduino::RingBuffer< T, A >::at_checked ( size_type const  index) const
inlineprivate

Definition at line 694 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::at_unchecked(), and Piduino::RingBuffer< T, A >::m_contents_size.

Referenced by Piduino::RingBuffer< T, A >::at(), and Piduino::RingBuffer< T, A >::at().

Here is the call graph for this function:

◆ at_unchecked()

template<typename T , typename A = std::allocator<T>>
reference Piduino::RingBuffer< T, A >::at_unchecked ( size_type const  index) const
inlineprivate

Definition at line 690 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::index_to_subscript(), and Piduino::RingBuffer< T, A >::m_array.

Referenced by Piduino::RingBuffer< T, A >::at_checked(), Piduino::RingBuffer< T, A >::operator[](), and Piduino::RingBuffer< T, A >::operator[]().

Here is the call graph for this function:

◆ back() [1/2]

template<typename T , typename A = std::allocator<T>>
reference Piduino::RingBuffer< T, A >::back ( )
inline

access the last element

Returns

Definition at line 506 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_array, and Piduino::RingBuffer< T, A >::m_tail.

◆ back() [2/2]

template<typename T , typename A = std::allocator<T>>
const_reference Piduino::RingBuffer< T, A >::back ( ) const
inline

access the last element

Returns

Definition at line 524 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_array, and Piduino::RingBuffer< T, A >::m_tail.

◆ begin() [1/2]

◆ begin() [2/2]

template<typename T , typename A = std::allocator<T>>
const_iterator Piduino::RingBuffer< T, A >::begin ( ) const
inline
Returns

Definition at line 377 of file ringbuffer.h.

◆ capacity()

template<typename T , typename A = std::allocator<T>>
size_type Piduino::RingBuffer< T, A >::capacity ( ) const
inline
Returns

Definition at line 443 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_capacity.

Referenced by Piduino::RingBuffer< T, A >::reserve().

◆ chop()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::chop ( size_type  len)
inline
Parameters
len

Definition at line 647 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::clear(), Piduino::RingBuffer< T, A >::m_contents_size, and Piduino::RingBuffer< T, A >::pop_back().

Here is the call graph for this function:

◆ clear()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::clear ( )
inline

◆ decrement_head()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::decrement_head ( )
inlineprivate

◆ decrement_tail()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::decrement_tail ( )
inlineprivate

Definition at line 716 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_contents_size, Piduino::RingBuffer< T, A >::m_tail, and Piduino::RingBuffer< T, A >::previous_tail().

Referenced by Piduino::RingBuffer< T, A >::pop_back().

Here is the call graph for this function:

◆ empty()

template<typename T , typename A = std::allocator<T>>
bool Piduino::RingBuffer< T, A >::empty ( ) const
inline
Returns

Definition at line 434 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_contents_size.

◆ end() [1/2]

template<typename T , typename A = std::allocator<T>>
iterator Piduino::RingBuffer< T, A >::end ( )
inline
Returns

Definition at line 368 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::size().

Referenced by Piduino::end(), Piduino::end(), Piduino::operator<(), Piduino::operator==(), Piduino::RingBuffer< T, A >::rbegin(), Piduino::RingBuffer< T, A >::rbegin(), Piduino::RingBuffer< T, A >::reserve(), and Piduino::RingBuffer< T, A >::RingBuffer().

Here is the call graph for this function:

◆ end() [2/2]

template<typename T , typename A = std::allocator<T>>
const_iterator Piduino::RingBuffer< T, A >::end ( ) const
inline
Returns

Definition at line 386 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::size().

Here is the call graph for this function:

◆ front() [1/2]

template<typename T , typename A = std::allocator<T>>
reference Piduino::RingBuffer< T, A >::front ( )
inline

access the first element

Returns
a reference to the first element in the container.

Definition at line 497 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_array, and Piduino::RingBuffer< T, A >::m_head.

◆ front() [2/2]

template<typename T , typename A = std::allocator<T>>
const_reference Piduino::RingBuffer< T, A >::front ( ) const
inline

access the first element

Returns
a reference to the first element in the container.

Definition at line 515 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_array, and Piduino::RingBuffer< T, A >::m_head.

◆ get_allocator()

template<typename T , typename A = std::allocator<T>>
allocator_type Piduino::RingBuffer< T, A >::get_allocator ( ) const
inline
Returns

Definition at line 182 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_allocator.

◆ getimpl()

template<typename T , typename A = std::allocator<T>>
pointer Piduino::RingBuffer< T, A >::getimpl ( )
inline
Returns

Definition at line 684 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_array.

◆ increment_head()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::increment_head ( )
inlineprivate

◆ increment_tail()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::increment_tail ( )
inlineprivate

Definition at line 711 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_contents_size, Piduino::RingBuffer< T, A >::m_tail, and Piduino::RingBuffer< T, A >::next_tail().

Referenced by Piduino::RingBuffer< T, A >::push_back().

Here is the call graph for this function:

◆ index_to_subscript()

template<typename T , typename A = std::allocator<T>>
size_type Piduino::RingBuffer< T, A >::index_to_subscript ( size_type const  index) const
inlineprivate

Definition at line 707 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_head, and Piduino::RingBuffer< T, A >::normalise().

Referenced by Piduino::RingBuffer< T, A >::at_unchecked(), and Piduino::RingBuffer< T, A >::clear().

Here is the call graph for this function:

◆ max_size()

template<typename T , typename A = std::allocator<T>>
size_type Piduino::RingBuffer< T, A >::max_size ( ) const
inline
Returns

Definition at line 461 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::m_allocator.

◆ next_tail()

template<typename T , typename A = std::allocator<T>>
size_type Piduino::RingBuffer< T, A >::next_tail ( )
inlineprivate

◆ normalise()

template<typename T , typename A = std::allocator<T>>
size_type Piduino::RingBuffer< T, A >::normalise ( size_type const  n) const
inlineprivate

◆ operator=()

template<typename T , typename A = std::allocator<T>>
RingBuffer & Piduino::RingBuffer< T, A >::operator= ( self_type  other)
inline

copy-swap idiom using value parameter

Parameters
other

Definition at line 154 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::swap().

Here is the call graph for this function:

◆ operator[]() [1/2]

template<typename T , typename A = std::allocator<T>>
reference Piduino::RingBuffer< T, A >::operator[] ( size_type const  n)
inline
Parameters
n
Returns

Definition at line 665 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::at_unchecked().

Here is the call graph for this function:

◆ operator[]() [2/2]

template<typename T , typename A = std::allocator<T>>
const_reference Piduino::RingBuffer< T, A >::operator[] ( size_type const  n) const
inline
Parameters
n
Returns

Definition at line 534 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::at_unchecked().

Here is the call graph for this function:

◆ pop_back()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::pop_back ( )
inline

Remove the last element from the container.

Definition at line 616 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::decrement_tail(), Piduino::RingBuffer< T, A >::m_allocator, Piduino::RingBuffer< T, A >::m_array, Piduino::RingBuffer< T, A >::m_contents_size, and Piduino::RingBuffer< T, A >::previous_tail().

Referenced by Piduino::RingBuffer< T, A >::chop().

Here is the call graph for this function:

◆ pop_front()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::pop_front ( )
inline

Removes the first element of the container.

Definition at line 603 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::increment_head(), Piduino::RingBuffer< T, A >::m_allocator, Piduino::RingBuffer< T, A >::m_array, Piduino::RingBuffer< T, A >::m_contents_size, and Piduino::RingBuffer< T, A >::m_head.

Referenced by Piduino::RingBuffer< T, A >::skip().

Here is the call graph for this function:

◆ previous_head()

template<typename T , typename A = std::allocator<T>>
size_type Piduino::RingBuffer< T, A >::previous_head ( )
inlineprivate

◆ previous_tail()

template<typename T , typename A = std::allocator<T>>
size_type Piduino::RingBuffer< T, A >::previous_tail ( )
inlineprivate

◆ push_back()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::push_back ( value_type const &  item)
inline

Appends the given item to the end of the container.

Definition at line 569 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::increment_head(), Piduino::RingBuffer< T, A >::increment_tail(), Piduino::RingBuffer< T, A >::m_allocator, Piduino::RingBuffer< T, A >::m_array, Piduino::RingBuffer< T, A >::m_capacity, Piduino::RingBuffer< T, A >::m_contents_size, and Piduino::RingBuffer< T, A >::next_tail().

Referenced by Piduino::RingBuffer< T, A >::assign_into().

Here is the call graph for this function:

◆ push_front()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::push_front ( value_type const &  item)
inline

Insert a new element at the beginning of the container.

Definition at line 586 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::decrement_head(), Piduino::RingBuffer< T, A >::m_allocator, Piduino::RingBuffer< T, A >::m_array, Piduino::RingBuffer< T, A >::m_capacity, Piduino::RingBuffer< T, A >::m_contents_size, and Piduino::RingBuffer< T, A >::previous_head().

Here is the call graph for this function:

◆ rbegin() [1/2]

template<typename T , typename A = std::allocator<T>>
reverse_iterator Piduino::RingBuffer< T, A >::rbegin ( )
inline
Returns

Definition at line 395 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::end().

Here is the call graph for this function:

◆ rbegin() [2/2]

template<typename T , typename A = std::allocator<T>>
const_reverse_iterator Piduino::RingBuffer< T, A >::rbegin ( ) const
inline
Returns

Definition at line 413 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::end().

Here is the call graph for this function:

◆ rend() [1/2]

template<typename T , typename A = std::allocator<T>>
reverse_iterator Piduino::RingBuffer< T, A >::rend ( )
inline
Returns

Definition at line 404 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::begin().

Here is the call graph for this function:

◆ rend() [2/2]

template<typename T , typename A = std::allocator<T>>
const_reverse_iterator Piduino::RingBuffer< T, A >::rend ( ) const
inline
Returns

Definition at line 422 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::begin().

Here is the call graph for this function:

◆ reserve()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::reserve ( size_type const  new_size)
inline

reserve shrinks or expands the internal buffer to the size given

if the buffer shrinks, keep at most the last new_size items.

Parameters
new_size

Definition at line 475 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::assign_into(), Piduino::RingBuffer< T, A >::begin(), Piduino::RingBuffer< T, A >::capacity(), Piduino::RingBuffer< T, A >::end(), Piduino::RingBuffer< T, A >::size(), and Piduino::RingBuffer< T, A >::swap().

Here is the call graph for this function:

◆ size()

template<typename T , typename A = std::allocator<T>>
size_type Piduino::RingBuffer< T, A >::size ( ) const
inline

◆ skip()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::skip ( size_type  len)
inline
Parameters
n

Definition at line 630 of file ringbuffer.h.

References Piduino::RingBuffer< T, A >::clear(), Piduino::RingBuffer< T, A >::m_contents_size, and Piduino::RingBuffer< T, A >::pop_front().

Here is the call graph for this function:

◆ swap()

template<typename T , typename A = std::allocator<T>>
void Piduino::RingBuffer< T, A >::swap ( self_type other)
inline

Member Data Documentation

◆ m_allocator

◆ m_array

◆ m_capacity

◆ m_contents_size

◆ m_head

◆ m_tail