00001 00038 #ifndef ABA_LIST_H 00039 #define ABA_LIST_H 00040 #include <iostream> 00041 using namespace std; 00042 00043 #include "abacus/abacusroot.h" 00044 #include "abacus/global.h" 00045 #include "abacus/listitem.h" 00046 00047 #ifdef ABACUS_NEW_TEMPLATE_SYNTAX 00048 template <class Type> 00049 class ABA_LIST; 00050 00051 template <class Type> 00052 ostream &operator<< (ostream&, const ABA_LIST<Type> &list); 00053 #endif 00054 00056 template<class Type> class ABA_LIST : public ABA_ABACUSROOT { 00057 friend class ABA_LISTITEM<Type>; 00058 public: 00059 00067 ABA_LIST(const ABA_GLOBAL *glob); 00068 00071 ~ABA_LIST(); 00072 #ifdef ABACUS_NEW_TEMPLATE_SYNTAX 00073 00081 friend ostream& operator<< <> (ostream&, const ABA_LIST<Type> &); 00082 #else 00083 00091 friend ostream& operator<< (ostream&, const ABA_LIST<Type> &list); 00092 #endif 00093 00098 void appendHead(const Type &elem); 00099 00104 void appendTail(const Type &elem); 00105 00114 int extractHead(Type &elem); 00115 00125 int firstElem(Type& elem) const; 00126 00130 bool empty() const; 00131 00132 private: 00133 00136 ABA_LISTITEM<Type>* first() const; 00137 00140 ABA_LISTITEM<Type>* last() const; 00141 00145 void appendHead(ABA_LISTITEM<Type> *item); 00146 00150 void appendTail(ABA_LISTITEM<Type> *item); 00151 00154 const ABA_GLOBAL *glob_; 00155 00158 ABA_LISTITEM<Type> *first_; 00159 00160 /* A pointer to last item of the list. 00161 */ 00162 ABA_LISTITEM<Type> *last_; 00163 ABA_LIST(const ABA_LIST &rhs); 00164 const ABA_LIST<Type>& operator=(const ABA_LIST<Type>& rhs); 00165 }; 00166 00167 #include "abacus/list.inc" 00168 00170 00186 #define forAllListElem(L, item, e) \ 00187 for((item = (L).first()) ? (e = (item)->elem()) : 0; item !=0; \ 00188 (item = (item)->succ()) ? (e = (item)->elem()) : 0) 00189 00190 #endif // ABA_LIST_H 00191