home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWFiles / Include / FWFilRep.h < prev   
Encoding:
Text File  |  1995-11-08  |  7.0 KB  |  248 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFilRep.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWFILREP_H
  11. #define FWFILREP_H
  12.  
  13. #ifndef FWEXCDEF_H
  14. #include "FWExcDef.h"
  15. #endif
  16.  
  17. #ifndef FWCOUPTR_H
  18. #include "FWCouPtr.h"
  19. #endif
  20.  
  21. #ifndef FWFILE_H
  22. #include "FWFileSy.h"
  23. #endif
  24.  
  25. #ifndef FWFILESP_H
  26. #include "FWFileSp.h"
  27. #endif
  28.  
  29. #ifndef FWACCBUF_H
  30. #include "FWAccBuf.h"
  31. #endif
  32.  
  33. #if defined(FW_BUILD_WIN) && !defined(__WINDOWS_H)
  34. #include <windows.h>
  35. #endif
  36.  
  37. #if FW_LIB_EXPORT_PRAGMAS
  38. #pragma lib_export on
  39. #endif
  40.  
  41. //========================================================================================
  42. //    FW_CFileRep
  43. //
  44. //    Class holding representation for FW_CFileSink.  This is an implementation class 
  45. //    and should not be used in general.  Use the FW_CFileSink class instead.
  46. //========================================================================================
  47.  
  48. class FW_CLASS_ATTR FW_CFileRep : public FW_CCountedPtrRep
  49. {
  50.  
  51. public:
  52.  
  53.     enum
  54.     {
  55.         kDefaultBufferCapacity = 1024
  56.     };
  57.  
  58.     FW_CFileRep(const FW_CFileSpecification& fileSpecification,
  59.                 long bufferSize = kDefaultBufferCapacity,
  60.                 FW_Boolean allowCreate = FALSE);
  61.         // Open with exclusive access 
  62.  
  63.     FW_CFileRep(const FW_CFileSpecification& fileSpecification,
  64.                 const FW_CAccessPermission& permission,
  65.                 long bufferSize = kDefaultBufferCapacity,
  66.                 FW_Boolean allowCreate = FALSE);
  67.         // Open with specified permissions.
  68.         
  69.     virtual ~ FW_CFileRep();
  70.         // Close the file.
  71.  
  72.  
  73.     //===========================================================
  74.     // Read/Write
  75.     //===========================================================
  76.  
  77.     void Read(void * destination, long count);
  78.         // Read 'count' bytes from current position to 'destination' and 
  79.         // increment current position by 'count'.
  80.         
  81.     const void* ReadPeek(long& availableReadBytes);
  82.         // Return read-only pointer to 'availableReadBytes' bytes of data
  83.         // at current file position.
  84.         
  85.     void ReadPeekAdvance(long bytesRead);
  86.         // Advance position in ReadPeek() buffer by 'bytesRead' bytes.
  87.     
  88.     void Write(const void* source, long count);
  89.         // Write 'count' bytes from 'source' to current file position.
  90.         
  91.     void* WritePeek(long& availableWriteBytes);
  92.         // Return write-only pointer to 'availableWriteBytes' bytes of data
  93.         // at current file position. 
  94.         
  95.     void WritePeekAdvance(long bytesWritten);
  96.         // Advance position in WritePeek() buffer by 'bytesWritten' bytes.
  97.  
  98.  
  99.     //===========================================================
  100.     // File Positioning
  101.     //===========================================================
  102.         
  103.     long GetLength() const;
  104.         // Return the logical size of the file.
  105.                                     
  106.     void SetLength(long length);
  107.         // Return the logical size of the file.
  108.  
  109.     long GetPosition() const;
  110.         // Return current file position.
  111.         
  112.     void SetPosition(FW_CFileSystem::MoveMethods positioningMode,
  113.                              long markOffset);
  114.         // Set current file position using mode.
  115.         
  116.     long BytesToEndOfFile() const;
  117.         // Returns the number of bytes from the current position to the
  118.         //   end of the file.
  119.         
  120.  
  121.     //===========================================================
  122.     // Accessor methods
  123.     //===========================================================
  124.  
  125.     void GetPermissions(FW_CAccessPermission& thePerms) const;
  126.         // Returns the permissions used to open this file.
  127.  
  128.     FW_CFileSpecification GetFileSpecification() const;
  129.         // Returns a reference to the file.  This routine is primarily used for 
  130.         //   exception handling.
  131.  
  132.     FW_FileAccessHandle GetFileHandle() const;
  133.         // Returns the native platform handle to the file.
  134.         
  135.  
  136.     //===========================================================
  137.     // Operators
  138.     //===========================================================
  139.  
  140.     FW_Boolean operator==(const FW_CFileRep& theOtherFile) const;
  141.         // Equality operator.
  142.  
  143.     FW_Boolean operator!=(const FW_CFileRep& theOtherFile) const;
  144.         // Inequality operator.
  145.  
  146.  
  147. private:    
  148.     void PrivOpenFile(FW_Boolean allowCreate);
  149.         // Open the file and prepare it for access.
  150.  
  151.     void PrivCloseFile();
  152.         // Close the file and clear all references to it.
  153.  
  154.     void PrivDoRead(void * destination, long count);
  155.         // Perform the actual reading of data.
  156.             
  157.     void PrivDoWrite(const void* source, long count);
  158.         // Perform the actual writing of data.
  159.         
  160.     void FlushAndInvalidateBuffer();
  161.         // Write pending "WritePeek" buffer if any.
  162.         // Invalidate active "WritePeek" or "ReadPeek" buffer.
  163.         
  164.     FW_CFileRep(const FW_CFileRep& otherAccess);
  165.     FW_CFileRep& operator=(const FW_CFileRep& theOtherFile);
  166.         // Copy constructor and assignment operator not valid for this class.
  167.  
  168.     FW_CFileSpecification        fFileSpec;
  169.     FW_CAccessPermission        fPermission;
  170.     FW_FileAccessHandle            fFileHandle;
  171.     FW_CPrivFileAccessBuffer    fFileBuffer;
  172.  
  173. #ifdef FW_BUILD_WIN
  174. private:
  175.     FW_CFileSystem::FileError PrivWinMoveFilePointer(long Offset,
  176.                                                      FW_CFileSystem::MoveMethods theMoveMethod,
  177.                                                      long& newPosition) const;
  178.                                                     
  179.     static short PrivWinGetIOBufferSize(long bytesDesired,
  180.                                        const void* buffer);
  181.                                        
  182.     static FW_CFileSystem::FileError PrivWinPrimitiveRead(FW_FileAccessHandle handle,
  183.                                                          short bytesToRead,
  184.                                                          void* buffer,
  185.                                                          short& bytesActuallyRead);
  186.     static FW_CFileSystem::FileError PrivWinPrimitiveWrite(FW_FileAccessHandle handle,
  187.                                                          short bytesToWrite,
  188.                                                          const void* buffer,
  189.                                                          short& bytesActuallyWritten);
  190. #endif
  191. };
  192.  
  193. //========================================================================================
  194. // CLASS FW_PFile
  195. //========================================================================================
  196.  
  197. class FW_CLASS_ATTR FW_PFile : public FW_CCountedPtr
  198. {
  199. public:
  200.     virtual ~ FW_PFile();
  201.  
  202.     enum
  203.     {
  204.         kDefaultBufferCapacity = FW_CFileRep::kDefaultBufferCapacity
  205.     };
  206.  
  207.     FW_PFile(FW_CFileRep* privFileAccessRep);
  208.         
  209.     FW_PFile(const FW_CFileSpecification& fileSpecification,
  210.              long bufferSize = kDefaultBufferCapacity,
  211.              FW_Boolean allowCreate = FALSE);
  212.         // Open with exclusive access 
  213.  
  214.     FW_PFile(const FW_CFileSpecification& fileSpecification,
  215.              const FW_CAccessPermission& permission,
  216.              long bufferSize = kDefaultBufferCapacity,
  217.              FW_Boolean allowCreate = FALSE);
  218.         // Open with specified permissions.
  219.         
  220.     // ----- Overload of accessors methods -----
  221.     FW_CFileRep* operator->() const;
  222.     FW_CFileRep& operator*() const;    
  223. };
  224.         
  225. //----------------------------------------------------------------------------------------
  226. // FW_PFile::operator->
  227. //----------------------------------------------------------------------------------------
  228.  
  229. inline FW_CFileRep* FW_PFile::operator->() const
  230. {
  231.     return (FW_CFileRep*)fRep;
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. // FW_PFile::operator*
  236. //----------------------------------------------------------------------------------------
  237.  
  238. inline FW_CFileRep& FW_PFile::operator*() const
  239. {
  240.     return *((FW_CFileRep*)fRep);
  241. }
  242.  
  243. #if FW_LIB_EXPORT_PRAGMAS
  244. #pragma lib_export off
  245. #endif
  246.  
  247. #endif
  248.