home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 6.ddi / MWHC.006 / 51 < prev    next >
Encoding:
Text File  |  1992-06-07  |  3.1 KB  |  98 lines

  1. #ifndef __RWFILEMGR_H__
  2. #define __RWFILEMGR_H__
  3. pragma push_align_members(64);
  4.  
  5. /*
  6.  * RWFileManager --- manages free space in a file
  7.  *
  8.  * $Header:   E:/vcs/rw/filemgr.h_v   1.2   18 Feb 1992 09:54:20   KEFFER  $
  9.  *
  10.  ****************************************************************************
  11.  *
  12.  * Rogue Wave 
  13.  * P.O. Box 2328
  14.  * Corvallis, OR 97339
  15.  * Voice: (503) 754-3010    FAX: (503) 757-6650
  16.  *
  17.  * Copyright (C) 1989, 1990, 1991. This software is subject to copyright 
  18.  * protection under the laws of the United States and other countries.
  19.  *
  20.  ***************************************************************************
  21.  *
  22.  * $Log:   E:/vcs/rw/filemgr.h_v  $
  23.  * 
  24.  *    Rev 1.2   18 Feb 1992 09:54:20   KEFFER
  25.  * 
  26.  *    Rev 1.1   28 Oct 1991 09:08:14   keffer
  27.  * Changed inclusions to <rw/xxx.h>
  28.  * 
  29.  *    Rev 1.0   28 Jul 1991 08:15:00   keffer
  30.  * Tools.h++ V4.0.5 PVCS baseline version
  31.  *
  32.  */
  33.  
  34. #include "rw/rwfile.h"
  35. #include "rw/tooldefs.h"
  36.  
  37. #ifdef RDEBUG
  38. const         int         freeListArraySize = 2;
  39. #else
  40. const         int         freeListArraySize = 10;
  41. #endif
  42.  
  43. class RWExport RWFileManager;
  44. class RWfreeListData {
  45. friend RWFileManager;
  46.   unsigned short    magicNumber;
  47.   RWoffset        freeSpaceOffset    [freeListArraySize];
  48.   RWspace        freeSpaceSize    [freeListArraySize];
  49.   int            entries;     // Number of free spaces entries.
  50.   RWoffset        next;        // Next block of free space data.
  51.  
  52.   RWBoolean        addFreeSpace(RWoffset, RWspace);
  53.   RWoffset        allocate(RWspace);
  54.   void            attemptMerge(int);
  55.   RWBoolean        coalesce(RWoffset, RWspace);
  56.   RWBoolean        enterFreeSpace(RWoffset, RWspace);
  57.   void            initialize(RWoffset);
  58.   void            slideRight(int);
  59.   void            slideLeft(int);
  60. };  
  61.  
  62. class RWExport RWFileManager : public RWFile {
  63. private:
  64.   RWfreeListData    freeList;    // Free list block in memory.
  65.   RWoffset        startOfData;    // Offset to first data in file.
  66.   RWoffset        endOfData;    // Offset to last data in file.
  67.   RWoffset        here;        // Location of freeList on disk.
  68.   RWFileManager(const RWFileManager&);    // Cannot have 2 managers for the same file.
  69.   void            operator=(const RWFileManager&);
  70. public:
  71.   RWFileManager(const char* filename);
  72.  
  73.   RWoffset        start()   const     {return startOfData;}
  74.   RWoffset        endData() const  {return endOfData;} 
  75.   RWoffset        allocate(RWspace);      // Allocate storage 
  76.   void            deallocate(RWoffset);    // Deallocate storage.
  77. #ifdef RDEBUG
  78.   void            summarize();
  79. #endif
  80.  
  81. private:
  82.   void            addFreeList(RWoffset, RWspace);
  83.   void            addToFreeList(RWoffset, RWspace);
  84.   RWoffset        allocateAtEnd(RWspace);
  85.   RWoffset        allocateInFreeList(RWspace);
  86.   RWBoolean        checkForEnd(RWoffset, RWspace); 
  87.   void            deleteFreeList();      
  88.   void            fileMgrErr(RWErrNo);        // Error handler.
  89.   RWBoolean        isRootFreeList() const;        // Root free list block?
  90.   RWBoolean        onlyRootFreeList() const;    // Is root free list block only block?
  91.   RWBoolean        readFreeList(RWoffset);        // Read free list block from location
  92.   RWBoolean        writeFreeList();        // Write free list block to disk
  93.   RWBoolean        writeFreeList(RWoffset);    // Write free list block to disk
  94. };
  95.  
  96. pragma pop_align_members();
  97. #endif /* __RWFILEMGR_H__ */
  98.