stack< contents > Class Template Reference

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

#include <stack.h>

Inheritance diagram for stack< contents >:

Inheritance graph
[legend]
List of all members.

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

Detailed Description

template<class contents>
class 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 27 of file stack.h.


Member Enumeration Documentation

template<class contents>
enum stack::stack_kinds

Enumerator:
BOUNDED 
UNBOUNDED 

Definition at line 30 of file stack.h.


Constructor & Destructor Documentation

template<class contents>
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 24 of file stack.cpp.

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

constructs a stack as a copy of "to_copy".

Definition at line 31 of file stack.cpp.

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

template<class contents>
stack< contents >::~stack (  ) 

destroys anything left on the stack.

Definition at line 35 of file stack.cpp.


Member Function Documentation

template<class contents>
void stack< contents >::reset (  ) 

throws out all contents on the stack.

Definition at line 41 of file stack.cpp.

References common::OKAY, and stack< contents >::pop().

Referenced by stack< contents >::operator=().

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

returns the type of stack that was constructed.

Definition at line 52 of file stack.h.

Referenced by tokenizer::parse().

template<class contents>
outcome 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 50 of file stack.cpp.

References stack< contents >::BOUNDED, stack< contents >::elements(), common::IS_FULL, and common::OKAY.

Referenced by tokenizer::parse(), nodes::packable_tree::recursive_unpack(), test_stack_with_objects(), and test_stack_with_pointers().

template<class contents>
outcome 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 62 of file stack.cpp.

References common::IS_EMPTY, common::OKAY, and stack< contents >::UNBOUNDED.

Referenced by tokenizer::parse(), stack< contents >::reset(), test_stack_with_objects(), and test_stack_with_pointers().

template<class contents>
contents & 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 72 of file stack.cpp.

Referenced by tokenizer::parse(), test_stack_with_objects(), and test_stack_with_pointers().

template<class contents>
outcome 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 107 of file stack.cpp.

References stack< contents >::elements(), common::IS_EMPTY, common::OKAY, and stack< contents >::UNBOUNDED.

Referenced by nodes::packable_tree::recursive_unpack(), test_stack_with_objects(), and test_stack_with_pointers().

template<class contents>
int stack< contents >::size (  )  const

returns the size of the stack.

if the stack is empty, then 0 is returned.

Definition at line 38 of file stack.cpp.

Referenced by tokenizer::parse(), nodes::packable_tree::recursive_unpack(), test_stack_with_objects(), and test_stack_with_pointers().

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

makes this stack a copy of "to_copy".

Definition at line 76 of file stack.cpp.

References stack< contents >::_kind, stack< contents >::_store, stack< contents >::_valid_fields, and stack< contents >::reset().

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

template<class contents>
contents & 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 100 of file stack.cpp.

template<class contents>
void stack< contents >::invert (  ) 

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

Definition at line 89 of file stack.cpp.

template<class contents>
int stack< contents >::elements (  )  const

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 47 of file stack.cpp.

Referenced by stack< contents >::acquire_pop(), stack< contents >::push(), and text_form().


The documentation for this class was generated from the following files:
Generated on Fri Nov 28 04:31:01 2008 for HOOPLE Libraries by  doxygen 1.5.1