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 / FWFileSp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  7.9 KB  |  252 lines  |  [TEXT/MPS ]

  1. #if !defined(FWFILESP_H) && !defined(__ODFRC__)
  2. #define FWFILESP_H
  3. //========================================================================================
  4. //
  5. //    File:        FWFileSp.h
  6. //    Release Version:    $ 1.0d11 $
  7. //
  8. //    Copyright:    1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWEXCDEF_H
  13. #include "FWExcDef.h"
  14. #endif
  15.  
  16. #ifndef FWSTRS_H
  17. #include "FWStrs.h"  
  18. #endif
  19.  
  20. #if defined(FW_BUILD_MAC) && !defined(__FILES__)
  21. #include <Files.h>
  22. #endif
  23.  
  24. #if FW_LIB_EXPORT_PRAGMAS
  25. #pragma lib_export on
  26. #endif
  27.  
  28. //========================================================================================
  29. // Forward class declarations
  30. //========================================================================================
  31. class FW_CLASS_ATTR FW_CDirectorySpecification;
  32.  
  33.  
  34. //========================================================================================
  35. //    FW_CFileSpecification
  36. //
  37. //    This class is used to identify a disk-based file.  
  38. //========================================================================================
  39.  
  40. class FW_CLASS_ATTR FW_CFileSpecification FW_AUTO_DESTRUCT_OBJECT
  41. {
  42. public:
  43.     FW_CFileSpecification(const FW_CDirectorySpecification& directory,
  44.                           const FW_CString& fileName);
  45.         // Create a file specification from a directory and a file name.  The file name
  46.         //   should include any extensions that might be necessary.
  47.         
  48.     FW_CFileSpecification(const FW_CString& fileName);
  49.         // Create a file specification from a full or partial pathname.  In the case of
  50.         //   a partial pathname, the specification will use the current default
  51.         //   directory to build a full pathname.
  52.  
  53.     FW_CFileSpecification(const FW_CFileSpecification& specification);
  54.         // Copy Constructor
  55.         
  56.     ~ FW_CFileSpecification();
  57.     
  58.  
  59.     void GetName(FW_CString& fileName) const;
  60.         // Get the name of the file.
  61.  
  62.     FW_CDirectorySpecification GetParentDirectory() const;
  63.         // Returns the path information for this file.
  64.  
  65.     void GetFullPath(FW_CString& fullPathName) const;
  66.         // Returns the fully qualified path and file name for this file.  The user should
  67.         //   pass in a dynamic string so as to guarantee that the path will fit inside
  68.         //   it.
  69.         
  70.  
  71.     //===========================================================
  72.     // Operators
  73.     //===========================================================
  74.     
  75.     FW_Boolean operator==(const FW_CFileSpecification& theOtherFile) const;
  76.         // Does this file represent the same file as theOtherFile.
  77.         
  78.     FW_Boolean operator!=(const FW_CFileSpecification& theOtherFile) const;
  79.         // Does this file not represent the same file as theOtherFile
  80.         
  81.         
  82.     FW_CFileSpecification& operator=(const FW_CFileSpecification& theOtherFile);
  83.         // Copy all of the file information from theOtherFile so that this file spec
  84.         //   represents the same file.
  85.  
  86.     FW_CFileSpecification& operator=(const FW_CString& fileName);
  87.         // Change the name of this file to fileName.  fileName may be a partial pathName.
  88.         // This does not change any of the existing path information.
  89.  
  90.  
  91. private:
  92.     void ThrowError(short theError) const;
  93.         // Throw the exception based on the error code.
  94.         
  95.     void FailOnError(short theError) const;
  96.         // Used to check error conditions from this class.
  97.  
  98. #ifdef FW_BUILD_WIN
  99. public:
  100.     FW_Char WinGetDrive() const;
  101.         // Get the letter of the drive this file is on and return it as a lower-case
  102.         //   character.  
  103.         
  104.     void WinGetExtension(FW_CString& extension) const;
  105.         // Get the file name extension for the Windows file.
  106.         
  107.     void WinSetExtension(const FW_CString& extension);
  108.         // Set the file name extension for the Windows file.
  109.         
  110. private:
  111.     FW_CDynamicString fFileInfo;
  112.     
  113. #endif
  114.  
  115. #ifdef FW_BUILD_MAC
  116. public:
  117.     FW_CFileSpecification(const FSSpec& specification);
  118.         // Create a file specification based on a Macintosh FSSpec.
  119.     
  120.     FW_CFileSpecification& operator=(const FSSpec& macSpec);
  121.         // This specifier will now represent the file described by macSpec.
  122.     
  123.     void MacGetFSSpec(FSSpec& macSpec) const;
  124.         // Return a Macintosh FSSpec that points to this file.
  125.  
  126.     void MacSetTypeAndCreator(OSType aFileType, OSType aCreatorType);
  127.     void MacGetTypeAndCreator(OSType &aFileType, OSType &aCreatorType) const;
  128.         // Accesors to the type and creator of the file specification.
  129.  
  130. private:
  131.     FSSpec fFileInfo;
  132.     OSType fFileType;
  133.     OSType fCreatorType;
  134. #endif 
  135.  
  136. };
  137.  
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    FW_CFileSpecification::operator!=
  141. //----------------------------------------------------------------------------------------
  142.  
  143. inline FW_Boolean FW_CFileSpecification::operator!=(const FW_CFileSpecification& theOtherFile) const
  144. {
  145.     return (!(FW_CFileSpecification::operator==(theOtherFile)));
  146. }
  147.  
  148.  
  149.  
  150. //========================================================================================
  151. //    FW_CDirectorySpecification
  152. //
  153. //    This class is used to indentify a disk-based directory. A directory uses most of the
  154. //    same information as a file specification, but is not a file.
  155. //========================================================================================
  156. class FW_CLASS_ATTR FW_CDirectorySpecification FW_AUTO_DESTRUCT_OBJECT
  157. {
  158. public:
  159.     friend FW_CFileSpecification;
  160.     
  161.     FW_CDirectorySpecification();
  162.         // Specifies the current default directory
  163.         
  164.     FW_CDirectorySpecification(const FW_CDirectorySpecification& specification);
  165.         // Copy constructor
  166.         
  167.     FW_CDirectorySpecification(const FW_CString& directoryName);
  168.         // Specifies the path by string.  directoryName can be either a full or 
  169.         //   partial path name.
  170.         
  171.     ~ FW_CDirectorySpecification();
  172.     
  173.     
  174.     void GetName(FW_CString& directoryName) const;
  175.         // Returns the name of the directory.
  176.     
  177.     FW_CDirectorySpecification GetParentDirectory() const;
  178.         // Returns the parent directory of this directory.
  179.  
  180.     void GetFullPath(FW_CString& fullPath) const;
  181.         // Returns the fully qualified path and name for this directory.  The user should
  182.         //   pass in a dynamic string so as to guarantee that the path will fit inside
  183.         //   it.
  184.         
  185.  
  186.     //===========================================================
  187.     // Operators
  188.     //===========================================================
  189.  
  190.     FW_Boolean operator==(const FW_CDirectorySpecification& theOtherDir) const;
  191.         // Equality operator.
  192.     
  193.     FW_Boolean operator!=(const FW_CDirectorySpecification& theOtherDir) const;
  194.         // Ineqaulity operator.
  195.     
  196.     FW_CDirectorySpecification& operator=(const FW_CDirectorySpecification& theOtherDir);
  197.         // Assignment operator
  198.     
  199.     FW_CDirectorySpecification& operator=(const FW_CString& directoryName);
  200.         // Change the directory name to directoryName.  directoryName may be a partial
  201.         //   path name.
  202.         
  203.     FW_CDirectorySpecification& operator+=(const FW_CString& directoryName);
  204.         // Add directoryName to the end of this path.  This routine will add a path
  205.         //   separator so that the user does not need to.  The remaining path information
  206.         //   may specify a subdirectory or parent directory, but must start from this
  207.         //   directory.
  208.         
  209. #ifdef FW_BUILD_WIN
  210. public:
  211.     FW_Char WinGetDrive() const;
  212.         // Get the letter of the drive this file is on and return it as a lower-case
  213.         //   character.  
  214.  
  215. #endif
  216.  
  217.  
  218. #ifdef FW_BUILD_MAC
  219. public:
  220.     FW_CDirectorySpecification(const FSSpec& macSpec);
  221.         // Create a directory spec from a Macintosh FSSpec.
  222.         
  223.     FW_CDirectorySpecification& operator=(const FSSpec& macSpec);
  224.         // Assignment operator for a Macintosh spec.
  225.         
  226.     void MacGetFSSpec(FSSpec& specification) const;
  227.         // Fill in specification with the information about this directory.
  228.  
  229. #endif
  230.  
  231. private:
  232.     FW_CFileSpecification fFileSpec;
  233.  
  234. };
  235.  
  236.  
  237. //----------------------------------------------------------------------------------------
  238. //    FW_CDirectorySpecification::operator!=
  239. //----------------------------------------------------------------------------------------
  240. inline FW_Boolean FW_CDirectorySpecification::operator!=(const FW_CDirectorySpecification& theOtherDir) const
  241. {
  242.     return (fFileSpec != theOtherDir.fFileSpec);
  243. }
  244.  
  245. #if FW_LIB_EXPORT_PRAGMAS
  246. #pragma lib_export off
  247. #endif
  248.  
  249. #endif
  250.  
  251.  
  252.