home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FileSpec.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __FILESPEC__
- #define __FILESPEC__
-
- #ifndef __FILES__
- #include "Files.h"
- #endif
-
- #ifndef __DIRECTOBJECT__
- #include "DirectObject.h"
- #endif
-
- #pragma push
- #pragma segment FileSpec
-
- class ostream;
-
- /*============================================================================
-
- THFSSpec is an abstraction for a file spec, a thing which represents
- the location of a local file or folder using Macintosh HFS.
-
- ----------------------------------------------------------------------------*/
-
- class THFSSpec : public TDirectObject
- {
- public: THFSSpec ();
- THFSSpec ( const char* ); // file in current WD
- THFSSpec ( const StringPtr ); // file in current WD
- THFSSpec ( short vRefNum, long parID, const char* name );
- THFSSpec ( short vRefNum, long parID, const StringPtr name );
- THFSSpec ( const FSSpec& );
- THFSSpec ( const THFSSpec& );
- virtual ~THFSSpec ();
-
- // handy operators
- operator const FSSpec* () const; // ‘this’ converts to a FSSpec*
- operator const FSSpec& () const; // ‘this’ converts to a FSSpec&
- THFSSpec& operator = ( const THFSSpec& );
- Boolean operator == ( const THFSSpec& ) const;
- Boolean operator != ( const THFSSpec& ) const;
-
- // characteristics
-
- const StringPtr GetPName () const;
- const char* GetCName () const;
-
- void GetName ( Str63 ) const;
- void GetName ( char*, unsigned long size ) const;
-
- long GetParent () const;
- virtual void GetParentName ( char*, unsigned long size ) const;
-
- short GetVolume () const;
- void GetVolumeName ( char*, unsigned long size ) const;
-
- unsigned long GetPathLength () const;
- void GetPath ( char*, unsigned long size ) const;
- const char* GetPath () const;
- virtual char* CreatePath () const;
-
- // debugging
-
- #if debug
- virtual Boolean InvariantCheck ( ostream& ) const;
- virtual ostream& operator >> ( ostream& ) const;
- #endif
- FSSpec& GetSpec () const; // handles direct and indirect FSSpec cases
-
- protected: void SetToCurrentDirectory ();
-
- private: FSSpec fSpec;
- char* fCachedPath;
- };
-
- /*============================================================================
-
- TFileSpec is an abstraction for a file spec, a thing which represents
- the location of a local file using Macintosh HFS.
-
- Change History:
-
- 11/19/92 CMM Created.
-
- ----------------------------------------------------------------------------*/
-
- class TFileSpec : public THFSSpec
- {
- public: TFileSpec ();
- TFileSpec ( const char* ); // file in current WD
- TFileSpec ( const StringPtr ); // file in current WD
- TFileSpec ( short vRefNum, long parID, const char* name );
- TFileSpec ( short vRefNum, long parID, const StringPtr name );
- TFileSpec ( const FSSpec& );
- TFileSpec ( const TFileSpec& );
- TFileSpec ( const THFSSpec& );
- virtual ~TFileSpec ();
-
- virtual Boolean CreateFile ( OSType creator = 'ttxt', OSType type = 'TEXT' );
- virtual Boolean DeleteFile ();
- virtual Boolean DoesFileExist () const;
- virtual Boolean GetLogicalSize ( unsigned long& ) const;
- virtual Boolean GetCreationDate ( unsigned long& ) const;
- virtual Boolean GetModificationDate ( unsigned long& ) const;
- };
-
- /*============================================================================
-
- TFolderSpec is an abstraction for a file spec, a thing which represents
- the location of a local file using Macintosh HFS.
-
- Change History:
-
- 11/19/92 CMM Created.
-
- ----------------------------------------------------------------------------*/
-
- class TFolderSpec : public THFSSpec
- {
- public: TFolderSpec ();
- TFolderSpec ( const char* ); // file in current WD
- TFolderSpec ( const StringPtr ); // file in current WD
- TFolderSpec ( short vRefNum, long parID, const char* name );
- TFolderSpec ( short vRefNum, long parID, const StringPtr name );
- TFolderSpec ( const FSSpec& );
- TFolderSpec ( const THFSSpec& );
- TFolderSpec ( const TFolderSpec& );
- virtual ~TFolderSpec ();
-
- virtual long GetID () const;
- virtual Boolean CreateFolder ();
- virtual Boolean DeleteFolder ();
- virtual Boolean DoesFolderExist () const;
- virtual unsigned long CountChildrenFiles () const;
- virtual Boolean GetChildFile ( unsigned long index, TFileSpec& ) const;
-
- #if debug
- virtual ostream& operator >> ( ostream& ) const;
- #endif
-
- protected: long LookupID () const;
- private: long fID;
- };
-
- /***********************************|****************************************/
-
- class TFolderFileIterator
- {
- public: TFolderFileIterator ( const TFolderSpec& );
- virtual ~TFolderFileIterator ();
-
- virtual const TFileSpec* FirstFile ();
- virtual const TFileSpec* NextFile ();
-
- private: CInfoPBRec fParams;
- TFileSpec* fCurrent;
- short fVRefNum;
- long fParID;
- Str63 fName;
- };
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- inline FSSpec&
- THFSSpec::GetSpec () const
- {
- return ( (THFSSpec*) this )->fSpec;
- }
-
- /***********************************|****************************************/
-
- inline
- THFSSpec::operator const FSSpec* () const
- {
- return &( (THFSSpec*) this )->fSpec;
- }
-
- /***********************************|****************************************/
-
- inline
- THFSSpec::operator const FSSpec& () const
- {
- return ( (THFSSpec*) this )->fSpec;
- }
-
- /***********************************|****************************************/
-
- inline long
- THFSSpec::GetParent () const
- {
- return GetSpec ().parID;
- }
-
- /***********************************|****************************************/
-
- inline short
- THFSSpec::GetVolume () const
- {
- return GetSpec ().vRefNum;
- }
-
- /***********************************|****************************************/
-
- inline Boolean
- THFSSpec::operator != ( const THFSSpec& that ) const
- {
- return !operator == ( that );
- }
-
- /***********************************|****************************************/
-
- inline const StringPtr
- THFSSpec::GetPName () const
- {
- return GetSpec ().name;
- }
-
- #pragma pop
-
- /***********************************|****************************************/
-
- #endif // __FILESPEC__
-