home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_06 / 9n06058a < prev    next >
Text File  |  1991-02-25  |  958b  |  56 lines

  1. //  class ThingList    --  a list of Things
  2. //
  3. //    Version 1.0    --  2/25/91
  4. //
  5. //    Michael Kelly    --  Author
  6. //
  7. //    See class Thing ( Thing.hpp )
  8. //
  9. #if !defined(TH_LIST_HPP)
  10. #define TH_LIST_HPP
  11.  
  12. #include "thing.hpp"
  13.  
  14. class ThingList  {
  15.  
  16.   struct thing_node  {
  17.     thing_node  *next;
  18.     Thing      *this_thing;
  19.   };
  20.  
  21.   thing_node      *head,
  22.         *rover;
  23.  
  24.   unsigned    nodes;
  25.  
  26.   public:
  27.  
  28.     ThingList()
  29.     {
  30.     head = rover = NULL;
  31.     nodes = 0;
  32.     }
  33.     ThingList( Thing &some_thing )
  34.     {
  35.     if( head = new thing_node )  {
  36.         head->this_thing = &some_thing;
  37.         head->next = NULL;
  38.         nodes = 1;
  39.     }
  40.     else  {
  41.         head = rover = NULL;
  42.         nodes = 0;
  43.     }
  44.     }
  45.  
  46.     ~ThingList();
  47.  
  48.     int     add( Thing &some_thing );
  49.     unsigned    iterate( void ( Thing::*funcptr )() );
  50.     unsigned    iterate( int  ( Thing::*funcptr )() );
  51.     Thing *operator[]( unsigned index );
  52.     unsigned list_nodes() { return nodes; }
  53. };
  54.  
  55. #endif
  56.