home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / hl10osrc.lzh / Include / ListRecord.h < prev    next >
Text File  |  1994-04-23  |  2KB  |  57 lines

  1. /* -*- Mode: C -*- */
  2. /* ListRecord.h - A record as a list
  3.  * Created by Robert Heller on Fri Dec  6 20:25:42 1991
  4.  *
  5.  * ------------------------------------------------------------------
  6.  * Home Libarian by Deepwoods Software
  7.  * Common Header Files
  8.  * ------------------------------------------------------------------
  9.  * Modification History:
  10.  * ------------------------------------------------------------------
  11.  * Contents:
  12.  * ------------------------------------------------------------------
  13.  * 
  14.  * 
  15.  * Copyright (c) 1991,1992 by Robert heller (D/B/A Deepwoods Software)
  16.  *        All Rights Reserved
  17.  * 
  18.  */
  19. #ifndef _LRECORD_
  20. #define _LRECORD_
  21. #include <common.h>
  22.  
  23. // This class maps between the list on disk (as a record) and the list
  24. // in memory (as a vector).
  25. // RawData is the disk record.  elems is the vector in memory.
  26. // numelts is the number of elements
  27. // dummy is returned for out of bounds references
  28. class ListRecord {
  29.     Record RawData;
  30.     int numelts;
  31.     char** elems;
  32.     static char* dummy;
  33.     void UpdateRecord();    // make a record from a vector
  34. public:
  35.     // Constructors and type conversions:
  36.           ListRecord(Record* record);    // a ListRecord from a Record
  37.           ListRecord(CoreItem* coreitem);    // a ListRecord from a CoreItem
  38.           ListRecord(int numitems,char* inelems[]);    // a ListRecord from a vector
  39.     // descructor.  clean things up
  40.          ~ListRecord() { RawData.NewBuffer(0); delete elems; }
  41.     // Index operator
  42.     char*& operator [] (int index)
  43.             { if (index >= 0 && index < numelts)
  44.                    return elems[index];
  45.               else return dummy;}
  46.     // Convert a ListRecord to a plain Record
  47.     operator Record ()
  48.         {
  49.             UpdateRecord();
  50.             Record record = RawData;
  51.             return record;
  52.         }
  53.     // Return number of elements
  54.     int ElementCount ()        { return numelts; }
  55. };
  56. #endif
  57.