00001 00029 #ifndef ABA_BSTACK_INC 00030 #define ABA_BSTACK_INC 00031 00032 template <class Type> 00033 ABA_BSTACK<Type>::ABA_BSTACK(ABA_GLOBAL *glob, int size) 00034 : 00035 glob_(glob), 00036 stack_(glob, size), 00037 tos_(0) 00038 { } 00039 00040 template <class Type> 00041 ostream& operator<<(ostream &out, const ABA_BSTACK<Type> &rhs) 00042 { 00043 for (int i = 0; i < rhs.tos(); i++) 00044 out << i << " " << rhs.stack_[i] << endl; 00045 return out; 00046 } 00047 00048 template <class Type> 00049 inline int ABA_BSTACK<Type>::size() const 00050 { 00051 return stack_.size(); 00052 } 00053 00054 template <class Type> 00055 inline int ABA_BSTACK<Type>::tos() const 00056 { 00057 return tos_; 00058 } 00059 00060 template <class Type> 00061 inline bool ABA_BSTACK<Type>::empty() const 00062 { 00063 return tos_ ? false : true; 00064 } 00065 00066 00067 template <class Type> 00068 inline bool ABA_BSTACK<Type>::full() const 00069 { 00070 return tos_ == size() ? true : false; 00071 } 00072 00073 template <class Type> 00074 void ABA_BSTACK<Type>::push(Type item) 00075 { 00077 #ifdef ABACUSSAFE 00078 if (full()) { 00079 glob_->err() << "ABA_BSTACK::push: stack is full" << endl; 00080 exit(Fatal); 00081 } 00082 #endif 00083 00084 stack_[tos_++] = item; 00085 } 00086 00087 template <class Type> 00088 Type ABA_BSTACK<Type>::top() const 00089 { 00090 00092 #ifdef ABACUSSAFE 00093 if(empty()) { 00094 glob_->err() << "ABA_BSTACK::top/pop: cannot perform operation on empty stack." << endl; 00095 exit(Fatal); 00096 } 00097 #endif 00098 00099 return stack_[tos_-1]; 00100 } 00101 00102 template <class Type> 00103 Type ABA_BSTACK<Type>::pop() 00104 { 00106 #ifdef ABACUSSAFE 00107 if(empty()) { 00108 glob_->err() << "ABA_BSTACK::top/pop: cannot perform operation on empty stack." << endl; 00109 exit(Fatal); 00110 } 00111 #endif 00112 00113 return stack_[--tos_]; 00114 00115 } 00116 00117 template <class Type> 00118 void ABA_BSTACK<Type>::realloc(int newSize) 00119 { 00120 stack_.realloc(newSize); 00121 if (newSize < tos_) tos_ = newSize; 00122 } 00123 00124 #endif