// File: genlist.h // // A generic list class // // Version 11/12/98 9:30am. Removed friend decalration in ListCell #ifndef _genlist_h #define _genlist_h class ListCell{ public: ListCell *next ; // next cell on the list ListCell() ; // constructor virtual ~ListCell() ; // virtual destructor virtual ListCell *clone() const ; // make a copy virtual int cmp(const ListCell&) const ; // virtual comparison virtual void print() const ; // virtual print virtual int *id() const ; // return &idvar static int idvar ; } ; class GenList { public: GenList() ; // constructor ~GenList() ; // destructor GenList(GenList&) ; GenList& operator=(const GenList&) ; void append(const ListCell&) ; // Add item to end of list void prepend(const ListCell&) ; // Add item to front of list ListCell *chop() ; // Remove & return first item void print() const ; // Print the entire list void remove(const ListCell&) ; // Remove every item with given key inline ListCell *begin() const ; // Return item at the front inline ListCell *end() const ; // Return item at the end inline int length() const ; // Return number of items in list protected: ListCell dummy ; // dummy ListCell (not pointer!) ListCell *last ; // last item in the list int len ; // number of items in the list enum {clean = 0, dirty} ; int cache_status ; // clean or dirty } ; //======================================================================== // ListCell inline functions // inline ListCell *GenList::begin() const { return dummy.next ; } inline ListCell *GenList::end() const { if (last == &dummy) return NULL ; return last ; } inline int GenList::length() const { return len ; } #endif