Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# deFile.hpp

Go to the documentation of this file.

    00001 ///////////////////////////////////////////////////////////////////////////////
    00002 /// @file deFile.hpp
    00003 ///
    00004 /// @brief basic file interface header
    00005 ///
    00006 /// @author Lightning
    00007 ///
    00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
    00009 /// contents of this file is subject to the Destiny3D Member License which
    00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
    00011 ///
    00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
    00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
    00014 /// for any particular purpose.
    00015 ///
    00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
    00017 ///
    00018 /// <hr>
    00019 ///                                 Change History
    00020 /// <hr>
    00021 ///
    00022 /// @date May 2003
    00023 /// @author Lightning
    00024 /// @remarks Creation
    00025 ///
    00026 ///////////////////////////////////////////////////////////////////////////////
    00027
    00028 #ifndef DE_FILE_HPP
    00029 #define DE_FILE_HPP
    00030
    00031 #include "deGlobalTypes.hpp"
    00032
    00033 #if defined(DEFILE_DLL_EXPORTS) || defined(DESTINY3D_EXPORT_ALL)
    00034 #   define DEFILE_API extern "C" DEDLL_EXPORT
    00035 #elif defined(DESTINY3D_STATIC_LINK)
    00036 #   define DEFILE_API extern "C"
    00037 #else
    00038 #   define DEFILE_API extern "C" DEDLL_IMPORT
    00039 #endif
    00040
    00041 #ifdef USING_DESTINY3D
    00042 #ifdef _DEBUG
    00043 #   ifdef DESTINY3D_STATIC_LINK
    00044 #       pragma comment(lib, "deFile_sd")
    00045 #   else
    00046 #       pragma comment(lib, "deFiled")
    00047 #   endif //DESTINY3D_STATIC_LINK
    00048 #else
    00049 #   ifdef DESTINY3D_STATIC_LINK
    00050 #       pragma comment(lib, "deFile_s")
    00051 #   else
    00052 #       pragma comment(lib, "deFile")
    00053 #   endif //DESTINY3D_STATIC_LINK
    00054 #endif //_DEBUG
    00055 #endif //USING_DESTINY3D
    00056
    00057 //-------------------------------------------
    00058 // Classes Declared
    00059 //-------------------------------------------
    00060 class IdeFile;
    00061 class IdeFileMemory;
    00062 class IdeFilePlugin;
    00063 class IdeFileVirtual;
    00064 class IdeFileReal;
    00065
    00066 class IdePlugin;
    00067 class IdeFileSystem;
    00068
    00069 //-------------------------------------------
    00070 // Factory functions
    00071 //-------------------------------------------
    00072 extern "C"
    00073 {
    00074     // use IdeFSReal::Open to create IdeFileReal instances
    00075     /// create a "memory file" - a file that exists only in application memory
    00076     DEFILE_API IdeFileMemory*   IdeFile_CreateFileMemory();
    00077     /// create a "plugin file" - one that can perform special plugin actions on other files
    00078     DEFILE_API IdeFilePlugin*   IdeFile_CreateFilePlugin();
    00079 }
    00080
    00081 //-------------------------------------------
    00082 // Structures
    00083 //-------------------------------------------
    00084
    00085 /// information about a file's properties
    00086 typedef struct deFileProperties
    00087 {
    00088     const char *    Filename;   ///< filename of the file
    00089     unsigned long   Size;       ///< size of the file (note, if a plugin is applied then this will not be accurate)
    00090     s64             Time;       ///< date/time of the file (seconds from Jan 01, 1970 of course)
    00091     long            Flags;      ///< flags about the file
    00092 } deFileProperties;
    00093
    00094 //-------------------------------------------
    00095 // Defines & Constants
    00096 //-------------------------------------------
    00097
    00098 //some defines for easy access to the seeks
    00099 #define deFile_Seek_Start       IdeFile::SEEKF_START
    00100 #define deFile_Seek_End         IdeFile::SEEKF_END
    00101 #define deFile_Seek_Current     IdeFile::SEEKF_CURRENT
    00102
    00103 //open flags that a file can implemente
    00104 const long deFile_Open_Create       =0x00000001;    ///<create file, fail if it exists
    00105 const long deFile_Open_Existing     =0x00000002;    ///<open existing file, fail if it does not exist
    00106 const long deFile_Open_Always       =0x00000003;    ///<always open, create if it does not exist
    00107 const long deFile_Open_CreateAlways =0x00000004;    ///<always create the file, overwrite if it exists
    00108
    00109 //if the file is read/write
    00110 const long deFile_Open_Read         =0x00000010;    ///open for reading
    00111 const long deFile_Open_Write        =0x00000020;    ///open for writing
    00112
    00113 //property flags for a deFileProperties.Flags entry
    00114 const long deFile_Directory     =0x00000001;
    00115
    00116 //-------------------------------------------
    00117 // Classes
    00118 //-------------------------------------------
    00119
    00120 /// general interface class to allow simple usage of the file returned from a file system.
    00121 //class IdeFile
    00122 DE3D_INTERFACE_(IdeFile)
    00123 {
    00124     protected:
    00125         virtual ~IdeFile() {}
    00126
    00127     public:
    00128         enum Seek
    00129         {
    00130             SEEKF_START = 0,        ///< start of a file
    00131             SEEKF_END,              ///< end of a file
    00132             SEEKF_CURRENT,          ///< current file pos
    00133             SEEK_COUNT,
    00134             SEEK_FORCE_32BIT = 0x7FFFFFFF
    00135         };
    00136
    00137         enum interface_t
    00138         {
    00139             iface_IdeFile = 0,
    00140             iface_IdeFileReal,
    00141             iface_IdeFileMemory,
    00142             iface_IdeFileVirtual,
    00143             iface_IdeFilePlugin,
    00144             iface_force_32bit = 0x7FFFFFFF
    00145         };
    00146         virtual void* GetInterface(IdeFile::interface_t i) = 0;
    00147
    00148         //close a file to release it
    00149         virtual int Release() = 0;
    00150
    00151         ///open a file
    00152         virtual deBoolean Open(IdeFileSystem *BaseFS, char *Filename, long OpenFlags) = 0;
    00153
    00154         ///close an open file
    00155         virtual deBoolean Close() = 0;
    00156
    00157         ///read a file
    00158         virtual long Read(void *Buffer, long Length) = 0;
    00159         ///write a file
    00160         virtual long Write(void *Buffer, long Length) = 0;
    00161
    00162         ///get file position
    00163         virtual long GetPosition() = 0;
    00164         ///set file position
    00165         virtual long SetPosition(long NewPosition, IdeFile::Seek SeekType) = 0;
    00166
    00167         ///get a file's size
    00168         virtual long GetSize() = 0;
    00169         ///set a file's length
    00170         virtual deBoolean SetSize(long NewSize) = 0;
    00171
    00172         ///get a file's date/time
    00173         virtual s64 GetTime() = 0;
    00174         ///set a file's date/time
    00175         virtual deBoolean SetTime(s64 Time) = 0;
    00176
    00177         ///get current file's properties
    00178         virtual deBoolean GetProperties(deFileProperties *Properties) = 0;
    00179
    00180         ///get the open flags
    00181         virtual long GetOpenFlags() = 0;
    00182 };
    00183
    00184 /// interface class for the memory file.
    00185 /// Related functions: IdeFile_CreateFileMemory
    00186 //class IdeFileMemory : virtual public IdeFile
    00187 DE3D_INTERFACE(IdeFileMemory, IdeFile)
    00188 {
    00189     protected:
    00190         ~IdeFileMemory() {}
    00191
    00192     public:
    00193         //open up a new memory file, if they tell us a buffer then it is read-only, otherwise
    00194         //data is read/write
    00195         virtual deBoolean Open() = 0;
    00196         virtual deBoolean Open(long Length) = 0;
    00197         virtual deBoolean Open(void *Buffer, long Length) = 0;
    00198         virtual deBoolean Open(IdeFile *BaseFile) = 0;
    00199
    00200         //MSVC requires that if 1 function has the same name here, any other virtual function
    00201         //in the base class with the same name must also be defined
    00202         //note from Assassin: COM classes aren't meant to have virtual functions with same name
    00203         virtual deBoolean Open(IdeFileSystem *BaseFS, char *Filename, long OpenFlags) = 0;
    00204 };
    00205
    00206 /// interface class for the virtual file.
    00207 //class IdeFileVirtual : virtual public IdeFile
    00208 DE3D_INTERFACE(IdeFileVirtual, IdeFile)
    00209 {
    00210     protected:
    00211         ~IdeFileVirtual() {}
    00212 };
    00213
    00214 /// interface class for the real (OS) file.
    00215 /// Related classes: IdeFSReal
    00216 //class IdeFileReal : virtual public IdeFile
    00217 DE3D_INTERFACE(IdeFileReal, IdeFile)
    00218 {
    00219     protected:
    00220         ~IdeFileReal() {}
    00221 };
    00222
    00223 /// interface class for the plugin file.
    00224 /// Related functions: IdeFile_CreateFilePlugin
    00225 //class IdeFilePlugin : virtual public IdeFile
    00226 DE3D_INTERFACE(IdeFilePlugin, IdeFile)
    00227 {
    00228     protected:
    00229         ~IdeFilePlugin() {}
    00230
    00231     public:
    00232         virtual deBoolean Open(IdeFile *BaseFile) = 0;
    00233
    00234         //MSVC requires that if 1 function has the same name here, any other virtual function
    00235         //in the base class with the same name must also be defined
    00236         //note from Assassin: COM classes aren't meant to have virtual functions with same name
    00237         virtual deBoolean Open(IdeFileSystem *BaseFS, char *Filename, long OpenFlags) = 0;
    00238
    00239         virtual deBoolean AddPlugin(IdePlugin *Plugin) = 0;
    00240         virtual deBoolean ReleasePlugin(IdePlugin *Plugin) = 0;
    00241         virtual deBoolean ReleaseAllPlugins() = 0;
    00242
    00243         //order all the blocks in the file
    00244         virtual deBoolean DefragFile() = 0;
    00245 };
    00246
    00247 #endif
    00248