A basic first-in, first-out queue implementation. The queue will overwrite itself when the maximum size is reached.
More...
#include <queue.h>
|
template<size_t N> |
| Queue (T(&array)[N]) |
| Construct a queue using the given statically-allocated array. More...
|
|
| Queue (T *array, const size_t length) |
| 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.
|
|
Queue & | enqueue (const T &value) |
| Insert an element to the buffer. More...
|
|
Queue & | insert (const T &value) |
|
T | dequeue () |
| Return and remove the oldest value in the buffer. More...
|
|
T | 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...
|
|
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:
- Queue_Demo.cpp.
Definition at line 37 of file queue.h.
template<typename T>
template<size_t N>
Construct a queue using the given statically-allocated array.
- Parameters
-
[in] | array | Statically allocated instance of an array, NOT a pointer |
Definition at line 45 of file queue.h.
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] | *array | Address where the array begins |
[in] | length | Number of elements allocated for the array |
Definition at line 58 of file queue.h.
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
-
- Returns
- Whether or not the value is valid
Definition at line 191 of file queue.h.
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 148 of file queue.h.
Insert an element to the buffer.
- Parameters
-
[in] | &value | Value 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 105 of file queue.h.
- See also
- PropWare::CircularQueue::enqueue(const T &value)
Definition at line 137 of file queue.h.
Determine if any elements exist.
- Returns
- True if there is one or more elements, false otherwise
Definition at line 76 of file queue.h.
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 85 of file queue.h.
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 176 of file queue.h.
Obtain the number of elements in the queue.
- Returns
- Number of elements in the queue
Definition at line 67 of file queue.h.
The documentation for this class was generated from the following file: