Stack
Stack
is a final
class template
defined in Fw/DataStructures
.
It represents a stack with internal storage.
1. Template Parameters
Stack
has the following template parameters.
Kind | Name | Purpose |
---|---|---|
typename |
T |
The type of a stack item |
FwSizeType |
C |
The stack capacity in items |
Stack
statically asserts the following:
T
is default constructible.C > 0
.
2. Base Class
Stack<T>
is publicly derived from
StackBase<T>
.
3. Private Member Variables
Stack
has the following private member variables.
Name | Type | Purpose | Default Value |
---|---|---|---|
m_extStack |
ExternalStack<T> |
The external stack implementation | C++ default initialization |
m_items |
T[C] |
The array providing the backing memory for m_extStack |
C++ default initialization |
classDiagram
Stack *-- ExternalStack
4. Public Constructors and Destructors
4.1. Zero-Argument Constructor
Initialize m_extStack
with ExternalStack<T>(m_items, C)
.
Example:
4.2. Copy Constructor
Set *this = stack
.
Example:
Stack<U32, 10> q1;
auto status = q1.push(3);
ASSERT_EQ(status, Success::SUCCESS);
Stack<U32, 10> q2(q1);
ASSERT_EQ(q2.size(), 1);
U32 value = 0;
status = q2.pop(value);
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(value, 3);
4.3. Destructor
Defined as = default
.
5. Public Member Functions
5.1. operator=
Call m_extStack.copyDataFrom(stack)
.
Example:
Stack<U32, 10> q1;
auto status = q1.push(3);
ASSERT_EQ(status, Success::SUCCESS);
Stack<U32, 10> q2;
ASSERT_EQ(q2.size(), 0);
q2 = q1;
ASSERT_EQ(q2.size(), 1);
U32 value = 0;
status = q2.pop(value);
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(value, 3);
5.2. clear
Call m_extStack.clear()
.
5.3. push
Return m_extStack.push(e)
.
5.4. at
Return m_extStack.at(index)
.
5.5. pop
Return m_extStack.pop(e)
.
5.6. getSize
Return m_extStack.getSize()
.
5.7. getCapacity
Return m_extStack.getCapacity()
.
6. Public Static Functions
6.1. getStaticCapacity
Return the static capacity C
.
Example: