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

  1. /*
  2.     TITLE:        BASELIST;
  3.     DESCRIPTION:    C++ Virtual Base Class for Linked List
  4.             Classes;
  5.  
  6.     FILENAME:    BASELIST.HPP;
  7.     VERSION:    1.0;
  8.     DATE:           9/21/90;
  9.     COMPILER:    BORLAND TURBO C++ V.1.0;
  10.  
  11.     AUTHOR:        Michael Kelly
  12.             254 Gold Street
  13.             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. #if !defined(BASELIST_HPP)
  26. #define BASELIST_HPP
  27.  
  28. #include <stdio.h>
  29. #include <stddef.h>
  30.  
  31.  //  global List error indicator (like errno)
  32.  
  33. typedef enum Lerror  {
  34.     OK,                 // no error
  35.     NO_MEM,             // not enough memory
  36.     NULL_PTR,           // NULL pointer - (usually a function argument)
  37.     EMPTY_LIST,         // empty List
  38.     INV_SIZE,           // invalid size - (usually itemsize == 0)
  39.     INV_OP        // invalid operation - (inappropriate method)
  40. } Lerror;
  41.  
  42. extern Lerror lerror;
  43.  
  44. typedef enum Boolean  {
  45.     False, True } Boolean;
  46.  
  47. typedef enum Place  {
  48.     FirstPlace, LastPlace, AfterCurrentPlace } Place;
  49.  
  50.  
  51.   //     ----------------< BaseList Class Definition >----------------
  52.  
  53.         //  Abstract Class for Linked List Type Classes
  54.  
  55. class BaseList  {
  56.   protected:
  57.     struct Entry  {
  58.     size_t itemsize;
  59.     void   *item;
  60.     };
  61.  
  62.     size_t entries;
  63.     Lerror lerror;
  64.     virtual int compare(void *item1, void *item2) = 0;
  65.   public:
  66.     BaseList(void)                      // constructor
  67.     { entries = 0; lerror = OK; }
  68.  
  69.     virtual ~BaseList(void) {}
  70.  
  71.   friend int qcompare(const void *entry1, const void *entry2);
  72.  
  73.     size_t get_entries(void)
  74.     { return entries; }
  75.     Lerror error(void)
  76.     { return lerror; }
  77.  
  78.     virtual const void *get_ptr(void) = 0;
  79.     virtual size_t get_size(void) = 0;
  80.     virtual Boolean
  81.     add_item(void *item, size_t itemsize, Place place = LastPlace) = 0;
  82.     virtual Boolean delete_item(void) = 0;
  83.     virtual Boolean get_item(void *itembuf) = 0;
  84.     virtual Boolean remove_item(void *itembuf) = 0;
  85.     virtual int compare_item(void *item1) = 0;
  86.     virtual Boolean find_item(void *item1) = 0;
  87.     virtual Boolean replace_item(void *newitem, size_t newsize) = 0;
  88.  
  89.     virtual Boolean first(void) = 0;
  90.     virtual Boolean last(void)     = 0;
  91.     virtual Boolean next(void)     = 0;
  92.     virtual Boolean prev(void)     = 0;
  93.     virtual Boolean sort(void)     = 0;
  94. };
  95.  
  96. extern BaseList *this_list;
  97.  
  98. #endif
  99.