Back to index

lightning-sunbird  0.9+nobinonly
GUSIFileSpec.h
Go to the documentation of this file.
00001 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
00002 // % Project  :      GUSI                        -      Grand Unified Socket Interface                    
00003 // % File            :      GUSIFileSpec.nw             -      File specifications                        
00004 // % Author   :      Matthias Neeracher                                           
00005 // % Language :      C++                                                        
00006 // %                                                                       
00007 // % $Log: GUSIFileSpec.h,v $
00008 // % Revision 1.2  2001/12/23 23:23:41  timeless%mac.com
00009 // % Bugzilla Bug 106386 rid source of these misspellings: persistant persistance priviledge protocal editting editted targetted targetting
00010 // % r='s from many people. sr=jst
00011 // %
00012 // % Revision 1.1  2001/03/11 22:35:07  sgehani%netscape.com
00013 // % First Checked In.
00014 // %                                             
00015 // % Revision 1.15  2001/01/17 08:46:45  neeri                             
00016 // % Get rid of excess directory separators when name is empty             
00017 // %                                                                       
00018 // % Revision 1.14  2000/12/23 06:10:17  neeri                             
00019 // % Add GUSIFSpTouchFolder, GUSIFSpGetCatInfo; copy error in copy constructor
00020 // %                                                                       
00021 // % Revision 1.13  2000/10/16 03:59:36  neeri                             
00022 // % Make FSSpec a member of GUSIFileSpec instead of a base class          
00023 // %                                                                       
00024 // % Revision 1.12  2000/06/12 04:20:58  neeri                             
00025 // % Introduce GUSI_*printf                                                
00026 // %                                                                       
00027 // % Revision 1.11  2000/05/23 07:00:00  neeri                             
00028 // % Improve formatting                                                    
00029 // %                                                                       
00030 // % Revision 1.10  2000/03/15 07:16:08  neeri                             
00031 // % Fix path construction, temp name bugs                                 
00032 // %                                                                       
00033 // % Revision 1.9  2000/03/06 06:34:11  neeri                              
00034 // % Added C FSSpec convenience calls                                      
00035 // %                                                                       
00036 // % Revision 1.8  1999/08/26 05:45:02  neeri                              
00037 // % Fixes for literate edition of source code                             
00038 // %                                                                       
00039 // % Revision 1.7  1999/07/19 06:21:02  neeri                              
00040 // % Add mkdir/rmdir, fix various file manager related bugs                
00041 // %                                                                       
00042 // % Revision 1.6  1999/06/28 06:00:53  neeri                              
00043 // % add support for generating temp names from basename                   
00044 // %                                                                       
00045 // % Revision 1.5  1999/05/30 02:16:53  neeri                              
00046 // % Cleaner definition of GUSICatInfo                                     
00047 // %                                                                       
00048 // % Revision 1.4  1999/03/17 09:05:07  neeri                              
00049 // % Added GUSITimer, expanded docs                                        
00050 // %                                                                       
00051 // % Revision 1.3  1998/10/11 16:45:15  neeri                              
00052 // % Ready to release 2.0a2                                                
00053 // %                                                                       
00054 // % Revision 1.2  1998/08/01 21:32:04  neeri                              
00055 // % About ready for 2.0a1                                                 
00056 // %                                                                       
00057 // % Revision 1.1  1998/01/25 21:02:46  neeri                              
00058 // % Engine implemented, except for signals & scheduling                   
00059 // %                                                                       
00060 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
00061 //                                                                         
00062 // \chapter{File specifications}                                           
00063 //                                                                         
00064 // While the Macintosh toolbox has a convenient type [[FSSpec]] to pass to 
00065 // file system routines, it lacks manipulation functions. We provide them here.
00066 // This module has been known under a different name and with different data types
00067 // in GUSI 1.                                                              
00068 //                                                                         
00069 // <GUSIFileSpec.h>=                                                       
00070 #ifndef _GUSIFileSpec_
00071 #define _GUSIFileSpec_
00072 
00073 #include <MacTypes.h>
00074 #include <Files.h>
00075 #include <Folders.h>
00076 
00077 #include <string.h>
00078 #include <sys/cdefs.h>
00079 
00080 __BEGIN_DECLS
00081 // \section{C Interfaces to [[GUSIFileSpec]]}                              
00082 //                                                                         
00083 // Many of the API routines defined here are useful to C code and not too hard to make accessible,
00084 // even though I prefer the C++ versions. As opposed to GUSI 1, we stick to our namespace now.
00085 //                                                                         
00086 // <Plain C interfaces to [[GUSIFileSpec]]>=                               
00087 /*
00088  * Construct a FSSpec from...
00089  */
00090 /* ... the refNum of an open file.               */
00091 OSErr GUSIFRefNum2FSp(short fRefNum, FSSpec * desc);
00092 /* ... a working directory & file name. */
00093 OSErr GUSIWD2FSp(short wd, ConstStr31Param name, FSSpec * desc);
00094 /* ... a path name.                                     */
00095 OSErr GUSIPath2FSp(const char * path, FSSpec * desc);   
00096 /* ... a special object.                         */
00097 OSErr GUSISpecial2FSp(OSType object, short vol, FSSpec * desc);       
00098 /* ... a temporary file path.                 */
00099 OSErr GUSIMakeTempFSp(short vol, long dirID, FSSpec * desc);
00100 
00101 /*
00102  * Convert a FSSpec into...
00103  */
00104 /* ... a full path name.                                                     */
00105 char * GUSIFSp2FullPath(const FSSpec * desc);
00106 /* ... a relative path name if possible, full if not    */
00107 char * GUSIFSp2RelPath(const FSSpec * desc);     
00108 /* ... a path relative to the specified directory              */
00109 char * GUSIFSp2DirRelPath(const FSSpec * desc, const FSSpec * dir);
00110 /* ... an GUSI-=specific ASCII encoding.                       */
00111 char * GUSIFSp2Encoding(const FSSpec * desc);
00112 
00113 /*
00114  * Construct FSSpec of...
00115  */
00116 /* ... (vRefNum, parID) */
00117 OSErr GUSIFSpUp(FSSpec * desc);
00118 /* ... file (name) in directory denoted by desc */
00119 OSErr GUSIFSpDown(FSSpec * desc, ConstStr31Param name);
00120 /* ... of nth file in directory denoted by (vRefNum, parID) */
00121 OSErr GUSIFSpIndex(FSSpec * desc, short n);
00122 
00123 /* Resolve if alias file */
00124 OSErr GUSIFSpResolve(FSSpec * spec);
00125 
00126 /* Touch folder containing the object */
00127 OSErr GUSIFSpTouchFolder(const FSSpec * spec);
00128 
00129 /* Get catalog information */
00130 OSErr GUSIFSpGetCatInfo(const FSSpec * spec, CInfoPBRec * info);
00131 __END_DECLS
00132 
00133 #ifdef GUSI_SOURCE
00134 
00135 #include "GUSIBasics.h"
00136 #include "GUSIContext.h"
00137 
00138 #include <ConditionalMacros.h>
00139 
00140 #if PRAGMA_STRUCT_ALIGN
00141 #pragma options align=native
00142 #endif
00143 
00144 // \section{Definition of [[GUSICatInfo]]}                                 
00145 //                                                                         
00146 // [[GUSICatInfo]] is a wrapper for [[CInfoPBRec]]. Since the latter is a [[union]], we cannot
00147 // inherit from it.                                                        
00148 //                                                                         
00149 // <Definition of class [[GUSICatInfo]]>=                                  
00150 class GUSICatInfo {
00151        CInfoPBRec    fInfo;
00152 public:
00153        bool          IsFile() const;
00154        bool          IsAlias() const;
00155        bool          DirIsExported() const;
00156        bool          DirIsMounted() const;
00157        bool          DirIsShared() const;
00158        bool          HasRdPerm() const;
00159        bool          HasWrPerm() const;
00160        bool          Locked() const;
00161        
00162        CInfoPBRec &                       Info()               {      return fInfo;                                                  }
00163        operator CInfoPBRec &()                                        {      return fInfo;                                                  }
00164        struct HFileInfo &                 FileInfo()           {      return fInfo.hFileInfo;                                 }
00165        struct DirInfo &                   DirInfo()            {      return fInfo.dirInfo;                                   }
00166        struct FInfo &                            FInfo()                     {      return fInfo.hFileInfo.ioFlFndrInfo;      }
00167        struct FXInfo &                           FXInfo()             {      return fInfo.hFileInfo.ioFlXFndrInfo;     }
00168        
00169        const CInfoPBRec &                 Info() const  {      return fInfo;                                                  }
00170        operator const CInfoPBRec &()      const         {      return fInfo;                                                  }
00171        const struct HFileInfo &    FileInfo() const{    return fInfo.hFileInfo;                                 }
00172        const struct DirInfo &             DirInfo() const      {      return fInfo.dirInfo;                                   }
00173        const struct FInfo &        FInfo() const {      return fInfo.hFileInfo.ioFlFndrInfo;      }
00174        const struct FXInfo &              FXInfo() const       {      return fInfo.hFileInfo.ioFlXFndrInfo;     }
00175 };
00176 // \section{Definition of [[GUSIFileSpec]]}                                
00177 //                                                                         
00178 // A [[GUSIFileSpec]] is a manipulation friendly version of an [[FSSpec]]. Due to
00179 // conversion operators, a [[GUSIFileSpec]] can be used whereever a [[const FSSpec]]
00180 // is specified. For any long term storage, [[FSSpec]] should be used rather than the
00181 // much bulkier [[GUSIFileSpec]].                                          
00182 //                                                                         
00183 // <Definition of class [[GUSIFileSpec]]>=                                 
00184 class GUSIFileSpec {
00185 public:
00186        // A [[GUSIFileSpec]] can be constructed in lots of different ways. Most of the 
00187  // constructors have a final argument [[useAlias]] that, when [[true]], suppresses
00188  // resolution of leaf aliases.                                             
00189  //                                                                         
00190  // First, two trivial cases: The default constructor and the copy constructor, which
00191  // do exactly what you'd expect them to do.                                
00192  //                                                                         
00193  // <Constructors for [[GUSIFileSpec]]>=                                    
00194  GUSIFileSpec()      {}
00195  GUSIFileSpec(const GUSIFileSpec & spec);
00196  // The [[FSSpec]] conversion is almost a copy constructor, but by default resolves
00197  // leaf aliases.                                                           
00198  //                                                                         
00199  // <Constructors for [[GUSIFileSpec]]>=                                    
00200  GUSIFileSpec(const FSSpec & spec, bool useAlias = false);
00201  // A number of convenience constructors let you construct a [[GUSIFileSpec]] from
00202  // various components.                                                     
00203  //                                                                         
00204  // <Constructors for [[GUSIFileSpec]]>=                                    
00205  // Construct from volume reference number, directory ID & file name
00206  GUSIFileSpec(short vRefNum, long parID, ConstStr31Param name, bool useAlias = false);
00207 
00208  // Construct from working directory & file name
00209  GUSIFileSpec(short wd, ConstStr31Param name, bool useAlias = false);
00210 
00211  // Construct from full or relative path
00212  GUSIFileSpec(const char * path, bool useAlias = false);
00213        
00214  // Construct from open file reference number
00215  explicit GUSIFileSpec(short fRefNum);
00216  // Finally, there is a constructor for constructing a [[GUSIFileSpec]] for one of
00217  // the folders obtainable with [[FindFolder]].                             
00218  //                                                                         
00219  // <Constructors for [[GUSIFileSpec]]>=                                    
00220  GUSIFileSpec(OSType object, short vol = kOnSystemDisk);
00221        // All [[GUSIFileSpecs]] have an error variable from which the last error  
00222  // is available.                                                           
00223  //                                                                         
00224  // <Error handling in [[GUSIFileSpec]]>=                                   
00225  OSErr        Error() const;
00226                      operator void*() const;
00227  bool         operator!() const;
00228        // While earlier versions of GUSI maintained a notion of "current directory" that
00229  // was independent of the HFS default directory, there is no such distinction anymore
00230  // in GUSI 2. [[SetDefaultDirectory]] sets the default directory to [[vRefNum, dirID]].
00231  // [[GetDefaultDirectory]] sets [[vRefNum,dirID]] to the default directory. Neither
00232  // routine affects the [[name]]. [[GetVolume]] gets the named or indexed volume.
00233  //                                                                         
00234  // <Default directory handling in [[GUSIFileSpec]]>=                       
00235  OSErr SetDefaultDirectory();
00236  OSErr GetDefaultDirectory();
00237  OSErr GetVolume(short index = -1);
00238        // Conversions of [[GUSIFileSpec]] to [[FSSpec]] values and references is, of course, 
00239  // simple. Pointers are a bit trickier; we define an custom [[operator&]] and two 
00240  // smart pointer classes. [[operator->]], however, is simpler.             
00241  //                                                                         
00242  // <Converting a [[GUSIFileSpec]] to a [[FSSpec]]>=                        
00243  operator const FSSpec &() const;
00244 
00245  class pointer {
00246  public:
00247        pointer(GUSIFileSpec * ptr);
00248        operator GUSIFileSpec *() const;
00249        operator const FSSpec *() const;
00250  private:
00251        GUSIFileSpec * ptr;
00252  };
00253  pointer operator&();
00254 
00255  class const_pointer {
00256  public:
00257        const_pointer(const GUSIFileSpec * ptr);
00258        operator const GUSIFileSpec *() const;
00259        operator const FSSpec *() const;
00260  private:
00261        const GUSIFileSpec * ptr;
00262  };
00263  const_pointer operator&() const;
00264 
00265  const FSSpec * operator->() const;
00266 
00267  friend class pointer;
00268  friend class const_pointer;
00269        // Each [[GUSIFileSpec]] has an implicit [[GUSICatInfo]] record associated with it.
00270  // [[CatInfo]] calls [[GetCatInfo]] if the record is not already valid and 
00271  // returns a pointer to the record. [[DirInfo]] replaces the [[GUSIFileSpec]] by 
00272  // the specification of its parent directory and returns a pointer to information 
00273  // about the parent. Both calls return a [[nil]] pointer if the object does not exist.
00274  // If all you are interested in is whether the object exists, call [[Exists]]. 
00275  //                                                                         
00276  // <Getting the [[GUSICatInfo]] for a [[GUSIFileSpec]]>=                   
00277  const GUSICatInfo * CatInfo(short index);
00278  const GUSICatInfo * DirInfo();
00279  const GUSICatInfo * CatInfo() const;
00280  bool                       Exists() const;
00281        // In many POSIXish contexts, it's necessary to specify path names with C string. 
00282  // Although this practice is dangerous on a Mac, we of course have to conform to
00283  // it. The basic operations are getting a full path and getting a path relative to
00284  // a directory (the current directory by default).                         
00285  //                                                                         
00286  // <Getting path names from a [[GUSIFileSpec]]>=                           
00287  char *       FullPath() const;
00288  char *       RelativePath() const;
00289  char *       RelativePath(const FSSpec & dir) const;
00290  // If the path ultimately is going to flow back into a GUSI routine again, it is 
00291  // possible to simply encode the [[GUSIFileSpec]] in ASCII. This is fast and reliable,
00292  // but you should of course not employ it with any non-GUSI destination routine and 
00293  // should never store such a part across a reboot. The standard [[GUSIFileSpec]] 
00294  // constructors for paths will accept encoded paths.                       
00295  //                                                                         
00296  // The encoding is defined as:                                             
00297  //                                                                         
00298  // \begin{itemize}                                                         
00299  // \item 1 byte:   DC1  (ASCII 0x11)                                       
00300  // \item 4 bytes:  Volume reference number in zero-padded hex              
00301  // \item 8 bytes:  Directory ID in zero-padded hex                         
00302  // \item n bytes:  Partial pathname, starting with ':'                     
00303  // \end{itemize}                                                           
00304  //                                                                         
00305  // <Getting path names from a [[GUSIFileSpec]]>=                           
00306  char *       EncodedPath() const;
00307        // Most aliases are resolved implicitly, but occasionally you may want to do
00308  // explicit resolution. [[Resolve]] resolves an alias. If [[gently]] is set, 
00309  // nonexistent target files of aliases don't cause an error to be returned.
00310  //                                                                         
00311  // <Alias resolution for a [[GUSIFileSpec]]>=                              
00312  OSErr Resolve(bool gently = true);
00313  // [[AliasPath]] returns the path an alias points to without mounting any volumes. 
00314  //                                                                         
00315  // <Alias resolution for a [[GUSIFileSpec]]>=                              
00316  char *       AliasPath() const;
00317        // A major feature of the [[GUSIFileSpec]] class is the set of operators for
00318  // manipulating a file specification.                                      
00319  //                                                                         
00320  // [[operator--]] replaces a file specification with the directory specification of
00321  // its parent.                                                             
00322  //                                                                         
00323  // <Manipulating a [[GUSIFileSpec]]>=                                      
00324  GUSIFileSpec &      operator--();
00325  // [[operator++]] sets the [[dirID]] of a directory specification to the ID of the
00326  // directory.                                                              
00327  //                                                                         
00328  // <Manipulating a [[GUSIFileSpec]]>=                                      
00329  GUSIFileSpec &      operator++();
00330  // The two versions of [[operator+=]], which internally both call [[AddPathComponent]],
00331  // replace a directory specification with the specification                
00332  //                                                                         
00333  // <Manipulating a [[GUSIFileSpec]]>=                                      
00334  GUSIFileSpec &      AddPathComponent(const char * name, int length, bool fullSpec);
00335  GUSIFileSpec &      operator+=(ConstStr31Param name);
00336  GUSIFileSpec &      operator+=(const char * name);
00337  // [[operator+]] provides a non-destructive variant of [[operator+=]].     
00338  //                                                                         
00339  // <Manipulating a [[GUSIFileSpec]]>=                                      
00340  friend GUSIFileSpec operator+(const FSSpec & spec, ConstStr31Param name);
00341  friend GUSIFileSpec operator+(const FSSpec & spec, const char * name);
00342  // Array access replaces the file specification with the [[index]]th object in the
00343  // {\em parent directory} of the specification (allowing the same specification to
00344  // be reused for reading a directory).                                     
00345  //                                                                         
00346  // <Manipulating a [[GUSIFileSpec]]>=                                      
00347  GUSIFileSpec & operator[](short index);
00348  // To manipulate the fields of the file specification directly, there is a procedural
00349  // interface.                                                              
00350  //                                                                         
00351  // <Manipulating a [[GUSIFileSpec]]>=                                      
00352  void SetVRef(short vref);
00353  void SetParID(long parid);
00354  void SetName(ConstStr63Param nam);
00355  void SetName(const char * nam);
00356  // For some modifications to propagate quickly, the surrounding folder needs to 
00357  // have its date modified.                                                 
00358  //                                                                         
00359  // <Manipulating a [[GUSIFileSpec]]>=                                      
00360  OSErr TouchFolder();
00361        // Two [[GUSIFileSpecs]] can be compared for (in)equality.                 
00362  //                                                                         
00363  // <Comparing two [[GUSIFileSpec]] objects>=                               
00364  friend bool operator==(const GUSIFileSpec & one, const GUSIFileSpec & other);
00365  // [[IsParentOf]] determines whether the object specifies a parent directory of 
00366  // [[other]].                                                              
00367  //                                                                         
00368  // <Comparing two [[GUSIFileSpec]] objects>=                               
00369  bool  IsParentOf(const GUSIFileSpec & other) const;
00370 protected:
00371        // \section{Implementation of [[GUSIFileSpec]]}                            
00372  //                                                                         
00373  // [[sError]] contains the error code for failed calls. [[Error]] returns the value.
00374  //                                                                         
00375  // <Privatissima of [[GUSIFileSpec]]>=                                     
00376  mutable OSErr       fError;
00377  // For path name constructions, a sometimes large scratch area is needed which is 
00378  // maintained in [[sScratch]]. A scratch request preserves a preexisting scratch area
00379  // at the {\em end} of the new area if [[extend]] is nonzero.              
00380  //                                                                         
00381  // <Privatissima of [[GUSIFileSpec]]>=                                     
00382  static char *              sScratch;
00383  static long                sScratchSize;
00384 
00385  static char *              CScratch(bool extend = false);
00386  static StringPtr    PScratch();
00387  // A [[GUSIFileSpec]] has a [[GUSICatInfo]] embedded and a flag [[fValidInfo]] indicating
00388  // that it is valid.                                                       
00389  //                                                                         
00390  // <Privatissima of [[GUSIFileSpec]]>=                                     
00391  FSSpec                                                 fSpec;
00392  GUSIIOPBWrapper<GUSICatInfo>      fInfo;
00393  bool                                            fValidInfo;
00394  // For convenience, we define a fictivous parent directory of all volumes. 
00395  //                                                                         
00396  // <Privatissima of [[GUSIFileSpec]]>=                                     
00397  enum { ROOT_MAGIC_COOKIE = 666 };
00398  // Each accumulation step is preformed in [[PrependPathComponent]].        
00399  //                                                                         
00400  // <Privatissima of [[GUSIFileSpec]]>=                                     
00401  OSErr PrependPathComponent(char *&path, ConstStr63Param component, bool colon) const;
00402 };
00403 // A [[GUSITempFileSpec]] is just a [[GUSIFileSpec]] with constructors to construct
00404 // filenames for temporary files.                                          
00405 //                                                                         
00406 // <Definition of class [[GUSIFileSpec]]>=                                 
00407 class GUSITempFileSpec : public GUSIFileSpec {
00408 public:
00409        GUSITempFileSpec(short vRefNum = kOnSystemDisk);
00410        GUSITempFileSpec(short vRefNum, long parID);
00411        GUSITempFileSpec(ConstStr31Param basename);
00412        GUSITempFileSpec(short vRefNum, ConstStr31Param basename);
00413        GUSITempFileSpec(short vRefNum, long parID, ConstStr31Param basename);
00414 private:
00415        void TempName();
00416        void TempName(ConstStr31Param basename);
00417        
00418        static int    sID;
00419 };
00420 
00421 #if PRAGMA_STRUCT_ALIGN
00422 #pragma options align=reset
00423 #endif
00424 
00425 // \section{Implementation of [[GUSICatInfo]]}                             
00426 //                                                                         
00427 // All of the member functions for [[GUSICatInfo]] are inline.             
00428 //                                                                         
00429 // <Inline member functions for class [[GUSICatInfo]]>=                    
00430 inline bool GUSICatInfo::IsFile() const
00431 {
00432        return !(DirInfo().ioFlAttrib & 0x10);
00433 }
00434 
00435 inline bool GUSICatInfo::IsAlias() const
00436 {
00437        return
00438               !(FileInfo().ioFlAttrib & 0x10) &&
00439               (FInfo().fdFlags & (1 << 15));
00440 }
00441 
00442 inline bool GUSICatInfo::DirIsExported() const
00443 {
00444        return (FileInfo().ioFlAttrib & 0x20) != 0;
00445 }
00446 
00447 inline bool GUSICatInfo::DirIsMounted() const
00448 {
00449        return (FileInfo().ioFlAttrib & 0x08) != 0;
00450 }
00451 
00452 inline bool GUSICatInfo::DirIsShared() const
00453 {
00454        return (FileInfo().ioFlAttrib & 0x04) != 0;
00455 }
00456 
00457 inline bool GUSICatInfo::HasRdPerm() const
00458 {
00459        return !(DirInfo().ioACUser & 0x02) != 0;
00460 }
00461 
00462 inline bool GUSICatInfo::HasWrPerm() const
00463 {
00464        return !(DirInfo().ioACUser & 0x04) != 0;
00465 }
00466 
00467 inline bool GUSICatInfo::Locked() const
00468 {
00469        return (FileInfo().ioFlAttrib & 0x11) == 0x01;
00470 }
00471 // <Inline member functions for class [[GUSIFileSpec]]>=                   
00472 inline OSErr GUSIFileSpec::Error() const
00473 {
00474        return fError;
00475 }
00476 
00477 inline GUSIFileSpec::operator void*() const
00478 {
00479        return (void *)!fError;
00480 }
00481 
00482 inline bool GUSIFileSpec::operator!() const
00483 {
00484        return fError!=0;
00485 }
00486 // <Inline member functions for class [[GUSIFileSpec]]>=                   
00487 inline StringPtr GUSIFileSpec::PScratch()
00488 {
00489        return (StringPtr) CScratch();
00490 }
00491 // <Inline member functions for class [[GUSIFileSpec]]>=                   
00492 inline OSErr GUSIFileSpec::SetDefaultDirectory()
00493 {
00494        return fError = HSetVol(nil, fSpec.vRefNum, fSpec.parID);
00495 }
00496 
00497 inline OSErr GUSIFileSpec::GetDefaultDirectory()
00498 {
00499        fSpec.name[0]        = 0;
00500        fValidInfo           = false;
00501        return fError        = HGetVol(nil, &fSpec.vRefNum, &fSpec.parID);
00502 }
00503 // [[operator+=]] and [[operator+]] are merely wrappers around [[AddPathComponent]].
00504 //                                                                         
00505 // <Inline member functions for class [[GUSIFileSpec]]>=                   
00506 inline GUSIFileSpec &       GUSIFileSpec::operator+=(ConstStr31Param name)
00507 {
00508        return AddPathComponent((char *) name+1, name[0], true);
00509 }
00510 
00511 inline GUSIFileSpec &       GUSIFileSpec::operator+=(const char * name)
00512 {
00513        return AddPathComponent(name, strlen(name), true);
00514 }
00515 // The other variations of the call are simple.                            
00516 //                                                                         
00517 // <Inline member functions for class [[GUSIFileSpec]]>=                   
00518 inline const GUSICatInfo * GUSIFileSpec::CatInfo() const
00519 {
00520        return const_cast<GUSIFileSpec *>(this)->CatInfo(0);
00521 }
00522 
00523 inline const GUSICatInfo * GUSIFileSpec::DirInfo()
00524 {
00525        if (CatInfo(-1)) {
00526               fSpec.parID = fInfo->DirInfo().ioDrParID;
00527               fValidInfo    = true;
00528               
00529               return &fInfo.fPB;
00530        } else
00531               return nil;
00532 }
00533 
00534 inline bool GUSIFileSpec::Exists() const
00535 {
00536        return CatInfo() != nil;
00537 }
00538 // Reference conversion is straightforward, as is [[operator->]].          
00539 //                                                                         
00540 // <Inline member functions for class [[GUSIFileSpec]]>=                   
00541 inline GUSIFileSpec::operator const FSSpec &() const
00542 {
00543        return fSpec;
00544 }
00545 inline const FSSpec * GUSIFileSpec::operator->() const
00546 {
00547        return &fSpec;
00548 }
00549 // Pointers, however, are a trickier issue, as they might be used either as a 
00550 // [[GUSIFileSpec *]] or as an [[FSSpec *]].                               
00551 //                                                                         
00552 // <Inline member functions for class [[GUSIFileSpec]]>=                   
00553 inline GUSIFileSpec::const_pointer::const_pointer(const GUSIFileSpec * ptr)
00554        : ptr(ptr)
00555 {
00556 }
00557 inline GUSIFileSpec::const_pointer::operator const GUSIFileSpec *() const
00558 {
00559        return ptr;
00560 }
00561 inline GUSIFileSpec::const_pointer::operator const FSSpec *() const
00562 {
00563        return &ptr->fSpec;
00564 }
00565 inline GUSIFileSpec::const_pointer GUSIFileSpec::operator&() const
00566 {
00567        return const_pointer(this);
00568 }
00569 // [[GUSIFileSpec::pointer]] is the non-constant equivalent to [[GUSIFileSpec::const_pointer]].
00570 //                                                                         
00571 // <Inline member functions for class [[GUSIFileSpec]]>=                   
00572 inline GUSIFileSpec::pointer::pointer(GUSIFileSpec * ptr)
00573        : ptr(ptr)
00574 {
00575 }
00576 inline GUSIFileSpec::pointer::operator GUSIFileSpec *() const
00577 {
00578        return ptr;
00579 }
00580 inline GUSIFileSpec::pointer::operator const FSSpec *() const
00581 {
00582        return &ptr->fSpec;
00583 }
00584 inline GUSIFileSpec::pointer GUSIFileSpec::operator&()
00585 {
00586        return pointer(this);
00587 }
00588 
00589 #endif /* GUSI_SOURCE */
00590 
00591 #endif /* GUSIFileSpec */