modm API documentation
modm::BoundedDeque< T, N > Class Template Reference

Double ended queue. More...

#include <modm/container/deque.hpp>

Classes

class  const_iterator
 Bidirectional const iterator More...
 

Public Typedefs

using Index = std::conditional_t< (N >=255), uint_fast16_t, uint_fast8_t >
 
using Size = Index
 

Public Member Functions

bool isEmpty () const
 
bool isNotEmpty () const
 
bool isFull () const
 
bool isNotFull () const
 
Size getSize () const
 
Size getMaxSize () const
 
void clear ()
 Clear the container. More...
 
T & getFront ()
 
const T & getFront () const
 
T & get (Index n)
 Get item at specified index. More...
 
const T & get (Index n) const
 
T & operator[] (Index n)
 Get item at specified index. More...
 
const T & operator[] (Index n) const
 
T & rget (Index n)
 Get item at specified index. More...
 
const T & rget (Index n) const
 
T & getBack ()
 
const T & getBack () const
 
bool append (const T &value)
 
void appendOverwrite (const T &value)
 Append an item to the back of the deque overwriting existing items. More...
 
bool prepend (const T &value)
 
void prependOverwrite (const T &value)
 Prepend an item to the front of the deque overwriting existing items. More...
 
void removeBack ()
 
void removeFront ()
 
const_iterator begin () const
 
const_iterator end () const
 

Friends

class const_iterator
 

Detailed Description

template<typename T, std::size_t N>
class modm::BoundedDeque< T, N >

Double ended queue.

Internally organized as a ring buffer.

*           tail --\                 /-- head
*                  |                 |
*        +------+------+---- ----+------+------+
*      0 |      | data |   ...   | data |      | N-1
*        +------+------+---- ----+------+------+
*           |      |                 |      |
* prepend --/      |                 |      \-- append
*                  |                 |
*       getFront --/                 \-- getBack
* 
Template Parameters
TType of the elements
NSize of the queue

Up to a size of 254 small index variables with 8-bits are used, after this they are switched to 16-bit.

Warning
This class don't check if the container is empty before a pop-operation. You have to do this by yourself!
Author
Fabian Greif

Member Function Documentation

template<typename T , std::size_t N>
void modm::BoundedDeque< T, N >::appendOverwrite ( const T &  value)

Append an item to the back of the deque overwriting existing items.

This method, in contrast to append(), overwrites existing items in the deque if it is full. When an item is appended to the already full deque, the front item is removed to use its space for the new item, which is inserted after back.

template<typename T , std::size_t N>
void modm::BoundedDeque< T, N >::clear ( )

Clear the container.

Warning
This will discard all the items in the container
template<typename T , std::size_t N>
T& modm::BoundedDeque< T, N >::get ( Index  n)
inline

Get item at specified index.

Returns a reference to the item at index n, counting 0-indexed from Front to Back, which is the same order in that the items were appended and the iterator addresses them.

Warning
Please make sure n is a valid index: 0 <= n < size. Other indexes will cause undefined behaviour.
template<typename T , std::size_t N>
T& modm::BoundedDeque< T, N >::operator[] ( Index  n)
inline

Get item at specified index.

Returns a reference to the item at index n, counting 0-indexed from Front to Back.

Warning
Please make sure n is a valid index: 0 <= n < size. Other indexes will cause undefined behaviour.
template<typename T , std::size_t N>
void modm::BoundedDeque< T, N >::prependOverwrite ( const T &  value)

Prepend an item to the front of the deque overwriting existing items.

This method, in contrast to prepend(), overwrites existing items in the deque if it is full. When an item is prepended to the already full deque, the back item is removed to use its space for the new item, which is inserted at front.

template<typename T , std::size_t N>
T& modm::BoundedDeque< T, N >::rget ( Index  n)
inline

Get item at specified index.

Returns a reference to the item at index n. The items are indexed in reverse (Back to Front), which is their order when they have been prepended.

Warning
Please make sure n is a valid index: 0 <= n < size. Other indexes will cause undefined behaviour.

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