ACE_Fixed_Stack< T, ACE_SIZE > Class Template Reference

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

#include <Containers_T.h>

Collaboration diagram for ACE_Fixed_Stack< T, ACE_SIZE >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Fixed_Stack (void)
 Initialize a new stack so that it is empty.

 ACE_Fixed_Stack (const ACE_Fixed_Stack< T, ACE_SIZE > &s)
 The copy constructor (performs initialization).

void operator= (const ACE_Fixed_Stack< T, ACE_SIZE > &s)
 Assignment operator (performs assignment).

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

int push (const T &new_item)
 Constant time placement of element on top of stack.

int pop (T &item)
 Constant time removal of top of stack.

int top (T &item) const
 Constant time examination of 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 allocated data.

size_t top_
 Keeps track of the current top of stack.

stack_ [ACE_SIZE]
 Holds the stack's contents.


Detailed Description

template<class T, size_t ACE_SIZE>
class ACE_Fixed_Stack< T, ACE_SIZE >

Implement a generic LIFO abstract data type.

This implementation of a Stack uses a fixed array with the size fixed at instantiation time.

Requirements and Performance Characteristics

Definition at line 209 of file Containers_T.h.


Constructor & Destructor Documentation

template<class T, size_t ACE_SIZE>
ACE_Fixed_Stack< T, ACE_SIZE >::ACE_Fixed_Stack void   ) 
 

Initialize a new stack so that it is empty.

Initialize an empty stack.

Definition at line 97 of file Containers_T.cpp.

References ACE_TRACE.

00098   : size_ (ACE_SIZE),
00099     top_ (0)
00100 {
00101   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::ACE_Fixed_Stack");
00102 }

template<class T, size_t ACE_SIZE>
ACE_Fixed_Stack< T, ACE_SIZE >::ACE_Fixed_Stack const ACE_Fixed_Stack< T, ACE_SIZE > &  s  ) 
 

The copy constructor (performs initialization).

Initialize the stack and copy the provided stack into the current stack.

Definition at line 105 of file Containers_T.cpp.

References ACE_TRACE, and ACE_Fixed_Stack< T, ACE_SIZE >::stack_.

00106   : size_ (s.size_),
00107     top_ (s.top_)
00108 {
00109   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::ACE_Fixed_Stack");
00110   for (size_t i = 0; i < this->top_; i++)
00111     this->stack_[i] = s.stack_[i];
00112 }

template<class T, size_t ACE_SIZE>
ACE_Fixed_Stack< T, ACE_SIZE >::~ACE_Fixed_Stack void   ) 
 

Perform actions needed when stack goes out of scope.

Destroy the stack.

Definition at line 129 of file Containers_T.cpp.

References ACE_TRACE.

00130 {
00131   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::~ACE_Fixed_Stack");
00132 }


Member Function Documentation

template<class T, size_t ACE_SIZE>
void ACE_Fixed_Stack< T, ACE_SIZE >::dump void   )  const
 

Dump the state of an object.

Definition at line 89 of file Containers_T.cpp.

References ACE_TRACE.

00090 {
00091 #if defined (ACE_HAS_DUMP)
00092   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::dump");
00093 #endif /* ACE_HAS_DUMP */
00094 }

template<class T, size_t ACE_SIZE>
ACE_INLINE int ACE_Fixed_Stack< T, ACE_SIZE >::is_empty void   )  const
 

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

Performs constant time check to see if stack is empty.

Definition at line 69 of file Containers_T.inl.

References ACE_TRACE.

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

00070 {
00071   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::is_empty");
00072   return this->top_ == 0;
00073 }

template<class T, size_t ACE_SIZE>
ACE_INLINE int ACE_Fixed_Stack< T, ACE_SIZE >::is_full void   )  const
 

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

Performs constant time check to see if stack is full.

Definition at line 76 of file Containers_T.inl.

References ACE_TRACE.

