home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 308_01 / dbl_list.hpp < prev    next >
C/C++ Source or Header  |  1990-09-22  |  3KB  |  105 lines

  1.  
  2. /*
  3.     TITLE:          C++ doubly-linked list object header file;
  4.     DESCRIPTION:    "Header file for doubly-linked list object";
  5.     VERSION:        1.01;
  6.     DATE:           9/22/90;
  7.     COMPILERS:      Borland Turbo C++ V.1.0;
  8.     KEYWORDS:       list object header;
  9.     FILENAME:       Dbl_List.hpp;
  10.     SEE-ALSO:       Dbl_List.cpp;
  11.  
  12.     AUTHOR:         Michael Kelly
  13.             254 Gold St. Boston, Ma. 02127
  14.             Copyright 1990;
  15.  
  16.     COPYRIGHT:    This code may not be commercially distributed
  17.             without prior arrangement with the author.  It
  18.             may be used by programmers, without royalty, for
  19.             their personal programs and for "one of a kind"
  20.             or "custom" applications, provided that said
  21.             programmers assume all liability concerning
  22.             same.
  23. */
  24.  
  25.  //             ----------< DoubleList Object Header >----------
  26.  
  27.  
  28. #if !defined(DBL_LIST_HPP)
  29. #define DBL_LIST_HPP
  30.  
  31. #include <string.h>
  32.  
  33. #if !defined(BASELIST_HPP)
  34. #include "baselist.hpp"
  35. #endif
  36.  
  37. class  DoubleList  :  public BaseList  {
  38.   protected:
  39.     struct DoubleLink  {
  40.     DoubleLink    *Next;
  41.     DoubleLink    *Prev;
  42.     Entry           *entry;
  43.     };
  44.  
  45.     DoubleLink    *First, *Last, *Current;
  46.     int compare(void *item1, void *item2)
  47.     { return strcmp((const char *) item1, (const char *) item2); }
  48.  
  49.   public:
  50.     DoubleList(void)
  51.     { First = Last = Current = NULL; }    // constructor
  52.  
  53.     ~DoubleList(void);                    // destructor
  54.  
  55.     const void *get_ptr(void)
  56.     { return (Current != NULL) ?
  57.         (const void *)Current->entry->item : 
  58.         lerror = EMPTY_LIST, (const void *)NULL; }
  59.  
  60.     size_t get_size(void)
  61.     { return (Current != NULL) ?
  62.         Current->entry->itemsize : lerror = EMPTY_LIST, 0; }
  63.  
  64.     Boolean add_item(void *item, size_t itemsize, Place place = LastPlace);
  65.     Boolean delete_item(void);
  66.     Boolean get_item(void *itembuf);
  67.     Boolean remove_item(void *itembuf)
  68.     {
  69.       if(! get_item(itembuf))
  70.         return False;
  71.  
  72.       return delete_item();
  73.     }
  74.  
  75.     int compare_item(void *item1);
  76.     Boolean find_item(void *item1);
  77.     Boolean replace_item(void *newitem, size_t newsize);
  78.  
  79.     Boolean first(void)
  80.     { return (Current = First) ? True : lerror = EMPTY_LIST, False; }
  81.     Boolean last(void)
  82.     { return (Current = Last) ? True : lerror = EMPTY_LIST, False; }
  83.     Boolean next(void)
  84.     { return (Current != Last) ?
  85.         Current = Current->Next, True : False; }
  86.     Boolean prev(void)
  87.     { return (Current != First) ?
  88.         Current = Current->Prev, True : False; }
  89.         
  90.     Boolean sort(void);
  91.     
  92.  
  93. };  // class DoubleList
  94.  
  95.  
  96. class CircularDoubleList  :  public DoubleList  {
  97.   public:
  98.     Boolean next(void)
  99.     { return (DoubleList::next()) ? True : first(); }
  100.     Boolean prev(void)
  101.     { return (DoubleList::prev()) ? True : last(); }
  102. };
  103.  
  104. #endif
  105.