home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2587 / List.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-20  |  2.8 KB  |  112 lines

  1. /*
  2.  * This is a semi-generic List class.
  3.  * This was written for FolkScan v2.2
  4.  * Copyright (C) 1992 Cory West
  5.  * corywest@rice.edu ; List.h ; Fri Nov 13 17:34:46 CST 1992
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 1, or (at your option)
  10.  * any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. #include <String.h>
  23. #include <bool.h>
  24. #include <curses.h>
  25. #include <string.h>
  26.  
  27. // These are list links
  28. struct ListLink
  29. {
  30.   ListLink* next = NULL;
  31.   ListLink* prev = NULL;
  32.   String name;
  33.   int alive = 3;
  34.   
  35.   // These are used when FolkScan runs in the background.
  36.   // This is yet another adaption to the interface.
  37.   // I should separate all of these special cases into a
  38.   // set of inherited classes.
  39.   bool seen = FALSE;
  40.   bool clean = TRUE;
  41. };
  42.  
  43. // This controls access to the list
  44. class List
  45. {
  46. private:
  47.   
  48.   ListLink* head = NULL;
  49.   int length = 0;
  50.   
  51. public:
  52.  
  53.   // Constructor and Destructor
  54.   List() { ; }
  55.  
  56.   // Useful interface functions
  57.  
  58.   int GetSize() { return length; }
  59.     // Return the number of elements in the
  60.     // list.  Index starts at 1.
  61.  
  62.   void AddElement(String);
  63.     // Add something to the list.
  64.  
  65.   String GetElement(int location);
  66.     // Get the element in the specified in zero based
  67.     // location. 
  68.  
  69.   void MarkDead(String);
  70.     // Decrement the named hosts grace failures.
  71.  
  72.   void RemoveDead(WINDOW*);
  73.     // Remove dead hosts and report to the given WINDOW.
  74.  
  75.   bool unify(char*);
  76.     // This is a semi-robust function to allow
  77.     // us to use this list as a cache.  If the
  78.     // provided char* already exists in the
  79.     // List, then this returns false.  Otherwise
  80.     // it returns true and remembers that we've
  81.     // seen the entry.  Report problems to errs.
  82.  
  83.   void dump(void);
  84.     // Totally clean out the structure.
  85.  
  86.   void printall(void);
  87.     // Print the representation of the structure
  88.     // out to standard error for debugging usage.
  89.  
  90.   void Seen(int);
  91.     // We've seen this node (user in the case that we use
  92.     // it) logged in.
  93.  
  94.   void UnSee(int);
  95.     // Unmark the seen bit.
  96.  
  97.   bool Saw(int);
  98.     // Predicate for Seen();
  99.  
  100.   void CleanAll(void);
  101.     // Mark all the the clean booleans to TRUE;
  102.  
  103.   void MakeDirty(int);
  104.     // Mark the kth node as dirty.
  105.  
  106.   bool isClean(int);
  107.     // Is the kth node clean?
  108. };
  109.   
  110.   
  111.   
  112.