Referenced by ACE_Fixed_Stack< T, ACE_SIZE >::push().

00077 {
00078   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::is_full");
00079   return this->top_ >= this->size_;
00080 }

template<class T, size_t ACE_SIZE>
void ACE_Fixed_Stack< T, ACE_SIZE >::operator= const ACE_Fixed_Stack< T, ACE_SIZE > &  s  ) 
 

Assignment operator (performs assignment).

Perform a deep copy of the provided stack.

Definition at line 115 of file Containers_T.cpp.

References ACE_TRACE, ACE_Fixed_Stack< T, ACE_SIZE >::stack_, and ACE_Fixed_Stack< T, ACE_SIZE >::top_.

00116 {
00117   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::operator=");
00118 
00119   if (&s != this)
00120     {
00121       this->top_ = s.top_;
00122 
00123       for (size_t i = 0; i < this->top_; i++)
00124         this->stack_[i] = s.stack_[i];
00125     }
00126 }

template<class T, size_t ACE_SIZE>
ACE_INLINE int ACE_Fixed_Stack< T, ACE_SIZE >::pop T &  item  ) 
 

Constant time removal of 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 96 of file Containers_T.inl.

References ACE_TRACE, and ACE_Fixed_Stack< T, ACE_SIZE >::is_empty().

00097 {
00098   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::pop");
00099   if (this->is_empty () == 0)
00100     {
00101       item = this->stack_[--this->top_];
00102       return 0;
00103     }
00104   else
00105     return -1;
00106 }

template<class T, size_t ACE_SIZE>
ACE_INLINE int ACE_Fixed_Stack< T, ACE_SIZE >::push const T &  new_item  ) 
 

Constant time placement of element on top of 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 83 of file Containers_T.inl.

References ACE_TRACE, and ACE_Fixed_Stack< T, ACE_SIZE >::is_full().

00084 {
00085   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::push");
00086   if (this->is_full () == 0)
00087     {
00088       this->stack_[this->top_++] = new_item;
00089       return 0;
00090     }
00091   else
00092     return -1;
00093 }

template<class T, size_t ACE_SIZE>
ACE_INLINE size_t ACE_Fixed_Stack< T, ACE_SIZE >::size void   )  const
 

The number of items in the stack.

Constant time access to the current size of the stack.

Definition at line 122 of file Containers_T.inl.

00123 {
00124   return this->size_;
00125 }

template<class T, size_t ACE_SIZE>
ACE_INLINE int ACE_Fixed_Stack< T, ACE_SIZE >::top T &  item  )  const
 

Constant time examination of 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 109 of file Containers_T.inl.

References ACE_TRACE, and ACE_Fixed_Stack< T, ACE_SIZE >::is_empty().

00110 {
00111   ACE_TRACE ("ACE_Fixed_Stack<T, ACE_SIZE>::top");
00112   if (this->is_empty () == 0)
00113     {
00114       item = this->stack_[this->top_ - 1];
00115       return 0;
00116     }
00117   else
00118     return -1;
00119 }


Member Data Documentation

template<class T, size_t ACE_SIZE>
ACE_Fixed_Stack< T, ACE_SIZE >::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 287 of file Containers_T.h.

template<class T, size_t ACE_SIZE>
size_t ACE_Fixed_Stack< T, ACE_SIZE >::size_ [private]
 

Size of the allocated data.

Definition at line 291 of file Containers_T.h.

template<class T, size_t ACE_SIZE>
T ACE_Fixed_Stack< T, ACE_SIZE >::stack_[ACE_SIZE] [private]
 

Holds the stack's contents.

Definition at line 297 of file Containers_T.h.

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

template<class T, size_t ACE_SIZE>
size_t ACE_Fixed_Stack< T, ACE_SIZE >::top_ [private]
 

Keeps track of the current top of stack.

Definition at line 294 of file Containers_T.h.

Referenced by ACE_Fixed_Stack< T, ACE_SIZE >::operator=().


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