mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK > Class Template Reference

A basic ring buffer with iterator. More...

#include <mn_ringbuffer.hpp>

+ Collaboration diagram for mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >:

Public Types

using value_type = T
 
using pointer = T *
 
using const_pointer = const T *
 
using reference = T &
 
using const_reference = const T &
 
using size_type = size_t
 
using difference_type = ptrdiff_t
 
using lock_type = TLOCK
 
using lock_guard = basic_autolock< TLOCK >
 
using self_type = basic_ring_buffer< T, TCAPACITY, TLOCK >
 
using iterator = basic_ring_buffer_iterator< self_type, value_type >
 
using const_iterator = basic_ring_buffer_iterator< self_type, const value_type >
 

Public Member Functions

 basic_ring_buffer ()
 
void clear ()
 Clear the ringbuffer and set read/write positoin to 0. More...
 
void reset ()
 Set read/write positoin to 0, for clear use function clear() More...
 
void push_back (const value_type &value)
 push a value to the end of the buffer More...
 
reference pop_front ()
 pop (read) the element from the front and remove it from buffer More...
 
const_reference pop_front () const
 pop (read) the element from the front and remove it from buffer More...
 
iterator begin ()
 
iterator end ()
 
const_iterator cbegin ()
 
const_iterator cend ()
 
reference rfront ()
 
const_reference crfront () const
 
const_reference crback () const
 
reference rback ()
 
size_type size () const
 Get the size of the ringbuffer. More...
 
size_type capacity () const
 Get the number of stored elements in the buffer. More...
 
bool empty () const
 Is the buffer empty? More...
 
bool full () const
 Is the buffer full? More...
 
size_type max () const
 
size_t get_head ()
 
size_t get_tail ()
 

Private Member Functions

void inc_tail ()
 
void inc_head ()
 

Private Attributes

m_Array [TCAPACITY]
 
size_t m_Head
 
size_t m_Tail
 
size_t m_ContentsSize
 
lock_type m_lockObject
 

Detailed Description

template<class T, size_t TCAPACITY = 100, typename TLOCK = LockType_t>
class mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >

A basic ring buffer with iterator.

Note
A ring buffer is a FIFO (first-in, first-out) container which acts much like a queue. The difference is that a ring buffer is implemented via chasing pointers around a container and moving the read and write positions forward (and possibly wrapping around) as the container is read and written via pop_front and push_back.
Template Parameters
TType of element. Required to be a complete type.
TCAPACITYThe maximal capacity of elements,
TLOCKThe lock object for task saftly

Member Typedef Documentation

◆ const_iterator

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::const_iterator = basic_ring_buffer_iterator<self_type, const value_type>

◆ const_pointer

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::const_pointer = const T*

◆ const_reference

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::const_reference = const T&

◆ difference_type

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::difference_type = ptrdiff_t

◆ iterator

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::iterator = basic_ring_buffer_iterator<self_type, value_type>

◆ lock_guard

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::lock_guard = basic_autolock<TLOCK>

◆ lock_type

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::lock_type = TLOCK

◆ pointer

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::pointer = T*

◆ reference

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::reference = T&

◆ self_type

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::self_type = basic_ring_buffer<T, TCAPACITY, TLOCK>

◆ size_type

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::size_type = size_t

◆ value_type

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
using mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::value_type = T

Constructor & Destructor Documentation

◆ basic_ring_buffer()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::basic_ring_buffer ( )
inline

Member Function Documentation

◆ begin()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
iterator mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::begin ( )
inline

◆ capacity()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
size_type mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::capacity ( ) const
inline

Get the number of stored elements in the buffer.

Returns
The number of stored elements in the buffer

◆ cbegin()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
const_iterator mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::cbegin ( )
inline

◆ cend()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
const_iterator mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::cend ( )
inline

◆ clear()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
void mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::clear ( )
inline

Clear the ringbuffer and set read/write positoin to 0.

◆ crback()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
const_reference mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::crback ( ) const
inline

◆ crfront()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
const_reference mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::crfront ( ) const
inline

◆ empty()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
bool mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::empty ( void  ) const
inline

Is the buffer empty?

Returns
true The buffer is empty
false The buffer is not empty

◆ end()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
iterator mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::end ( )
inline

◆ full()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
bool mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::full ( ) const
inline

Is the buffer full?

Returns
true The buffer is full
false The buffer is not full

◆ get_head()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
size_t mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::get_head ( )
inline

Get the write position (head)

Returns
The write position (head)

◆ get_tail()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
size_t mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::get_tail ( )
inline

Get the read position index (head)

Returns
The read position (head)

◆ inc_head()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
void mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::inc_head ( )
inlineprivate

◆ inc_tail()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
void mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::inc_tail ( )
inlineprivate

◆ max()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
size_type mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::max ( ) const
inline

◆ pop_front() [1/2]

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
reference mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::pop_front ( )
inline

pop (read) the element from the front and remove it from buffer

Returns
The poped value

◆ pop_front() [2/2]

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
const_reference mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::pop_front ( ) const
inline

pop (read) the element from the front and remove it from buffer

Returns
The poped value

◆ push_back()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
void mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::push_back ( const value_type value)
inline

push a value to the end of the buffer

Parameters
valueThe value to add

◆ rback()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
reference mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::rback ( )
inline

◆ reset()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
void mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::reset ( )
inline

Set read/write positoin to 0, for clear use function clear()

◆ rfront()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
reference mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::rfront ( )
inline

◆ size()

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
size_type mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::size ( ) const
inline

Get the size of the ringbuffer.

Returns
The size of the ringbuffer

Member Data Documentation

◆ m_Array

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
T mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::m_Array[TCAPACITY]
private

◆ m_ContentsSize

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
size_t mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::m_ContentsSize
private

◆ m_Head

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
size_t mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::m_Head
private

◆ m_lockObject

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
lock_type mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::m_lockObject
private

◆ m_Tail

template<class T , size_t TCAPACITY = 100, typename TLOCK = LockType_t>
size_t mn::container::basic_ring_buffer< T, TCAPACITY, TLOCK >::m_Tail
private

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