home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games / INFESPGAMES.mdf / os2 / ribble / support / cslist.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-06  |  2.2 KB  |  94 lines

  1. // -------------------------------
  2. //  $Source: C:\logical\store\classes/RCS/CSLIST.H,v $
  3. //  $Revision: 1.8 $
  4. //  $Date: 1994/01/22 14:47:12 $
  5. //  $Author: jason $
  6. //  J.R.Shannon (jrs@larch.demon.co.uk)
  7. //  Language:       C++ (BC3.1, BC4.0, BCOS2 1.0, CSET++, WATCOM10.0)
  8. //  Licence:        Public Domain
  9. //  Purpose:        Singly linked list & iterator classes
  10. // -------------------------------
  11.  
  12. #ifndef _CSList_h
  13. #define _CSList_h
  14.  
  15. // Forward declaration of list and iterator
  16.  
  17. template <class T> class CSList;
  18. template <class T> class CSListIterator;
  19.  
  20. template <class T>
  21. class CSListNode
  22. {
  23. public:
  24.   CSListNode(const T& _item);
  25.  
  26. private:
  27.   CSListNode<T>* next;
  28.   T     item;
  29.   friend class CSList<T>;
  30.   friend class CSListIterator<T>;
  31. };
  32.  
  33. // -------------------------------------------------------------
  34. // The CSList class.  Assumes meaningful copy characteristics
  35. // for the item type to be stored, and a meaningful default
  36. // constructor.
  37. // -------------------------------------------------------------
  38.  
  39. template <class T>
  40. class CSList
  41. {
  42.   friend class CSListIterator<T>;
  43.  
  44. public:
  45.   CSListNode<T>* tail;
  46.  
  47. public:
  48.   CSList();
  49.   CSList(const CSList<T>& from);
  50.   ~CSList();
  51.   CSList<T>& operator=(const CSList<T>& from);
  52.   CSList<T>& operator+=(const T item);
  53.   T& getHead(void) const;
  54.   T& getTail(void) const;
  55.   void addTail(const T item);
  56.   void addHead(const T item);
  57.   T remHead(void);
  58.   int detach(const T item);
  59.   void destroy(void);
  60.   int isEmpty(void) const;
  61.   operator int() const;
  62.   int count(void) const;
  63. };
  64.  
  65. // -------------------------------------------------------------
  66. // The CSListIterator class.  Allows sequential perusal
  67. // of a CSList class's contents.
  68. // -------------------------------------------------------------
  69.  
  70. template <class T>
  71. class CSListIterator
  72. {
  73. protected:
  74.   CSListNode<T>*   cur;
  75.   const CSList<T>* list;
  76.  
  77. public:
  78.   CSListIterator(const CSList<T>& _list);
  79.   CSListIterator(const CSListIterator<T>& _it);
  80.   T& current(void) const;
  81.   void rewind(void);
  82.   operator int();
  83.   T& operator++(int);
  84.   T& operator++();
  85.   CSListIterator<T>& operator=(const CSListIterator<T>& _it);
  86. };
  87.  
  88. #ifndef _CSET2
  89. #include <CSList.c>
  90. #endif
  91.  
  92. #endif
  93.  
  94.