ROSE 0.11.145.192
Public Types | Public Member Functions | List of all members
Sawyer::Container::Stack< T > Class Template Reference

Description

template<typename T>
class Sawyer::Container::Stack< T >

Stack-based container.

The stack stores values in a last-in-first-out order. New items are pushed onto the top of the stack and existing items are popped from the top of the stack.

Definition at line 22 of file Stack.h.

#include <Sawyer/Stack.h>

Inheritance diagram for Sawyer::Container::Stack< T >:
Inheritance graph
[legend]

Public Types

typedef T Value
 

Public Member Functions

 Stack ()
 Construct an empty stack.
 
template<class Iterator >
 Stack (const boost::iterator_range< Iterator > &range)
 Construct a stack from an iterator range.
 
size_t size () const
 Returns the number of items on the stack.
 
bool isEmpty () const
 Determines if the stack is empty.
 
Stackpush (const Value &value)
 Push new item onto stack.
 
Value pop ()
 Pop existing item from stack.
 
Value & top ()
 Returns the top item.
 
const Value & top () const
 Returns the top item.
 
Value & get (size_t idx)
 Access an item not at the top of the stack.
 
const Value & get (size_t idx) const
 Access an item not at the top of the stack.
 
Value & operator[] (size_t idx)
 Access an item not at the top of the stack.
 
const Value & operator[] (size_t idx) const
 Access an item not at the top of the stack.
 

Member Typedef Documentation

◆ Value

template<typename T >
typedef T Sawyer::Container::Stack< T >::Value

Definition at line 24 of file Stack.h.

Constructor & Destructor Documentation

◆ Stack() [1/2]

template<typename T >
Sawyer::Container::Stack< T >::Stack ( )
inline

Construct an empty stack.

Definition at line 29 of file Stack.h.

◆ Stack() [2/2]

template<typename T >
template<class Iterator >
Sawyer::Container::Stack< T >::Stack ( const boost::iterator_range< Iterator > &  range)
inline

Construct a stack from an iterator range.

Definition at line 33 of file Stack.h.

References Sawyer::Container::IndexedList< T, Alloc >::pushBack().

Member Function Documentation

◆ size()

template<typename T >
size_t Sawyer::Container::Stack< T >::size ( ) const
inline

Returns the number of items on the stack.

Definition at line 41 of file Stack.h.

References Sawyer::Container::IndexedList< T, Alloc >::size().

Referenced by Sawyer::Container::Stack< T >::get(), and Sawyer::Container::Stack< T >::get().

◆ isEmpty()

template<typename T >
bool Sawyer::Container::Stack< T >::isEmpty ( ) const
inline

Determines if the stack is empty.

Returns true if the stack is empty, false if not empty.

Definition at line 48 of file Stack.h.

References Sawyer::Container::IndexedList< T, Alloc >::isEmpty().

Referenced by Sawyer::Container::Stack< T >::top(), and Sawyer::Container::Stack< T >::top().

◆ top() [1/2]

template<typename T >
Value & Sawyer::Container::Stack< T >::top ( )
inline

Returns the top item.

Returns a reference to the top item of the stack. The stack must not be empty.

Definition at line 57 of file Stack.h.

References Sawyer::Container::IndexedList< T, Alloc >::backValue(), and Sawyer::Container::Stack< T >::isEmpty().

Referenced by Sawyer::Container::Stack< T >::pop().

◆ top() [2/2]

template<typename T >
const Value & Sawyer::Container::Stack< T >::top ( ) const
inline

Returns the top item.

Returns a reference to the top item of the stack. The stack must not be empty.

Definition at line 61 of file Stack.h.

References Sawyer::Container::IndexedList< T, Alloc >::backValue(), and Sawyer::Container::Stack< T >::isEmpty().

◆ get() [1/2]

template<typename T >
Value & Sawyer::Container::Stack< T >::get ( size_t  idx)
inline

Access an item not at the top of the stack.

Returns a reference to the indicated item. Item zero is the top of the stack, item one is the next item below the top, etc. The stack must not be empty, and idx must be less than the size of the stack.

Definition at line 73 of file Stack.h.

References Sawyer::Container::IndexedList< T, Alloc >::size(), and Sawyer::Container::Stack< T >::size().

Referenced by Sawyer::Container::Stack< T >::operator[](), and Sawyer::Container::Stack< T >::operator[]().

◆ get() [2/2]

template<typename T >
const Value & Sawyer::Container::Stack< T >::get ( size_t  idx) const
inline

Access an item not at the top of the stack.

Returns a reference to the indicated item. Item zero is the top of the stack, item one is the next item below the top, etc. The stack must not be empty, and idx must be less than the size of the stack.

Definition at line 77 of file Stack.h.

References Sawyer::Container::IndexedList< T, Alloc >::size(), and Sawyer::Container::Stack< T >::size().

◆ operator[]() [1/2]

template<typename T >
Value & Sawyer::Container::Stack< T >::operator[] ( size_t  idx)
inline

Access an item not at the top of the stack.

Returns a reference to the indicated item. Item zero is the top of the stack, item one is the next item below the top, etc. The stack must not be empty, and idx must be less than the size of the stack.

Definition at line 81 of file Stack.h.

References Sawyer::Container::Stack< T >::get().

◆ operator[]() [2/2]

template<typename T >
const Value & Sawyer::Container::Stack< T >::operator[] ( size_t  idx) const
inline

Access an item not at the top of the stack.

Returns a reference to the indicated item. Item zero is the top of the stack, item one is the next item below the top, etc. The stack must not be empty, and idx must be less than the size of the stack.

Definition at line 82 of file Stack.h.

References Sawyer::Container::Stack< T >::get().

◆ push()

template<typename T >
Stack & Sawyer::Container::Stack< T >::push ( const Value &  value)
inline

Push new item onto stack.

Copies the specified item onto the top of the stack, making the stack one element larger. The stack itself is returned so that this method can be chained.

Definition at line 89 of file Stack.h.

References Sawyer::Container::IndexedList< T, Alloc >::pushBack().

◆ pop()

template<typename T >
Value Sawyer::Container::Stack< T >::pop ( )
inline

Pop existing item from stack.

Copies the top item from the stack and returns it, then reduces the size of the stack by one element. The stack must not be empty at the time this method is called.

Definition at line 98 of file Stack.h.

References Sawyer::Container::IndexedList< T, Alloc >::erase(), Sawyer::Container::IndexedList< T, Alloc >::size(), and Sawyer::Container::Stack< T >::top().


The documentation for this class was generated from the following file: