feisty meow concerns codebase  2.140
structures::stack< contents > Class Template Reference

An abstraction that represents a stack data structure. More...

#include <stack.h>

Public Types

enum  stack_kinds { BOUNDED , UNBOUNDED }
 

Public Member Functions

 stack (int elements=0)
 Creates a stack with room for the specified number of "elements". More...
 
 stack (const stack &to_copy)
 constructs a stack as a copy of "to_copy". More...
 
 ~stack ()
 destroys anything left on the stack. More...
 
void reset ()
 throws out all contents on the stack. More...
 
stack_kinds kind () const
 returns the type of stack that was constructed. More...
 
basis::outcome push (const contents &element)
 Enters a new element onto the top of the stack. More...
 
basis::outcome pop ()
 Removes the top element on the stack. More...
 
contents & top ()
 Returns the top element from the stack but doesn't change the stack. More...
 
basis::outcome acquire_pop (contents &to_stuff)
 Used to grab the top off of the stack. More...
 
int size () const
 returns the size of the stack. More...
 
stackoperator= (const stack &to_copy)
 makes this stack a copy of "to_copy". More...
 
contents & operator[] (int index)
 Accesses the item at position "index" in the stack. More...
 
void invert ()
 Inverts this stack, meaning that the old bottom is the new top. More...
 
int elements () const
 Returns the number of elements used by the stack. More...
 

Detailed Description

template<class contents>
class structures::stack< contents >

An abstraction that represents a stack data structure.

This behaves like a standard stack of objects, but it additionally allows access to any item in the stack via an array style bracket operator.

Definition at line 29 of file stack.h.

Member Enumeration Documentation

◆ stack_kinds

template<class contents >
enum structures::stack::stack_kinds
Enumerator
BOUNDED 
UNBOUNDED 

Definition at line 32 of file stack.h.

Constructor & Destructor Documentation

◆ stack() [1/2]

template<class contents >
structures::stack< contents >::stack ( int  elements = 0)

Creates a stack with room for the specified number of "elements".

If "elements" is zero, then the stack is an UNBOUNDED stack that has no set limit on the number of elements it can contain (besides the amount of memory available). on an unbounded stack, a result of IS_FULL will never be returned–instead a memory allocation failure would occur. If "elements" is greater than zero, then the stack is a BOUNDED stack which can hold at maximum "elements" number of objects. for bounded stacks, if there is to be an allocation failure, it will happen at the time of stack construction, rather than during execution.

Definition at line 113 of file stack.h.

◆ stack() [2/2]

template<class contents >
structures::stack< contents >::stack ( const stack< contents > &  to_copy)

constructs a stack as a copy of "to_copy".

Definition at line 120 of file stack.h.

References structures::stack< contents >::operator=().

◆ ~stack()

template<class contents >
structures::stack< contents >::~stack

destroys anything left on the stack.

Definition at line 124 of file stack.h.

Member Function Documentation

◆ acquire_pop()

template<class contents >
basis::outcome structures::stack< contents >::acquire_pop ( contents &  to_stuff)

Used to grab the top off of the stack.

this is basically a call to top() followed by a pop(). if there was no top, then IS_EMPTY is returned.

Definition at line 196 of file stack.h.

Referenced by nodes::packable_tree::recursive_unpack(), and nodes::tree::~tree().

◆ elements()

template<class contents >
int structures::stack< contents >::elements

Returns the number of elements used by the stack.

For a bounded stack, this returns the number of elements the stack was constructed to hold. For an unbounded stack, it returns the current number of elements (which is the same as size()). Note though that it is different from size() for a bounded size stack!

Definition at line 136 of file stack.h.

◆ invert()

template<class contents >
void structures::stack< contents >::invert

Inverts this stack, meaning that the old bottom is the new top.

Definition at line 178 of file stack.h.

◆ kind()

template<class contents >
stack_kinds structures::stack< contents >::kind ( ) const
inline

returns the type of stack that was constructed.

Definition at line 54 of file stack.h.

Referenced by configuration::variable_tokenizer::parse().

◆ operator=()

template<class contents >
stack< contents > & structures::stack< contents >::operator= ( const stack< contents > &  to_copy)

makes this stack a copy of "to_copy".

Definition at line 165 of file stack.h.

Referenced by structures::stack< contents >::stack().

◆ operator[]()

template<class contents >
contents & structures::stack< contents >::operator[] ( int  index)

Accesses the item at position "index" in the stack.

Allows access to the stack in an impure fashion; elements other than the top can be examined. Efforts to access elements that do not exist are ignored. The range for the element numbers is as in C and runs from 0 to size() - 1.

Definition at line 189 of file stack.h.

◆ pop()

template<class contents >
basis::outcome structures::stack< contents >::pop

Removes the top element on the stack.

If the stack has no elements to be popped off, then IS_EMPTY is returned. The element that was popped is destroyed.

Definition at line 151 of file stack.h.

Referenced by configuration::variable_tokenizer::parse().

◆ push()

template<class contents >
basis::outcome structures::stack< contents >::push ( const contents &  element)

Enters a new element onto the top of the stack.

if the stack is too large to add another element, then IS_FULL is returned. if the element to push is nil, the stack is unchanged and IS_EMPTY is returned.

Definition at line 139 of file stack.h.

Referenced by configuration::variable_tokenizer::parse(), nodes::packable_tree::recursive_unpack(), and nodes::tree::~tree().

◆ reset()

template<class contents >
void structures::stack< contents >::reset

throws out all contents on the stack.

Definition at line 130 of file stack.h.

◆ size()

template<class contents >
int structures::stack< contents >::size

returns the size of the stack.

if the stack is empty, then 0 is returned.

Definition at line 127 of file stack.h.

Referenced by configuration::variable_tokenizer::parse(), nodes::packable_tree::recursive_unpack(), and nodes::tree::~tree().

◆ top()

template<class contents >
contents & structures::stack< contents >::top

Returns the top element from the stack but doesn't change the stack.

This method does not pop the element! If the stack is empty, then a bogus contents object is returned.

Definition at line 161 of file stack.h.

Referenced by configuration::variable_tokenizer::parse().


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