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 / BuildingBlocks / FileSpec.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  6.2 KB  |  236 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        FileSpec.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    __FILESPEC__
  15. #define    __FILESPEC__
  16.  
  17. #ifndef    __FILES__
  18. #include "Files.h"
  19. #endif
  20.  
  21. #ifndef    __DIRECTOBJECT__
  22. #include "DirectObject.h"
  23. #endif
  24.  
  25. #pragma push
  26. #pragma segment FileSpec
  27.  
  28. class ostream;
  29.  
  30. /*============================================================================
  31.  
  32.     THFSSpec is an abstraction for a file spec, a thing which represents
  33.     the location of a local file or folder using Macintosh HFS.
  34.  
  35. ----------------------------------------------------------------------------*/
  36.  
  37. class THFSSpec : public TDirectObject
  38. {
  39. public:        THFSSpec ();
  40.             THFSSpec ( const char* );        // file in current WD
  41.             THFSSpec ( const StringPtr );    // file in current WD
  42.             THFSSpec ( short vRefNum, long parID, const char* name );
  43.             THFSSpec ( short vRefNum, long parID, const StringPtr name );
  44.             THFSSpec ( const FSSpec& );
  45.             THFSSpec ( const THFSSpec& );
  46.     virtual    ~THFSSpec ();
  47.  
  48. // handy operators
  49.                                     operator const FSSpec* () const;    // ‘this’ converts to a FSSpec*
  50.                                     operator const FSSpec& () const;    // ‘this’ converts to a FSSpec&
  51.             THFSSpec&                operator = ( const THFSSpec& );
  52.             Boolean                    operator == ( const THFSSpec& ) const;
  53.             Boolean                    operator != ( const THFSSpec& ) const;
  54.  
  55. // characteristics
  56.  
  57.             const StringPtr            GetPName () const;
  58.             const char*                GetCName () const;
  59.  
  60.             void                    GetName ( Str63 ) const;
  61.             void                    GetName ( char*, unsigned long size ) const;
  62.  
  63.             long                    GetParent () const;
  64.     virtual    void                    GetParentName ( char*, unsigned long size ) const;
  65.  
  66.             short                    GetVolume () const;
  67.             void                    GetVolumeName ( char*, unsigned long size ) const;
  68.  
  69.             unsigned long            GetPathLength () const;
  70.             void                    GetPath ( char*, unsigned long size ) const;
  71.             const char*                GetPath () const;
  72.     virtual    char*                    CreatePath () const;
  73.  
  74. // debugging
  75.  
  76. #if debug
  77.     virtual    Boolean                    InvariantCheck ( ostream& ) const;
  78.     virtual    ostream&                operator >> ( ostream& ) const;
  79. #endif
  80.             FSSpec&                    GetSpec () const;    // handles direct and indirect FSSpec cases
  81.  
  82. protected:    void                    SetToCurrentDirectory ();
  83.  
  84. private:    FSSpec                    fSpec;
  85.             char*                    fCachedPath;
  86. };
  87.  
  88. /*============================================================================
  89.  
  90.     TFileSpec is an abstraction for a file spec, a thing which represents
  91.     the location of a local file using Macintosh HFS.
  92.  
  93.     Change History:
  94.  
  95.         11/19/92      CMM        Created.
  96.  
  97. ----------------------------------------------------------------------------*/
  98.  
  99. class TFileSpec : public THFSSpec
  100. {
  101. public:        TFileSpec ();
  102.             TFileSpec ( const char* );    // file in current WD
  103.             TFileSpec ( const StringPtr );    // file in current WD
  104.             TFileSpec ( short vRefNum, long parID, const char* name );
  105.             TFileSpec ( short vRefNum, long parID, const StringPtr name );
  106.             TFileSpec ( const FSSpec& );
  107.             TFileSpec ( const TFileSpec& );
  108.             TFileSpec ( const THFSSpec& );
  109.     virtual    ~TFileSpec ();
  110.  
  111.     virtual    Boolean                    CreateFile ( OSType creator = 'ttxt', OSType type = 'TEXT' );
  112.     virtual    Boolean                    DeleteFile ();
  113.     virtual    Boolean                    DoesFileExist () const;
  114.     virtual    Boolean                    GetLogicalSize ( unsigned long& ) const;
  115.     virtual    Boolean                    GetCreationDate ( unsigned long& ) const;
  116.     virtual    Boolean                    GetModificationDate ( unsigned long& ) const;
  117. };
  118.  
  119. /*============================================================================
  120.  
  121.     TFolderSpec is an abstraction for a file spec, a thing which represents
  122.     the location of a local file using Macintosh HFS.
  123.  
  124.     Change History:
  125.  
  126.         11/19/92      CMM        Created.
  127.  
  128. ----------------------------------------------------------------------------*/
  129.  
  130. class TFolderSpec : public THFSSpec
  131. {
  132. public:        TFolderSpec ();
  133.             TFolderSpec ( const char* );        // file in current WD
  134.             TFolderSpec ( const StringPtr );    // file in current WD
  135.             TFolderSpec ( short vRefNum, long parID, const char* name );
  136.             TFolderSpec ( short vRefNum, long parID, const StringPtr name );
  137.             TFolderSpec ( const FSSpec& );
  138.             TFolderSpec ( const THFSSpec& );
  139.             TFolderSpec ( const TFolderSpec& );
  140.     virtual    ~TFolderSpec ();
  141.  
  142.     virtual    long                    GetID () const;
  143.     virtual    Boolean                    CreateFolder ();
  144.     virtual    Boolean                    DeleteFolder ();
  145.     virtual    Boolean                    DoesFolderExist () const;
  146.     virtual    unsigned long            CountChildrenFiles () const;
  147.     virtual    Boolean                    GetChildFile ( unsigned long index, TFileSpec& ) const;
  148.  
  149. #if debug
  150.     virtual    ostream&                operator >> ( ostream& ) const;
  151. #endif
  152.  
  153. protected:    long                    LookupID () const;
  154. private:    long                    fID;
  155. };
  156.  
  157. /***********************************|****************************************/
  158.  
  159. class TFolderFileIterator
  160. {
  161. public:        TFolderFileIterator ( const TFolderSpec& );
  162.     virtual    ~TFolderFileIterator ();
  163.  
  164.     virtual    const TFileSpec*        FirstFile ();
  165.     virtual    const TFileSpec*        NextFile ();
  166.  
  167. private:    CInfoPBRec                fParams;
  168.             TFileSpec*                fCurrent;
  169.             short                    fVRefNum;
  170.             long                    fParID;
  171.             Str63                    fName;
  172. };
  173.  
  174. /***********************************|****************************************/
  175. /***********************************|****************************************/
  176.  
  177. inline FSSpec&
  178. THFSSpec::GetSpec () const
  179. {
  180.     return ( (THFSSpec*) this )->fSpec;
  181. }
  182.  
  183. /***********************************|****************************************/
  184.  
  185. inline
  186. THFSSpec::operator const FSSpec* () const
  187. {
  188.     return &( (THFSSpec*) this )->fSpec;
  189. }
  190.  
  191. /***********************************|****************************************/
  192.  
  193. inline
  194. THFSSpec::operator const FSSpec& () const
  195. {
  196.     return ( (THFSSpec*) this )->fSpec;
  197. }
  198.  
  199. /***********************************|****************************************/
  200.  
  201. inline long
  202. THFSSpec::GetParent () const
  203. {
  204.     return GetSpec ().parID;
  205. }
  206.  
  207. /***********************************|****************************************/
  208.  
  209. inline short
  210. THFSSpec::GetVolume () const
  211. {
  212.     return GetSpec ().vRefNum;
  213. }
  214.  
  215. /***********************************|****************************************/
  216.  
  217. inline Boolean
  218. THFSSpec::operator != ( const THFSSpec& that ) const
  219. {
  220.     return !operator == ( that );
  221. }
  222.  
  223. /***********************************|****************************************/
  224.  
  225. inline const StringPtr
  226. THFSSpec::GetPName () const
  227. {
  228.     return GetSpec ().name;
  229. }
  230.  
  231. #pragma pop
  232.  
  233. /***********************************|****************************************/
  234.  
  235. #endif    // __FILESPEC__
  236.