Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Bounded_Stack Class Template Reference

Implement a generic LIFO abstract data type. More...

#include <Containers_T.h>

Collaboration diagram for ACE_Bounded_Stack:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Bounded_Stack (size_t size)
 Initialize a new empty stack with the provided size.. More...

 ACE_Bounded_Stack (const ACE_Bounded_Stack< T > &s)
 Initialize the stack to be a copy of the stack provided. More...

void operator= (const ACE_Bounded_Stack< T > &s)
 Assignment operator. More...

 ~ACE_Bounded_Stack (void)
 Perform actions needed when stack goes out of scope. More...

int push (const T &new_item)
 Add an element to the top of the stack. More...

int pop (T &item)
 Remove an item from the top of stack. More...

int top (T &item) const
 Examine the contents of the top of stack. More...

int is_empty (void) const
 Returns 1 if the container is empty, otherwise returns 0. More...

int is_full (void) const
 Returns 1 if the container is full, otherwise returns 0. More...

size_t size (void) const
 The number of items in the stack. More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Private Attributes

size_t size_
 Size of the dynamically allocated data. More...

size_t top_
 Keeps track of the current top of stack. More...

T * stack_
 Holds the stack's contents. More...


Detailed Description

template<class T>
class ACE_Bounded_Stack< T >

Implement a generic LIFO abstract data type.

This implementation of a Stack uses a bounded array that is allocated dynamically. The Stack interface provides the standard constant time push, pop, and top operations.

Requirements and Performance Characteristics

Definition at line 76 of file Containers_T.h.


Constructor & Destructor Documentation

template<class T>
ACE_Bounded_Stack< T >::ACE_Bounded_Stack size_t    size
 

Initialize a new empty stack with the provided size..

Initialize and allocate space for a new Bounded_Stack with the provided size.

Definition at line 30 of file Containers_T.cpp.

References ACE_NEW, ACE_TRACE, and size.

00031   : size_ (size),
00032     top_ (0)
00033 {
00034   ACE_NEW (this->stack_,
00035            T[size]);
00036   ACE_TRACE ("ACE_Bounded_Stack<T>::ACE_Bounded_Stack");
00037 }

template<class T>
ACE_Bounded_Stack< T >::ACE_Bounded_Stack const ACE_Bounded_Stack< T > &    s
 

Initialize the stack to be a copy of the stack provided.

Initialize the stack to be an exact copy of the Bounded_Stack provided as a parameter.

Definition at line 40 of file Containers_T.cpp.

References ACE_NEW, ACE_TRACE, stack_, and top_.

00041   : size_ (s.size_),
00042     top_ (s.top_)
00043 {
00044   ACE_NEW (this->stack_,
00045            T[s.size_]);
00046 
00047   ACE_TRACE ("ACE_Bounded_Stack<T>::ACE_Bounded_Stack");
00048 
00049   for (size_t i = 0; i < this->top_; i++)
00050     this->stack_[i] = s.stack_[i];
00051 }

template<class T>
ACE_Bounded_Stack< T >::~ACE_Bounded_Stack void   
 

Perform actions needed when stack goes out of scope.

Deallocate the memory used by the Bounded_Stack.

Definition at line 75 of file Containers_T.cpp.

References ACE_TRACE, and stack_.

00076 {
00077   ACE_TRACE ("ACE_Bounded_Stack<T>::~ACE_Bounded_Stack");
00078   delete [] this->stack_;
00079 }


Member Function Documentation

template<class T>
void ACE_Bounded_Stack< T >::dump void    const
 

Dump the state of an object.

Definition at line 24 of file Containers_T.cpp.

References ACE_TRACE.

00025 {
00026   ACE_TRACE ("ACE_Bounded_Stack<T>::dump");
00027 }

template<class T>
ACE_INLINE int ACE_Bounded_Stack< T >::is_empty void    const
 

Returns 1 if the container is empty, otherwise returns 0.

Performs constant time check to determine if the stack is empty.

Definition at line 7 of file Containers_T.i.

References ACE_TRACE, and top_.

Referenced by pop, and top.

00008 {
00009   ACE_TRACE ("ACE_Bounded_Stack<T>::is_empty");
00010   return this->top_ == 0;
00011 }

template<class T>
ACE_INLINE int ACE_Bounded_Stack< T >::is_full void    const
 

Returns 1 if the container is full, otherwise returns 0.

Performs constant time check to determine if the stack is at capacity.

