|
From: Paul S. <psn...@us...> - 2004-03-28 22:25:13
|
Update of /cvsroot/whisper2/Whisper/Source/BackEnd/Files/Source/Files In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19418/Source/BackEnd/Files/Source/Files Modified Files: XFileSystemSpec.h XMemoryMappedFile.h Log Message: Minor code fixes to build on both Mac and Win32 again; fixes to project files to not cache like mad order things so precompiled headers work again. Index: XFileSystemSpec.h =================================================================== RCS file: /cvsroot/whisper2/Whisper/Source/BackEnd/Files/Source/Files/XFileSystemSpec.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** XFileSystemSpec.h 15 Aug 2003 10:05:15 -0000 1.6 --- XFileSystemSpec.h 28 Mar 2004 22:13:16 -0000 1.7 *************** *** 1,231 **** ! /* ! * File: XFileSystemSpec.h ! * Summary: An object that points to a (possibly non-existent) file/folder. ! * Written by: Jesse Jones ! * ! * Copyright © 1998-1999 Jesse Jones. ! * This code is distributed under the zlib/libpng license (see License.txt for details). ! * ! * Change History (most recent first): ! * ! * $Log$ ! * Revision 1.6 2003/08/15 10:05:15 meeroh ! * Macro changes: ! * MAC -> TARGET_OS_MAC ! * WIN -> TARGET_OS_WIN32 ! * TARGET_CARBON -> TARGET_API_MAC_CARBON ! * BIG_ENDIAN -> TARGET_RT_BIG_ENDIAN ! * !BIG_ENDIAN -> TARGET_RT_LITTLE_ENDIAN ! * CODE_WARRIOR -> TARGET_CC_METROWERKS ! * __MWERKS__ -> TARGET_CC_METROWERKS ! * MSVC -> TARGET_CC_MICROSOFT ! * _MSC_VER -> TARGET_CC_MICROSOFT ! * #pragma mark ~ -> #pragma mark - ! * Added #ifdef PRAGMA_MARK ! * ! * Revision 1.5 2003/08/14 06:01:31 meeroh ! * Replaced FSSpecs with CFURLs/FSRefs ! * ! * Revision 1.4 2001/03/05 05:41:34 jesjones ! * Removed the dollar signs around the Log comment. ! * ! * Revision 1.3 2000/12/10 08:52:30 jesjones ! * Converted header comments to Doxygen format. ! * ! * Revision 1.2 2000/11/09 12:35:57 jesjones ! * 1) Removed double CRs introduced during the initial checkin. 2) Changed the header comments to make it clearer that Whisper is using the zlib license agreement. 3) Added the Log keyword. ! */ ! ! #pragma once ! ! #if TARGET_OS_MAC ! #include <Aliases.h> ! #include <Files.h> ! #include <Resources.h> ! #endif ! ! #include <XTypes.h> ! ! namespace Whisper { ! ! #if MULTI_FRAGMENT_APP && PRAGMA_EXPORT_SUPPORTED ! #pragma export on ! #endif ! ! ! //----------------------------------- ! // Forward References ! // ! class XFolderSpec; ! class XInStream; ! class XOutStream; ! ! ! // =================================================================================== ! // class XFileSystemSpec ! //! An object that points to a (possibly non-existent) file/folder. ! // =================================================================================== ! class FILES_EXPORT XFileSystemSpec { ! ! //----------------------------------- ! // Initialization/Destruction ! // ! public: ! virtual ~XFileSystemSpec(); ! ! XFileSystemSpec(); ! /**< Points to a bogus file. */ ! ! XFileSystemSpec(const OSFSSpec& spec); ! ! XFileSystemSpec(const XFolderSpec& folder, const std::wstring& fileName); ! ! #if TARGET_OS_MAC ! XFileSystemSpec(int16 volume, int32 parID, const std::wstring& fileName); ! ! XFileSystemSpec(const FSSpec& spec); ! ! XFileSystemSpec(const FSRef& ref); ! ! XFileSystemSpec(AliasHandle alias); ! ! explicit XFileSystemSpec(ResID aliasID); ! ! explicit XFileSystemSpec(const std::wstring& path); ! #endif ! ! //----------------------------------- ! // API ! // ! public: ! //! @name Conversion Operators ! //@{ ! // OSFSSpec& GetOSSpec() {return mSpec;} ! ! const OSFSSpec& GetOSSpec() const {return mSpec;} ! //@} ! ! //! @name Comparisons ! //@{ ! bool operator==(const XFileSystemSpec& rhs) const; ! ! bool operator!=(const XFileSystemSpec& rhs) const {return !this->operator==(rhs);} ! //@} ! ! //! @name Information ! //@{ ! std::wstring GetName() const; ! /**< Returns the name of the file/folder. */ ! ! std::wstring GetPrefix() const; ! /**< Returns the name sans extension. */ ! ! std::wstring GetExtension() const; ! /**< Returns the text after the last period (may be empty). ! Note that extensions are always returned as lower case. */ ! ! XFolderSpec GetParent() const; ! ! bool Exists () const; ! /**< Returnes true if this represents an existent file or folder */ ! ! OSVolume GetVolume() const; ! ! std::wstring GetPath() const; ! ! #if TARGET_OS_MAC ! MCFURL GetCFURL() const {return MCFURL(*mSpec, false);} ! ! const FSRef& GetFSRef() const; ! /**< Returns the FSRef if this represenents an existent file or folder */ ! ! FSSpec GetFSSpec() const; ! /**< Returns the FSSpec if this represenents an existent file or folder */ ! ! void ! GetCatalogInfo( ! FSCatalogInfoBitmap whichInfo, ! FSCatalogInfo* catalogInfo, ! HFSUniStr255* outName, ! FSSpec* fsSpec, ! FSRef* parentRef) const; ! /**< Gets catalog info if this represenents an existent file or folder, throws otherwise */ ! ! OSErr ! GetCatalogInfoErr( ! FSCatalogInfoBitmap whichInfo, ! FSCatalogInfo* catalogInfo, ! HFSUniStr255* outName, ! FSSpec* fsSpec, ! FSRef* parentRef) const; ! /**< Gets catalog info if this represenents an existent file or folder, returns error otherwise */ ! ! void ! SetCatalogInfo( ! FSCatalogInfoBitmap whichInfo, ! FSCatalogInfo* catalogInfo) const; ! /**< Sets catalog info if this represenents an existent file or folder, throws otherwise */ ! #endif ! //@} ! ! //! @name Streaming ! //@{ ! friend XInStream& operator>>(XInStream& stream, XFileSystemSpec& value); ! ! friend XOutStream& operator<<(XOutStream& stream, const XFileSystemSpec& value); ! //@} ! ! //----------------------------------- ! // Member Data ! // ! protected: ! #if TARGET_OS_MAC ! // On Mac OS, we can have the file spec, or the file ref, or both ! // Since converting from one to the other could be expensive, we create ! // them lazily. Calling GetOSSpec or GetFSRef may cause us to update ! // one or the other ! mutable OSFSSpec mSpec; ! ! // We cache the FSRef because it's expensive to convert ! // a CFURL to an FSRef ! mutable FSRef mFSRef; ! mutable bool mHaveFSRef; ! ! void InitWithOSFSSpec (const OSFSSpec& inSpec); ! void InitWithFSRef (const FSRef& inFSRef); ! void UpdateFSRef () const; ! void ClearFSRef () const; ! #endif ! ! #if TARGET_OS_WIN32 ! OSFSSpec mSpec; ! ! mutable std::wstring mLongName; ! #endif ! }; ! ! ! // =================================================================================== ! // Exception helpers ! // ! // =================================================================================== ! ! //--------------------------------------------------------------- ! // ThrowFileErr ! // ! FILES_EXPORT void ThrowFileErr(const XFileSystemSpec& spec, OSStatus err); ! ! //--------------------------------------------------------------- ! // ThrowIfFileErr ! // ! inline void ThrowIfFileErr(const XFileSystemSpec& spec, OSStatus err) ! { ! if (err != noErr) ! ThrowFileErr(spec, err); ! } ! ! #if MULTI_FRAGMENT_APP && PRAGMA_EXPORT_SUPPORTED ! #pragma export reset ! #endif ! ! } // namespace Whisper --- 1,4 ---- ! /* * File: XFileSystemSpec.h * Summary: An object that points to a (possibly non-existent) file/folder. * Written by: Jesse Jones * * Copyright © 1998-1999 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * $Log$ ! /* * File: XFileSystemSpec.h * Summary: An object that points to a (possibly non-existent) file/folder. * Written by: Jesse Jones * * Copyright © 1998-1999 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * Revision 1.7 2004/03/28 22:13:16 psnively ! /* * File: XFileSystemSpec.h * Summary: An object that points to a (possibly non-existent) file/folder. * Written by: Jesse Jones * * Copyright © 1998-1999 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * Minor code fixes to build on both Mac and Win32 again; fixes to project files to not cache like mad order things so precompiled headers work again. ! /* * File: XFileSystemSpec.h * Summary: An object that points to a (possibly non-existent) file/folder. * Written by: Jesse Jones * * Copyright © 1998-1999 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * * Revision 1.6 2003/08/15 10:05:15 meeroh * Macro changes: * MAC -> TARGET_OS_MAC * WIN -> TARGET_OS_WIN32 * TARGET_CARBON -> TARGET_API_MAC_CARBON * BIG_ENDIAN -> TARGET_RT_BIG_ENDIAN * !BIG_ENDIAN -> TARGET_RT_LITTLE_ENDIAN * CODE_WARRIOR -> TARGET_CC_METROWERKS * __MWERKS__ -> TARGET_CC_METROWERKS * MSVC -> TARGET_CC_MICROSOFT * _MSC_VER -> TARGET_CC_MICROSOFT * #pragma mark ~ -> #pragma mark - * Added #ifdef PRAGMA_MARK * * Revision 1.5 2003/08/14 06:01:31 meeroh * Replaced FSSpecs with CFURLs/FSRefs * * Revision 1.4 2001/03/05 05:41:34 jesjones * Removed the dollar signs around the Log comment. * * Revision 1.3 2000/12/10 08:52:30 jesjones * Converted header comments to Doxygen format. * * Revision 1.2 2000/11/09 12:35:57 jesjones * 1) Removed double CRs introduced during the initial checkin. 2) Changed the header comments to make it clearer that Whisper is using the zlib license agreement. 3) Added the Log keyword. */ #pragma once #if TARGET_OS_MAC #include <Aliases.h> #include <Files.h> #include <Resources.h> #endif #include <XTypes.h> namespace Whisper { #if MULTI_FRAGMENT_APP && PRAGMA_EXPORT_SUPPORTED #pragma export on #endif //----------------------------------- // Forward References // class XFolderSpec; class XInStream; class XOutStream; // =================================================================================== // class XFileSystemSpec //! An object that points to a (possibly non-existent) file/folder. // =================================================================================== class FILES_EXPORT XFileSystemSpec { //----------------------------------- // Initialization/Destruction // public: virtual ~XFileSystemSpec(); XFileSystemSpec(); /**< Points to a bogus file. */ XFileSystemSpec(const OSFSSpec& spec); XFileSystemSpec(const XFolderSpec& folder, const std::wstring& fileName); #if TARGET_OS_MAC XFileSystemSpec(int16 volume, int32 parID, const std::wstring& fileName); XFileSystemSpec(const FSSpec& spec); XFileSystemSpec(const FSRef& ref); XFileSystemSpec(AliasHandle alias); explicit XFileSystemSpec(ResID aliasID); explicit XFileSystemSpec(const std::wstring& path); #endif //----------------------------------- // API // public: //! @name Conversion Operators //@{ // OSFSSpec& GetOSSpec() {return mSpec;} const OSFSSpec& GetOSSpec() const {return mSpec;} //@} //! @name Comparisons //@{ bool operator==(const XFileSystemSpec& rhs) const; bool operator!=(const XFileSystemSpec& rhs) const {return !this->operator==(rhs);} //@} //! @name Information //@{ std::wstring GetName() const; /**< Returns the name of the file/folder. */ std::wstring GetPrefix() const; /**< Returns the name sans extension. */ std::wstring GetExtension() const; /**< Returns the text after the last period (may be empty). Note that extensions are always returned as lower case. */ XFolderSpec GetParent() const; bool Exists () const; /**< Returnes true if this represents an existent file or folder */ OSVolume GetVolume() const; std::wstring GetPath() const; #if TARGET_OS_MAC MCFURL GetCFURL() const {return MCFURL(*mSpec, false);} const FSRef& GetFSRef() const; /**< Returns the FSRef if this represenents an existent file or folder */ FSSpec GetFSSpec() const; /**< Returns the FSSpec if this represenents an existent file or folder */ void GetCatalogInfo( FSCatalogInfoBitmap whichInfo, FSCatalogInfo* catalogInfo, HFSUniStr255* outName, FSSpec* fsSpec, FSRef* parentRef) const; /**< Gets catalog info if this represenents an existent file or folder, throws otherwise */ OSErr GetCatalogInfoErr( FSCatalogInfoBitmap whichInfo, FSCatalogInfo* catalogInfo, HFSUniStr255* outName, FSSpec* fsSpec, FSRef* parentRef) const; /**< Gets catalog info if this represenents an existent file or folder, returns error otherwise */ void SetCatalogInfo( FSCatalogInfoBitmap whichInfo, FSCatalogInfo* catalogInfo) const; /**< Sets catalog info if this represenents an existent file or folder, throws otherwise */ #endif //@} //! @name Streaming //@{ friend XInStream& operator>>(XInStream& stream, XFileSystemSpec& value); friend XOutStream& operator<<(XOutStream& stream, const XFileSystemSpec& value); //@} //----------------------------------- // Member Data // protected: #if TARGET_OS_MAC // On Mac OS, we can have the file spec, or the file ref, or both // Since converting from one to the other could be expensive, we create // them lazily. Calling GetOSSpec or GetFSRef may cause us to update // one or the other mutable OSFSSpec mSpec; // We cache the FSRef because it's expensive to convert // a CFURL to an FSRef mutable FSRef mFSRef; mutable bool mHaveFSRef; void InitWithOSFSSpec (const OSFSSpec& inSpec); void InitWithFSRef (const FSRef& inFSRef); void UpdateFSRef () const; void ClearFSRef () const; #endif #if TARGET_OS_WIN32 OSFSSpec mSpec; mutable std::wstring mLongName; #endif }; // =================================================================================== // Exception helpers // // =================================================================================== #if TARGET_OS_MAC //--------------------------------------------------------------- // ThrowFileErr // FILES_EXPORT void ThrowFileErr(const XFileSystemSpec& spec, OSStatus err); //--------------------------------------------------------------- // ThrowIfFileErr // inline void ThrowIfFileErr(const XFileSystemSpec& spec, OSStatus err) { if (err != noErr) ThrowFileErr(spec, err); } #endif #if MULTI_FRAGMENT_APP && PRAGMA_EXPORT_SUPPORTED #pragma export reset #endif } // namespace Whisper \ No newline at end of file Index: XMemoryMappedFile.h =================================================================== RCS file: /cvsroot/whisper2/Whisper/Source/BackEnd/Files/Source/Files/XMemoryMappedFile.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** XMemoryMappedFile.h 15 Aug 2003 10:08:06 -0000 1.8 --- XMemoryMappedFile.h 28 Mar 2004 22:13:16 -0000 1.9 *************** *** 1,174 **** ! /* ! * File: XMemoryMappedFile.h ! * Summary: A class that allows a file to be efficiently treated as a bag'o'bits. ! * Written by: Jesse Jones ! * ! * Copyright © 1999-2001 Jesse Jones. ! * This code is distributed under the zlib/libpng license (see License.txt for details). ! * ! * Change History (most recent first): ! * ! * $Log$ ! * Revision 1.8 2003/08/15 10:08:06 meeroh ! * Macro changes: ! * MAC -> TARGET_OS_MAC ! * WIN -> TARGET_OS_WIN32 ! * TARGET_CARBON -> TARGET_API_MAC_CARBON ! * BIG_ENDIAN -> TARGET_RT_BIG_ENDIAN ! * !BIG_ENDIAN -> TARGET_RT_LITTLE_ENDIAN ! * CODE_WARRIOR -> TARGET_CC_METROWERKS ! * __MWERKS__ -> TARGET_CC_METROWERKS ! * MSVC -> TARGET_CC_MICROSOFT ! * _MSC_VER -> TARGET_CC_MICROSOFT ! * #pragma mark ~ -> #pragma mark - ! * Added #ifdef PRAGMA_MARK ! * ! * Revision 1.7 2003/08/14 06:01:58 meeroh ! * Replaced FSSpecs with CFURLs/FSRefs ! * ! * Revision 1.6 2003/03/16 02:46:08 psnively ! * Updates for CW Pro 8.3 and new zlib/libpng ! * ! * Revision 1.5 2001/04/17 01:44:26 jesjones ! * Got rid of XInvariantMixin. ! * ! * Revision 1.4 2001/03/05 05:42:39 jesjones ! * Removed the dollar signs around the Log comment. ! * ! * Revision 1.3 2000/12/10 08:54:04 jesjones ! * Converted header comments to Doxygen format. ! * ! * Revision 1.2 2000/11/09 12:42:38 jesjones ! * 1) Removed double CRs introduced during the initial checkin. 2) Changed the header comments to make it clearer that Whisper is using the zlib license agreement. 3) Added the Log keyword. ! */ ! ! #pragma once ! ! #include <XFile.h> ! #include <XLockable.h> ! ! namespace Whisper { ! ! #if MULTI_FRAGMENT_APP && PRAGMA_EXPORT_SUPPORTED ! #pragma export on ! #endif ! ! ! // =================================================================================== ! // class XMemoryMappedFile ! //! A class that allows a file to be efficiently treated as a bag'o'bits. ! // =================================================================================== ! class FILES_EXPORT XMemoryMappedFile : public XLockableMixin { ! ! //----------------------------------- ! // Initialization/Destruction ! // ! public: ! virtual ~XMemoryMappedFile(); ! /**< ASSERTs if the file is still open (however it will close ! the file if it's open to make it easier to write exception ! safe code). */ ! ! explicit XMemoryMappedFile(const XFileSpec& file); ! ! XMemoryMappedFile(const XFolderSpec& folder, const std::wstring& fileName); ! ! private: ! XMemoryMappedFile(const XMemoryMappedFile& rhs); ! ! XMemoryMappedFile& operator=(const XMemoryMappedFile& rhs); ! ! //----------------------------------- ! // New API ! // ! public: ! //! @name Open/Close ! //@{ ! void Open(EFilePermission perm, uint32 maxBytes = 0); ! /**< File should already exist. maxBytes is used with writeable files. If it's ! zero the file cannot be expanded. It can be set to an arbitrarily large ! value for growable files, but if enough memory (Mac) or swap file space ! (Win) cannot be found an exception will be thrown. */ ! ! void Open(OSType creator, OSType fileType, EFilePermission perm, uint32 maxBytes = 0); ! /**< Creates the file if it doesn't already exist. ! Perm can be kReadPermission, kWritePermission, or kReadWritePermission. ! creator and fileType are ignored on Windows. */ ! ! void Close(); ! void Close(uint32 newSize); ! /**< May throw an exception. For growable files you may specify the final file size. */ ! ! bool IsOpened() const; ! //@} ! ! //! @name Read/Write ! //@{ ! uint8* GetBuffer(); ! const uint8* GetBuffer() const {return const_cast<XMemoryMappedFile*>(this)->GetBuffer();} ! /**< File must be locked. */ ! ! uint32 GetBufferSize() const; ! /**< Returns the size in bytes of the buffer. The file must be open. */ ! ! void Flush(); ! //@} ! ! //! @name Misc ! //@{ ! XFileSpec GetSpec() const {return mFile.GetSpec();} ! ! #if TARGET_OS_MAC ! void EnablePurging(bool enable = true); ! /**< On the Mac the buffer is allocated in temp memory when possible. ! In order to work well with other app's the handle defaults to ! purgeable (for read-only files), but you can disable purging with ! this method. */ ! #endif ! //@} ! ! //----------------------------------- ! // Inherited API ! // ! protected: ! friend class ZCheckInvariant; ! void Invariant() const; ! ! virtual void OnLock(bool moveHigh); ! ! virtual void OnUnlock(); ! ! //----------------------------------- ! // Internal API ! // ! protected: ! void DoOpen(EFilePermission perm, uint32 flags, uint32 maxBytes); ! ! //----------------------------------- ! // Member Data ! // ! protected: ! XFile mFile; ! bool mWriting; ! uint32 mMaxBytes; ! ! #if TARGET_OS_MAC ! // int16 mRefNum; ! bool mReading; ! Handle mData; // purgable handle allocated in temp memory (or app memory if temp memory is exhausted) ! ! bool mPurgable; ! ! #elif TARGET_OS_WIN32 ! HANDLE mFileHandle; ! HANDLE mMapHandle; ! void* mData; ! #endif ! }; ! ! ! #if MULTI_FRAGMENT_APP && PRAGMA_EXPORT_SUPPORTED ! #pragma export reset ! #endif ! ! } // namespace Whisper --- 1,4 ---- ! /* * File: XMemoryMappedFile.h * Summary: A class that allows a file to be efficiently treated as a bag'o'bits. * Written by: Jesse Jones * * Copyright © 1999-2001 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * $Log$ ! /* * File: XMemoryMappedFile.h * Summary: A class that allows a file to be efficiently treated as a bag'o'bits. * Written by: Jesse Jones * * Copyright © 1999-2001 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * Revision 1.9 2004/03/28 22:13:16 psnively ! /* * File: XMemoryMappedFile.h * Summary: A class that allows a file to be efficiently treated as a bag'o'bits. * Written by: Jesse Jones * * Copyright © 1999-2001 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * Minor code fixes to build on both Mac and Win32 again; fixes to project files to not cache like mad order things so precompiled headers work again. ! /* * File: XMemoryMappedFile.h * Summary: A class that allows a file to be efficiently treated as a bag'o'bits. * Written by: Jesse Jones * * Copyright © 1999-2001 Jesse Jones. * This code is distributed under the zlib/libpng license (see License.txt for details). * * Change History (most recent first): * * * Revision 1.8 2003/08/15 10:08:06 meeroh * Macro changes: * MAC -> TARGET_OS_MAC * WIN -> TARGET_OS_WIN32 * TARGET_CARBON -> TARGET_API_MAC_CARBON * BIG_ENDIAN -> TARGET_RT_BIG_ENDIAN * !BIG_ENDIAN -> TARGET_RT_LITTLE_ENDIAN * CODE_WARRIOR -> TARGET_CC_METROWERKS * __MWERKS__ -> TARGET_CC_METROWERKS * MSVC -> TARGET_CC_MICROSOFT * _MSC_VER -> TARGET_CC_MICROSOFT * #pragma mark ~ -> #pragma mark - * Added #ifdef PRAGMA_MARK * * Revision 1.7 2003/08/14 06:01:58 meeroh * Replaced FSSpecs with CFURLs/FSRefs * * Revision 1.6 2003/03/16 02:46:08 psnively * Updates for CW Pro 8.3 and new zlib/libpng * * Revision 1.5 2001/04/17 01:44:26 jesjones * Got rid of XInvariantMixin. * * Revision 1.4 2001/03/05 05:42:39 jesjones * Removed the dollar signs around the Log comment. * * Revision 1.3 2000/12/10 08:54:04 jesjones * Converted header comments to Doxygen format. * * Revision 1.2 2000/11/09 12:42:38 jesjones * 1) Removed double CRs introduced during the initial checkin. 2) Changed the header comments to make it clearer that Whisper is using the zlib license agreement. 3) Added the Log keyword. */ #pragma once #include <XFile.h> #include <XLockable.h> namespace Whisper { #if MULTI_FRAGMENT_APP && PRAGMA_EXPORT_SUPPORTED #pragma export on #endif // =================================================================================== // class XMemoryMappedFile //! A class that allows a file to be efficiently treated as a bag'o'bits. // =================================================================================== class FILES_EXPORT XMemoryMappedFile : public XLockableMixin { //----------------------------------- // Initialization/Destruction // public: virtual ~XMemoryMappedFile(); /**< ASSERTs if the file is still open (however it will close the file if it's open to make it easier to write exception safe code). */ explicit XMemoryMappedFile(const XFileSpec& file); XMemoryMappedFile(const XFolderSpec& folder, const std::wstring& fileName); private: XMemoryMappedFile(const XMemoryMappedFile& rhs); XMemoryMappedFile& operator=(const XMemoryMappedFile& rhs); //----------------------------------- // New API // public: //! @name Open/Close //@{ void Open(EFilePermission perm, uint32 maxBytes = 0); /**< File should already exist. maxBytes is used with writeable files. If it's zero the file cannot be expanded. It can be set to an arbitrarily large value for growable files, but if enough memory (Mac) or swap file space (Win) cannot be found an exception will be thrown. */ void Open(OSType creator, OSType fileType, EFilePermission perm, uint32 maxBytes = 0); /**< Creates the file if it doesn't already exist. Perm can be kReadPermission, kWritePermission, or kReadWritePermission. creator and fileType are ignored on Windows. */ void Close(); void Close(uint32 newSize); /**< May throw an exception. For growable files you may specify the final file size. */ bool IsOpened() const; //@} //! @name Read/Write //@{ uint8* GetBuffer(); const uint8* GetBuffer() const {return const_cast<XMemoryMappedFile*>(this)->GetBuffer();} /**< File must be locked. */ uint32 GetBufferSize() const; /**< Returns the size in bytes of the buffer. The file must be open. */ void Flush(); //@} //! @name Misc //@{ XFileSpec GetSpec() const {return mFile.GetSpec();} #if TARGET_OS_MAC void EnablePurging(bool enable = true); /**< On the Mac the buffer is allocated in temp memory when possible. In order to work well with other app's the handle defaults to purgeable (for read-only files), but you can disable purging with this method. */ #endif //@} //----------------------------------- // Inherited API // protected: friend class ZCheckInvariant; void Invariant() const; virtual void OnLock(bool moveHigh); virtual void OnUnlock(); //----------------------------------- // Internal API // protected: void DoOpen(EFilePermission perm, uint32 flags, uint32 maxBytes); //----------------------------------- // Member Data // protected: XFile mFile; bool mWriting; uint32 mMaxBytes; #if TARGET_OS_MAC // int16 mRefNum; bool mReading; Handle mData; // purgable handle allocated in temp memory (or app memory if temp memory is exhausted) bool mPurgable; #elif TARGET_OS_WIN32 HANDLE mFileHandle; HANDLE mMapHandle; void* mData; #endif }; #if MULTI_FRAGMENT_APP && PRAGMA_EXPORT_SUPPORTED #pragma export reset #endif } // namespace Whisper \ No newline at end of file |