home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / hl10osrc.zoo / Include / LList.h < prev    next >
Text File  |  2009-11-06  |  2KB  |  61 lines

  1. /* -*- Mode: C -*- */
  2. /* LList.h - Line List interface defination
  3.  * Created by Robert Heller on Tue Mar 24 19:15:50 1992
  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.  
  20. #ifndef _LLIST_
  21. #define _LLIST_
  22. #include <common.h>        // common defs
  23.  
  24. // LineList class.  This class is a linked-list of lines of text.
  25. // To avoid pounding on the simple heap memory management,  LineLists are
  26. // allocated 100 at a time (upto a max of 100,000 LineListss), and "old"
  27. // LineListss are reused, rather than returned to the general heap.
  28.  
  29. const LineLength = 128;        // max length of a line
  30.  
  31. class LineList {
  32.     const blocksize = 100;    // number of LineListss to allocate at a time
  33.     const maxblocks = 1000;    // maximum number blocks to allocate
  34.     static int numblocks;    // current number of allocated blocks
  35.     static LineList* blocks[maxblocks]; // allocated LineLists
  36.     static LineList* freelist;    // linked list of available LineLists
  37.     void   moreblocks();    // internal function to get another block of LineLists
  38. public:
  39.     char thisline[LineLength];    // current line
  40.     LineList* nextline;        // next line
  41.     LineList* prevline;        // prev line
  42.           LineList()        // New blank LineList
  43.         {LineList("",(LineList*) 0,(LineList*) 0);}
  44.                 // New initialized LineList
  45.           LineList(char* line) {LineList(line,(LineList*)0,(LineList*)0);}
  46.           LineList(char* line,LineList* next,LineList* prev)
  47.             {
  48.                 strncpy(thisline,line,LineLength);
  49.                 thisline[LineLength-1] = 0;
  50.                 nextline = next;
  51.                 prevline = prev;
  52.                 if (next != (LineList*) 0) next->prevline = this;
  53.                 if (prev != (LineList*) 0) prev->nextline = this;
  54.             }
  55.     void* operator new (long bytes);    // dyn. allocated LineList
  56.     void  operator delete  (void* ptr);    // free a dyn. allocated LineList
  57. };
  58. extern void FreeLineList(LineList* l);
  59. #endif
  60.  
  61.