home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / VirtualFile / VirtualRamOrDiskFile.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  2.7 KB  |  94 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        VirtualRamOrDiskFile.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __VIRTUALRAMORDISKFILE__
  15. #define __VIRTUALRAMORDISKFILE__
  16.  
  17. #ifndef __VIRTUALFILE__
  18. #include "VirtualFile.h"
  19. #endif
  20.  
  21. #ifndef __IOSTREAM__
  22. #include <iostream.h>
  23. #endif
  24.  
  25. #pragma push
  26. #pragma segment VirtualFile
  27.  
  28. /***********************************|****************************************/
  29.  
  30. class TVirtualRamOrDiskFile : public TVirtualFile
  31. {
  32. public:
  33.  
  34.     enum Location { kMemory, kDisk };
  35.  
  36.             TVirtualRamOrDiskFile ( Location = kMemory );
  37.             TVirtualRamOrDiskFile ( Location l, unsigned long ramToDiskThreshold );
  38.     virtual ~TVirtualRamOrDiskFile();
  39.  
  40.     virtual Location                 GetLocation () const;
  41.     virtual OSErr                     ForceToDisk();
  42.     virtual OSErr                     ForceToMemory();
  43.  
  44.     virtual unsigned long             GetMaxMemSize() const;
  45.     virtual OSErr                     SetMaxMemSize(unsigned long maxSize);
  46.  
  47.     virtual OSErr                     ReadData (void* buffer,long& count);
  48.     virtual OSErr                     WriteData (const void* buffer, long& count);
  49.  
  50.     virtual OSErr                     SetEnd (long logEof);
  51.     virtual OSErr                     GetEnd (long& logEof) const;
  52.  
  53.     virtual OSErr                     SetPosition (short posMode, long posOff);
  54.     virtual OSErr                     GetPosition (long& filePos) const;
  55.         
  56.     static void                     SetDefaultStorageLocation ( const FSSpec& );
  57.     static void                     GetDefaultStorageLocation ( FSSpec& );
  58.  
  59.     static unsigned long            GetVirtualRamOrDiskFilesCount();
  60.     static unsigned long            GetVirtualRamOrDiskFilesSize();
  61.     static void                     ForceFreeMemory (unsigned long freespace );
  62.  
  63.     
  64.     
  65.     virtual ostream&                 operator >> ( ostream& ) const;
  66.  
  67. private:    TVirtualRamOrDiskFile ( const TVirtualRamOrDiskFile& );
  68.             TVirtualRamOrDiskFile&    operator = ( const TVirtualRamOrDiskFile& );
  69.  
  70.     virtual    OSErr                    ForceTo ( Location, TAbstractFile* );
  71.     virtual    TAbstractFile*             CreateDiskFile ();
  72.     
  73.     static    void                     UniqueFileName( StringPtr );
  74.     static    FSSpec                    gDefaultStorageLocation;
  75.     
  76.             TAbstractFile*            fFile;
  77.             Location                fLocation;
  78.             unsigned long            fRamLimit;
  79.             long                    fLength;
  80. };
  81.  
  82. /***********************************|****************************************/
  83.  
  84. inline TVirtualRamOrDiskFile::Location TVirtualRamOrDiskFile::GetLocation () const { return fLocation; }
  85. inline unsigned long TVirtualRamOrDiskFile::GetMaxMemSize() const { return fRamLimit; }
  86. inline void TVirtualRamOrDiskFile::SetDefaultStorageLocation ( const FSSpec& location ) { gDefaultStorageLocation = location; }
  87. inline void TVirtualRamOrDiskFile::GetDefaultStorageLocation ( FSSpec& location ) { location = gDefaultStorageLocation; }
  88.  
  89. /***********************************|****************************************/
  90.  
  91. #pragma pop
  92.  
  93. #endif    // __VIRTUALRAMORDISKFILE__
  94.