Definition at line 14 of file Containers_T.i.

References ACE_TRACE, size_, and top_.

Referenced by push.

00015 {
00016   ACE_TRACE ("ACE_Bounded_Stack<T>::is_full");
00017   return this->top_ >= this->size_;
00018 }

template<class T>
void ACE_Bounded_Stack< T >::operator= const ACE_Bounded_Stack< T > &    s
 

Assignment operator.

Perform a deep copy operation using the Bounded_Stack parameter. If the capacity of the lhs isn't sufficient for the rhs, then the underlying data structure will be reallocated to accomadate the larger number of elements.

Definition at line 54 of file Containers_T.cpp.

References ACE_NEW, ACE_TRACE, size_, stack_, and top_.

00055 {
00056   ACE_TRACE ("ACE_Bounded_Stack<T>::operator=");
00057 
00058   if (&s != this)
00059     {
00060       if (this->size_ < s.size_)
00061         {
00062           delete [] this->stack_;
00063           ACE_NEW (this->stack_,
00064                    T[s.size_]);
00065           this->size_ = s.size_;
00066         }
00067       this->top_ = s.top_;
00068 
00069       for (size_t i = 0; i < this->top_; i++)
00070         this->stack_[i] = s.stack_[i];
00071     }
00072 }

template<class T>
ACE_INLINE int ACE_Bounded_Stack< T >::pop T &    item
 

Remove an item from the top of stack.

Remove and return the top stack item. Returns -1 if the stack is already empty, 0 if the stack is not already empty, and -1 if failure occurs.

Definition at line 34 of file Containers_T.i.

References ACE_TRACE, is_empty, stack_, and top_.

00035 {
00036   ACE_TRACE ("ACE_Bounded_Stack<T>::pop");
00037   if (this->is_empty () == 0)
00038     {
00039       item = this->stack_[--this->top_];
00040       return 0;
00041     }
00042   else
00043     return -1;
00044 }

template<class T>
ACE_INLINE int ACE_Bounded_Stack< T >::push const T &    new_item
 

Add an element to the top of the stack.

Place a new item on top of the stack. Returns -1 if the stack is already full, 0 if the stack is not already full, and -1 if failure occurs.

Definition at line 21 of file Containers_T.i.

References ACE_TRACE, is_full, stack_, and top_.

00022 {
00023   ACE_TRACE ("ACE_Bounded_Stack<T>::push");
00024   if (this->is_full () == 0)
00025     {
00026       this->stack_[this->top_++] = new_item;
00027       return 0;
00028     }
00029   else
00030     return -1;
00031 }

template<class T>
ACE_INLINE size_t ACE_Bounded_Stack< T >::size void    const
 

The number of items in the stack.

Return the number of items currently in the stack.

Definition at line 60 of file Containers_T.i.

References size_.

Referenced by ACE_Bounded_Stack.

00061 {
00062   return this->size_;
00063 }

template<class T>
ACE_INLINE int ACE_Bounded_Stack< T >::top T &    item const
 

Examine the contents of the top of stack.

Return top stack item without removing it. Returns -1 if the stack is already empty, 0 if the stack is not already empty, and -1 if failure occurs.

Definition at line 47 of file Containers_T.i.

References ACE_TRACE, is_empty, stack_, and top_.

00048 {
00049   ACE_TRACE ("ACE_Bounded_Stack<T>::top");
00050   if (this->is_empty () == 0)
00051     {
00052       item = this->stack_[this->top_ - 1];
00053       return 0;
00054     }
00055   else
00056     return -1;
00057 }


Member Data Documentation

template<class T>
ACE_Bounded_Stack::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 159 of file Containers_T.h.

template<class T>
size_t ACE_Bounded_Stack::size_ [private]
 

Size of the dynamically allocated data.

Definition at line 163 of file Containers_T.h.

Referenced by is_full, operator=, and size.

template<class T>
T* ACE_Bounded_Stack::stack_ [private]
 

Holds the stack's contents.

Definition at line 169 of file Containers_T.h.

Referenced by ACE_Bounded_Stack, operator=, pop, push, top, and ~ACE_Bounded_Stack.

template<class T>
size_t ACE_Bounded_Stack::top_ [private]
 

Keeps track of the current top of stack.

Definition at line 166 of file Containers_T.h.

Referenced by ACE_Bounded_Stack, is_empty, is_full, operator=, pop, push, and top.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:46:15 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002