ACE_Bounded_Stack< T > Class Template Reference

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

#include <Containers_T.h>

Collaboration diagram for ACE_Bounded_Stack< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

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

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

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

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

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

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

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

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

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

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


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Attributes

size_t size_
 Size of the dynamically allocated data.

size_t top_
 Keeps track of the current top of stack.

T * stack_
 Holds the stack's contents.


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 78 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 33 of file Containers_T.cpp.

References ACE_NEW, and ACE_TRACE.

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

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 43 of file Containers_T.cpp.

References ACE_NEW, ACE_TRACE, ACE_Bounded_Stack< T >::size_, ACE_Bounded_Stack< T >::stack_, and ACE_Bounded_Stack< T >::top_.

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

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 78 of file Containers_T.cpp.

References ACE_TRACE, and ACE_Bounded_Stack< T >::stack_.

00079 {
00080   ACE_TRACE ("ACE_Bounded_Stack<T>::~ACE_Bounded_Stack");
00081   delete [] this->stack_;
00082 }


Member Function Documentation

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

Dump the state of an object.

Definition at line 25 of file Containers_T.cpp.

References ACE_TRACE.

00026 {
00027 #if defined (ACE_HAS_DUMP)
00028   ACE_TRACE ("ACE_Bounded_Stack<T>::dump");
00029 #endif /* ACE_HAS_DUMP */
00030 }

template<class T>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL 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 8 of file Containers_T.inl.

References ACE_TRACE, and ACE_Bounded_Stack< T >::top_.

Referenced by ACE_Bounded_Stack< T >::pop(), and ACE_Bounded_Stack< T >::top().

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

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 15 of file Containers_T.inl.

References ACE_TRACE, and ACE_Bounded_Stack< T >::top_.

Referenced by ACE_Bounded_Stack< T >::push().

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

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 57 of file Containers_T.cpp.

References ACE_NEW, ACE_TRACE, ACE_Bounded_Stack< T >::size_, ACE_Bounded_Stack< T >::stack_, and ACE_Bounded_Stack< T >::top_.

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

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 35 of file Containers_T.inl.

References ACE_TRACE, ACE_Bounded_Stack< T >::is_empty(), ACE_Bounded_Stack< T >::stack_, and ACE_Bounded_Stack< T >::top_.

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

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 22 of file Containers_T.inl.

References ACE_TRACE, ACE_Bounded_Stack< T >::is_full(), ACE_Bounded_Stack< T >::stack_, and ACE_Bounded_Stack< T >::top_.

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

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 61 of file Containers_T.inl.

00062 {
00063   return this->size_;
00064 }

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 48 of file Containers_T.inl.

References ACE_TRACE, ACE_Bounded_Stack< T >::is_empty(), ACE_Bounded_Stack< T >::stack_, and ACE_Bounded_Stack< T >::top_.

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


Member Data Documentation

template<class T>
ACE_Bounded_Stack< T >::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 161 of file Containers_T.h.

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

Size of the dynamically allocated data.

Definition at line 165 of file Containers_T.h.

Referenced by ACE_Bounded_Stack< T >::ACE_Bounded_Stack(), and ACE_Bounded_Stack< T >::operator=().

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

Holds the stack's contents.

Definition at line 171 of file Containers_T.h.

Referenced by ACE_Bounded_Stack< T >::ACE_Bounded_Stack(), ACE_Bounded_Stack< T >::operator=(), ACE_Bounded_Stack< T >::pop(), ACE_Bounded_Stack< T >::push(), ACE_Bounded_Stack< T >::top(), and ACE_Bounded_Stack< T >::~ACE_Bounded_Stack().

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

Keeps track of the current top of stack.

Definition at line 168 of file Containers_T.h.

Referenced by ACE_Bounded_Stack< T >::ACE_Bounded_Stack(), ACE_Bounded_Stack< T >::is_empty(), ACE_Bounded_Stack< T >::is_full(), ACE_Bounded_Stack< T >::operator=(), ACE_Bounded_Stack< T >::pop(), ACE_Bounded_Stack< T >::push(), and ACE_Bounded_Stack< T >::top().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:20:24 2006 for ACE by doxygen 1.3.6