Aria  2.8.0
ArRingQueue< T > Class Template Reference

An expanding ring queue. More...

#include <ArRingQueue.h>

Public Member Functions

void advance_back ()
 Advance the back (an 'empty' push), if the queue is not full. More...
 
void advance_front ()
 Advance (pop) the front of the queue. More...
 
 ArRingQueue (int capacity, T init_value)
 
std::list< T >::iterator back ()
 Get an iterator for the back of the queue (the item that would be replaced by push()). More...
 
size_t capacity ()
 Get the current capacity of the queue. More...
 
bool empty ()
 Return true if the queue is empty (has no 'used' items), false otherwise. More...
 
std::list< T >::iterator front ()
 Get an iterator for the front item of the ring queue (the item that would be returned by pop()). More...
 
bool full ()
 Return true if the queue is full, false otherwise. More...
 
std::list< T >::iterator nil ()
 Return an iterator representing an invalid item. More...
 
void pop_front ()
 Same as advance_front()
 
void print ()
 Print the current contents of the queue. More...
 
void push (const T &item)
 Add an item to the back of the ring queue. More...
 
void push_back (const T &item)
 Same as push()
 
void push_without_expanding (const T &item)
 Push a new item, but preserve capacity: instead of expanding the queue if full, then the oldest item is replaced and the front is advanced.
 
void reset ()
 Logically clear the queue, resetting to initial empty state, but preserving current capacity, and leaving all contents as they are; the contents are not destroyed, but will be when replaced by new data later. More...
 
size_t size ()
 Get the number of items currently 'used' in the queue. More...
 

Protected Attributes

std::list< T >::iterator back_it
 
size_t curSize
 
std::list< T >::iterator front_it
 
initval
 
std::list< T > ring
 

Detailed Description

template<class T>
class ArRingQueue< T >

An expanding ring queue.

It is used to keep a queue with a minimum of allocation and freeing of heap memory. The ring queue is implemented using std::list. The queue starts with an initial capacity, but those initial items are considered 'unused'. Items are "pushed" into the queue at the "back", and "popped" from the queue at the "front". pop() and advance_front() will move the front of the queue to the next item, creating a new 'unused slot' for future use; advance_back() changes the next item in the back to a 'used' slot. push() either uses the next 'unused' slot, or inserts a new item into the std::list. When the capacity of the queue is filled, all operations will fail except push(). Use push() to insert new items in the queue and increase its capacity.

Constructor & Destructor Documentation

◆ ArRingQueue()

template<class T >
ArRingQueue< T >::ArRingQueue ( int  capacity,
init_value 
)
inline
Parameters
capacityInitial capacity of the ring queue.
init_valueInitial value for new, unused items in the queue.

Member Function Documentation

◆ advance_back()

template<class T >
void ArRingQueue< T >::advance_back ( )
inline

Advance the back (an 'empty' push), if the queue is not full.

'Used' size will be incremented.

◆ advance_front()

template<class T >
void ArRingQueue< T >::advance_front ( )
inline

Advance (pop) the front of the queue.

'Used' size will be decremented.

◆ back()

template<class T >
std::list<T>::iterator ArRingQueue< T >::back ( )
inline

Get an iterator for the back of the queue (the item that would be replaced by push()).

This is not the last item in the queue, rather it is the next, unused, "slot". If the queue is full, an iterator equivalent to that returned by nil() is returned.

To add an item to the queue without pushing a copy with push(), first check if the queue is full (in which case you must push() your item). Then use this function to write the data into the next unused 'slot'. Then call advance_back() to advance the back of the queue to your new item.

◆ capacity()

template<class T >
size_t ArRingQueue< T >::capacity ( )
inline

Get the current capacity of the queue.

◆ empty()

template<class T >
bool ArRingQueue< T >::empty ( void  )
inline

Return true if the queue is empty (has no 'used' items), false otherwise.

◆ front()

template<class T >
std::list<T>::iterator ArRingQueue< T >::front ( )
inline

Get an iterator for the front item of the ring queue (the item that would be returned by pop()).

If the queue is currently empty, nil() will be returned.

To remove an item from the queue without making a copy with pop(), first check if the queue is empty(). Then use this function to get the data. Then call advance_front().

◆ full()

template<class T >
bool ArRingQueue< T >::full ( )
inline

Return true if the queue is full, false otherwise.

◆ nil()

template<class T >
std::list<T>::iterator ArRingQueue< T >::nil ( )
inline

Return an iterator representing an invalid item.

Compare to the return values of front(), back(), pop(), etc.

◆ print()

template<class T >
void ArRingQueue< T >::print ( )
inline

Print the current contents of the queue.

Python Wrapper Library: use printQueue() instead of print() (which is a reserved word in Python)

◆ push()

template<class T >
void ArRingQueue< T >::push ( const T &  item)
inline

Add an item to the back of the ring queue.

If the queue is full, the capacity of the queue will be expanded and the item will be inserted.

◆ reset()

template<class T >
void ArRingQueue< T >::reset ( void  )
inline

Logically clear the queue, resetting to initial empty state, but preserving current capacity, and leaving all contents as they are; the contents are not destroyed, but will be when replaced by new data later.

◆ size()

template<class T >
size_t ArRingQueue< T >::size ( )
inline

Get the number of items currently 'used' in the queue.


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