Stack collection.
More...
#include <base/collection/Stack.h>
Inherits Collection.
template<class TYPE>
class Stack< TYPE >
Stack collection.
A stack is a last-in-first-out data structure. This class is implemented as a linked list.
- Version
- 1.1
- Examples
- testsuite/Stack.cpp.
◆ Stack() [1/3]
Initializes an empty stack.
◆ Stack() [2/3]
template<class TYPE >
Stack< TYPE >::Stack |
( |
std::initializer_list< TYPE > |
values | ) |
|
|
inline |
Pushes all the values in left-to-right order.
◆ Stack() [3/3]
Initializes stack from other stack.
◆ copyOnWrite()
template<class TYPE >
void Stack< TYPE >::copyOnWrite |
( |
| ) |
|
|
inlineprotected |
Makes a new copy of the internal representation of the elements if shared by several stacks. This member function must be called explicitly before most modifications to the stack.
◆ getReadEnumerator()
Returns a non-modifying enumerator of the stack. The elements are enumerated from top to bottom.
◆ getSize()
template<class TYPE >
MemorySize Stack< TYPE >::getSize |
( |
| ) |
const |
|
inlinenoexcept |
Returns the number of elements on the stack.
◆ isEmpty()
template<class TYPE >
bool Stack< TYPE >::isEmpty |
( |
| ) |
const |
|
inlinenoexcept |
Returns true if the stack is empty.
◆ operator<<() [1/2]
template<class TYPE >
Stack& Stack< TYPE >::operator<< |
( |
const TYPE & |
value | ) |
|
|
inline |
◆ operator<<() [2/2]
◆ operator=()
Assignment of stack by stack.
◆ peek()
template<class TYPE >
TYPE Stack< TYPE >::peek |
( |
MemorySize |
index = 0 | ) |
const |
|
inline |
Returns the element at the specified index from the top. Raises OutOfRange if index is invalid.
- Parameters
-
index | Index of the element. Default is 0 corresponding to the top. |
◆ pop() [1/2]
template<class TYPE >
TYPE Stack< TYPE >::pop |
( |
| ) |
|
|
inline |
Pops the top element from the stack. Raises OutOfRange if the stack is empty.
- Returns
- The value of the top element.
◆ pop() [2/2]
template<class TYPE >
void Stack< TYPE >::pop |
( |
MemorySize |
count | ) |
|
|
inline |
Pops the specified number of elements from the stack. Raises OutOfRange if the stack does not contain the specified number of elements.
- Parameters
-
count | The number of elements to pop of the stack. |
◆ push()
template<class TYPE >
void Stack< TYPE >::push |
( |
const TYPE & |
value | ) |
|
|
inline |
Pushes an element onto the stack.
◆ removeAll()
template<class TYPE >
void Stack< TYPE >::removeAll |
( |
| ) |
|
|
inlinenoexcept |
Removes all the elements from the stack.
◆ operator<<()
Writes a string representation of a stack to a format output stream.
◆ elements
The elements of the stack.