muwerk ustd Library
A low-resource, minimal implementation of Arrays, Maps and Queues for low-resource avrs.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ustd::queue< T > Class Template Reference

Lightweight c++11 ring buffer queue implementation. More...

#include <ustd_queue.h>

Public Member Functions

 queue (unsigned int maxQueueSize)
 
 ~queue ()
 
queueIterator< T > begin ()
 
queueIterator< T > end ()
 
queueIterator< const T > begin () const
 
queueIterator< const T > end () const
 
bool push (T ent)
 
pop ()
 
void setInvalidValue (T &entryInvalidValue)
 
bool isEmpty ()
 
unsigned int length ()
 
unsigned int peak ()
 

Detailed Description

template<class T>
class ustd::queue< T >

Lightweight c++11 ring buffer queue implementation.

ustd_queue.h is a minimal, yet highly portable ring buffer queue implementation that runs well on architectures with very limited resources such as attiny 8kb avr.

Make sure to provide the required platform define before including ustd headers.

An example:

#define __ATTINY__ 1 // Appropriate platform define required
#include <ustd_queue.h>
int wi;
wi=1;
que.push(wi);
int wo;
wo=que.pop();
printf("%d\n",wo);
Lightweight c++11 ring buffer queue implementation.
Definition: ustd_queue.h:84
T pop()
Definition: ustd_queue.h:181
bool push(T ent)
Definition: ustd_queue.h:164

Queue inspection with iterators

queue<int> que = queue<int>(16);

que.push(12); que.push(13);

Iterate through queue content (does not modify content) for (auto i : que) { printf("%d\n", i); }

New pop() the values: int w0,w1; w0=que.pop(); w1=que.pop(); Queue is now empty.

printf("%d %d, len=%d\n",w0,w1,que.length());

Constructor & Destructor Documentation

◆ queue()

template<class T >
ustd::queue< T >::queue ( unsigned int  maxQueueSize)
inline

Constructs a queue object

Parameters
maxQueueSizeThe maximum number of entries, the queue can hold.

◆ ~queue()

template<class T >
ustd::queue< T >::~queue ( )
inline

Deallocate the queue structure.

Member Function Documentation

◆ begin() [1/2]

template<class T >
queueIterator< T > ustd::queue< T >::begin ( )
inline

Iterator support: begin()

◆ begin() [2/2]

template<class T >
queueIterator< const T > ustd::queue< T >::begin ( ) const
inline

Iterator support: begin()

◆ end() [1/2]

template<class T >
queueIterator< T > ustd::queue< T >::end ( )
inline

Iterator support: end()

◆ end() [2/2]

template<class T >
queueIterator< const T > ustd::queue< T >::end ( ) const
inline

Iterator support: end()

◆ isEmpty()

template<class T >
bool ustd::queue< T >::isEmpty ( )
inline

Check, if queue is empty.

Returns
true: queue empty, false: not empty.

◆ length()

template<class T >
unsigned int ustd::queue< T >::length ( )
inline

Check number of queue entries.

Returns
number of entries in the queue.

◆ peak()

template<class T >
unsigned int ustd::queue< T >::peak ( )
inline

Check the maxiumum number of entries that have been in the queue.

Returns
max number of queue entries.

◆ pop()

template<class T >
T ustd::queue< T >::pop ( )
inline

Pop the oldest entry from the queue.

Returns
badEntry if queue is empty, or T element otherwise.

◆ push()

template<class T >
bool ustd::queue< T >::push ( ent)
inline

Push a new entry into the queue.

Parameters
entT element
Returns
true on success, false if queue is full.

◆ setInvalidValue()

template<class T >
void ustd::queue< T >::setInvalidValue ( T &  entryInvalidValue)
inline

Set the value that's given back, if read from an empty queue is requested. By default, an entry all set to zero is given back. Using this function, the value of an invalid read can be configured.

Parameters
entryInvalidValueThe value that is given back in case an invalid operation (e.g. read out of bounds) is tried.

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