Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArRingQueue< T > Class Template Reference

#include <ArRingQueue.h>

List of all members.

Public Member Functions

void advance_back ()
void advance_front ()
 ArRingQueue (int capacity, T init_value)
std::list< T >::iterator back ()
size_t capacity ()
bool empty ()
std::list< T >::iterator front ()
bool full ()
std::list< T >::iterator nil ()
pop ()
pop_front ()
void print ()
void push (const T &item)
void push_back (const T &item)
void push_without_expanding (const T &item)
void reset ()
size_t size ()

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 >

This is 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.

Definition at line 52 of file ArRingQueue.h.


Constructor & Destructor Documentation

template<class T>
ArRingQueue< T >::ArRingQueue int  capacity,
init_value
[inline]
 

Parameters:
capacity Initial capacity of the ring queue.
init_value Initial value for new, unused items in the queue.

Definition at line 57 of file ArRingQueue.h.


Member Function Documentation

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.

Definition at line 114 of file ArRingQueue.h.

Referenced by ArRingQueue< T >::push().

template<class T>
void ArRingQueue< T >::advance_front  )  [inline]
 

Advance the front: an 'empty' pop. 'Used' size will be decremented.

Definition at line 100 of file ArRingQueue.h.

Referenced by ArRingQueue< T >::pop(), and ArRingQueue< T >::push_without_expanding().

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.

Definition at line 90 of file ArRingQueue.h.

References ArRingQueue< T >::nil().

template<class T>
size_t ArRingQueue< T >::capacity  )  [inline]
 

Get the current capacity of the queue.

Definition at line 181 of file ArRingQueue.h.

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

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

Definition at line 186 of file ArRingQueue.h.

Referenced by ArRingQueue< T >::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().

Definition at line 73 of file ArRingQueue.h.

References ArRingQueue< T >::empty(), and ArRingQueue< T >::nil().

Referenced by ArRingQueue< T >::pop().

template<class T>
bool ArRingQueue< T >::full  )  [inline]
 

Return true if the queue is full, false otherwise.

Definition at line 199 of file ArRingQueue.h.

Referenced by ArRingQueue< T >::push(), and ArRingQueue< T >::push_without_expanding().

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.

Definition at line 205 of file ArRingQueue.h.

Referenced by ArRingQueue< T >::back(), ArRingQueue< T >::front(), and ArRingQueue< T >::pop().

template<class T>
T ArRingQueue< T >::pop  )  [inline]
 

Remove the next item from the queue and return it. If the queue is empty, nil() will be returned.

Definition at line 153 of file ArRingQueue.h.

References ArRingQueue< T >::advance_front(), ArRingQueue< T >::front(), and ArRingQueue< T >::nil().

Referenced by ArRingQueue< T >::pop_front().

template<class T>
T ArRingQueue< T >::pop_front  )  [inline]
 

Same as pop()

Definition at line 161 of file ArRingQueue.h.

References ArRingQueue< T >::pop().

template<class T>
void ArRingQueue< T >::print  )  [inline]
 

Print the current contents of the queue.

Definition at line 164 of file ArRingQueue.h.

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

Add an item to the end of the ring queue. If the queue is full, the capacity of the queue will be expanded and the item will be inserted.

Definition at line 130 of file ArRingQueue.h.

References ArRingQueue< T >::advance_back(), and ArRingQueue< T >::full().

Referenced by ArRingQueue< T >::push_back(), and ArRingQueue< T >::push_without_expanding().

template<class T>
void ArRingQueue< T >::push_back const T &  item  )  [inline]
 

Same as push()

Definition at line 140 of file ArRingQueue.h.

References ArRingQueue< T >::push().

template<class T>
void ArRingQueue< T >::push_without_expanding const T &  item  )  [inline]
 

Push a new item, but preserve capacity: instead of expanding the queue for new data, re-use the front (oldest item). If the queue is full, then the front (oldest item) becomes the back.

Definition at line 145 of file ArRingQueue.h.

References ArRingQueue< T >::advance_front(), ArRingQueue< T >::full(), and ArRingQueue< T >::push().

template<class T>
void ArRingQueue< T >::reset void   )  [inline]
 

Clear the queue, resetting to initial empty state (but preserving current capacity)

Definition at line 192 of file ArRingQueue.h.

template<class T>
size_t ArRingQueue< T >::size  )  [inline]
 

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

Definition at line 176 of file ArRingQueue.h.


The documentation for this class was generated from the following file:
Generated on Wed Oct 19 12:56:53 2005 for Aria by  doxygen 1.4.0