PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Public Member Functions | List of all members
PropWare::Queue< T > Class Template Reference

A basic first-in, first-out queue implementation. The queue will overwrite itself when the maximum size is reached. More...

#include <PropWare/utility/collection/queue.h>

Public Member Functions

template<size_t N>
 Queue (T(&array)[N], const int lockNumber=locknew())
 Construct a queue using the given statically-allocated array. More...
 
 Queue (T *array, const size_t length, const int lockNumber)
 Construct a queue using the given dynamically allocated array (i.e., with new or malloc) More...
 
size_t size () const
 Obtain the number of elements in the queue. More...
 
bool is_empty () const
 Determine if any elements exist. More...
 
bool is_full () const
 Determine if inserting another element would overwrite data. More...
 
void clear ()
 Remove all data from the queue.
 
virtual Queueenqueue (const T &value)
 Insert an element to the buffer. More...
 
Queueinsert (const T &value)
 
virtual T dequeue ()
 Return and remove the oldest value in the buffer. More...
 
peek () const
 Return the oldest value in the buffer without removing it from the buffer. More...
 
bool check (const T &value) const
 Determine if a value is valid. More...
 

Detailed Description

template<typename T>
class PropWare::Queue< T >

A basic first-in, first-out queue implementation. The queue will overwrite itself when the maximum size is reached.

Examples
I2CSlave_Demo.cpp, and Queue_Demo.cpp.

Definition at line 44 of file queue.h.

Constructor & Destructor Documentation

◆ Queue() [1/2]

template<typename T >
template<size_t N>
PropWare::Queue< T >::Queue ( T(&)  array[N],
const int  lockNumber = locknew() 
)

Construct a queue using the given statically-allocated array.

Parameters
[in]arrayStatically allocated instance of an array, NOT a pointer

Definition at line 52 of file queue.h.

◆ Queue() [2/2]

template<typename T >
PropWare::Queue< T >::Queue ( T *  array,
const size_t  length,
const int  lockNumber 
)

Construct a queue using the given dynamically allocated array (i.e., with new or malloc)

This constructor is not recommended unless dynamic allocation is used. When using statically allocated arrays, use the single-parameter constructor

Parameters
[in]arrayAddress where the array begins
[in]lengthNumber of elements allocated for the array

Definition at line 71 of file queue.h.

Member Function Documentation

◆ check()

template<typename T >
bool PropWare::Queue< T >::check ( const T &  value) const

Determine if a value is valid.

If the queue is read (deque or peek) when the size is 0 then a value at address 0 is returned. A better implementation would throw an exception when this occurs, but that isn't feasible on the Propeller. Use this method if you want to ensure values are valid prior to using them

Parameters
[in]valueA value returned by PropWare::Queue::peek() or PropWare::Queue::dequeue()
Returns
Whether or not the value is valid

Definition at line 234 of file queue.h.

◆ dequeue()

template<typename T >
virtual T PropWare::Queue< T >::dequeue ( )
virtual

Return and remove the oldest value in the buffer.

Precondition
Buffer must not be empty - no checks are performed to ensure the buffer contains data
Returns
Oldest value in the buffer

Definition at line 181 of file queue.h.

+ Here is the caller graph for this function:

◆ enqueue()

template<typename T >
virtual Queue& PropWare::Queue< T >::enqueue ( const T &  value)
virtual

Insert an element to the buffer.

Parameters
[in]valueValue to be inserted at the end of the buffer
Postcondition
If the buffer is already full, the oldest value will be overwritten with the value parameter
Returns
In order to allow chained calls to PropWare::Queue::enqueue, the Queue instance is returned

Definition at line 129 of file queue.h.

+ Here is the caller graph for this function:

◆ insert()

template<typename T >
Queue& PropWare::Queue< T >::insert ( const T &  value)
See also
PropWare::CircularQueue::enqueue(const T &value)

Definition at line 170 of file queue.h.

◆ is_empty()

template<typename T >
bool PropWare::Queue< T >::is_empty ( ) const

Determine if any elements exist.

Returns
True if there is one or more elements, false otherwise

Definition at line 100 of file queue.h.

+ Here is the caller graph for this function:

◆ is_full()

template<typename T >
bool PropWare::Queue< T >::is_full ( ) const

Determine if inserting another element would overwrite data.

Returns
True if the queue can not fit any more data without loosing old data, false otherwise

Definition at line 109 of file queue.h.

◆ peek()

template<typename T >
T PropWare::Queue< T >::peek ( ) const

Return the oldest value in the buffer without removing it from the buffer.

Precondition
Buffer must not be empty - no checks are performed to ensure the buffer contains data
Returns
Oldest value in the buffer

Definition at line 219 of file queue.h.

◆ size()

template<typename T >
size_t PropWare::Queue< T >::size ( ) const

Obtain the number of elements in the queue.

Returns
Number of elements in the queue

Definition at line 91 of file queue.h.

+ Here is the caller graph for this function:

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