FifoQueueBase
FifoQueueBase is a class template
defined in Fw/DataStructures.
It represents an abstract base class for a FIFO queue.
1. Template Parameters
FifoQueueBase has the following template parameters.
| Kind | Name | Purpose |
|---|---|---|
typename |
T |
The type of an item on the queue |
2. Base Class
FifoQueueBase<T> is publicly derived from SizedContainer.
3. Private Constructors
3.1. Copy Constructor
Defined as = delete.
4. Protected Constructors and Destructors
4.1. Zero-Argument Constructor
Use default initialization of members.
4.2. Destructor
Defined as = default.
5. Private Member Functions
5.1. operator=
Defined as = delete.
6. Public Member Functions
6.1. at
Return the item at the specified index. Index 0 is the leftmost (earliest) element in the queue. Increasing indices go from left to right. Fails an assertion if the index is out of range.
Example:
void f(FifoQueueBase<U32>& queue) {
queue.clear();
const auto status = queue.enqueue(3);
ASSERT_EQ(status, Success::SUCCESS);
const auto status = queue.enqueue(4);
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(queue.at(0), 3);
ASSERT_EQ(queue.at(1), 4);
ASSERT_DEATH(queue.at(2), "Assert");
}
6.2. copyDataFrom
-
If
&queue != thisthen-
Call
clear(). -
Let
sizebe the minimum ofqueue.getSize()andgetCapacity(). -
For
iin [0,size)-
Set
e = at(i). -
Set
status = enqueue(e). -
Assert
status == Success::SUCCESS.
-
-
Example:
void f(FifoQueueBase<U32>& q1, FifoQueueBase<U32>& q2) {
q1.clear();
// Enqueue an item
U32 value = 42;
(void) q1.enqueue(value);
q2.clear();
ASSERT_EQ(q2.getSize(), 0);
q2.copyDataFrom(q1);
ASSERT_EQ(q2.getSize(), 1);
}
6.3. dequeue
-
Set
status = Success::FAILURE. -
If
size > 0-
Remove the leftmost item from the queue and store it into
e. -
Set
status = Success::SUCCESS.
-
-
Return
status.
Example:
void f(FifoQueueBase<U32>& queue) {
queue.clear();
U32 val = 0;
auto status = queue.dequeue(val);
ASSERT_EQ(status, Success::FAILURE);
status = queue.enqueue(3);
ASSERT_EQ(status, Success::SUCCESS);
status = queue.dequeue(val);
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(val, 3);
}
6.4. enqueue
-
Set
status = Success::FAILURE. -
If there is room on the queue for a new item, then
-
Add
eto the right of the queue. -
Set
status = Success::SUCCESS.
-
-
Return
status.
Example:
void f(FifoQueueBase<U32>& queue) {
queue.clear();
const auto status = queue.enqueue(3);
ASSERT_EQ(status, Success::SUCCESS);
}
6.5. peek
-
Set
status = Success::FAILURE. -
If
index < getSize()-
Set
e = at(index). -
Set
status = Success::SUCCESS.
-
-
Return
status.
Example:
void f(FifoQueueBase<U32>& queue) {
queue.clear();
U32 value = 0;
auto status = queue.peek(value);
ASSERT_EQ(status, Success::FAILURE);
status = queue.enqueue(3);
status = queue.peek(value);
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(value, 3);
status = queue.peek(value, 1);
ASSERT_EQ(status, Success::FAILURE);
status = queue.enqueue(4);
status = queue.peek(value, 1);
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(value, 4);
}