Fw/DataStructures/docs/Stack.md
Stack is a final class template
defined in Fw/DataStructures.
It represents a stack with internal storage.
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.Stack<T> is publicly derived from
StackBase<T>.
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
Stack()
Initialize m_extStack with ExternalStack<T>(m_items, C).
Example:
Stack<U32, 10> stack;
Stack(const Stack<T, S>& stack)
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);
~Stack() override
Defined as = default.
Stack<T>& operator=(const Stack<T>& stack)
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);
void clear() override
Call m_extStack.clear().
Success push(const T& e) override
Return m_extStack.push(e).
const T& at(FwSizeType index) const override
Return m_extStack.at(index).
Success pop(T& e) override
Return m_extStack.pop(e).
FwSizeType getSize() const override
Return m_extStack.getSize().
FwSizeType getCapacity() const override
Return m_extStack.getCapacity().
static constexpr FwSizeType getStaticCapacity()
Return the static capacity C.
Example:
const auto capacity = Stack<U32, 3>::getStaticCapacity();
ASSERT_EQ(capacity, 3);