Base Framework
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Related Functions | List of all members
Stack< TYPE > Class Template Reference

Stack collection. More...

#include <base/collection/Stack.h>

Inherits Collection.

Classes

class  StackImpl
 
class  StackReadEnumerator
 

Public Types

typedef StackReadEnumerator< ReadEnumeratorTraits< TYPE > > ReadEnumerator
 

Public Member Functions

 Stack () noexcept
 
 Stack (std::initializer_list< TYPE > values)
 
 Stack (const Stack &copy) noexcept
 
Stackoperator= (const Stack &assign) noexcept
 
MemorySize getSize () const noexcept
 
bool isEmpty () const noexcept
 
TYPE peek (MemorySize index=0) const
 
void push (const TYPE &value)
 
TYPE pop ()
 
void pop (MemorySize count)
 
ReadEnumerator getReadEnumerator () const noexcept
 
Iterator begin () noexcept
 
Iterator end () noexcept
 
ReadIterator cbegin () const noexcept
 
ReadIterator cend () const noexcept
 
void removeAll () noexcept
 
Stackoperator<< (const TYPE &value)
 
Stackoperator<< (TYPE &&value)
 

Protected Types

typedef DoubleLinkedNode< TYPE > StackNode
 
typedef DoubleLinkedNodeIterator< TYPE > Iterator
 
typedef DoubleLinkedNodeReadIterator< TYPE > ReadIterator
 

Protected Member Functions

void copyOnWrite ()
 

Protected Attributes

Reference< StackImplelements
 

Related Functions

(Note that these are not member functions.)

template<class TYPE >
FormatOutputStreamoperator<< (FormatOutputStream &stream, const Stack< TYPE > &value)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Stack() [1/3]

template<class TYPE >
Stack< TYPE >::Stack ( )
inlinenoexcept

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]

template<class TYPE >
Stack< TYPE >::Stack ( const Stack< TYPE > &  copy)
inlinenoexcept

Initializes stack from other stack.

Member Function Documentation

◆ 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()

template<class TYPE >
ReadEnumerator Stack< TYPE >::getReadEnumerator ( ) const
inlinenoexcept

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

Pushes value.

◆ operator<<() [2/2]

template<class TYPE >
Stack& Stack< TYPE >::operator<< ( TYPE &&  value)
inline

Pushes value.

◆ operator=()

template<class TYPE >
Stack& Stack< TYPE >::operator= ( const Stack< TYPE > &  assign)
inlinenoexcept

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
indexIndex 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
countThe 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.

Friends And Related Function Documentation

◆ operator<<()

template<class TYPE >
FormatOutputStream & operator<< ( FormatOutputStream stream,
const Stack< TYPE > &  value 
)
related

Writes a string representation of a stack to a format output stream.

Member Data Documentation

◆ elements

template<class TYPE >
Reference<StackImpl> Stack< TYPE >::elements
protected

The elements of the stack.