00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef CPL_VSI_VIRTUAL_H_INCLUDED
00035 #define CPL_VSI_VIRTUAL_H_INCLUDED
00036
00037 #include "cpl_vsi.h"
00038 #include "cpl_string.h"
00039
00040 #if defined(WIN32CE)
00041 # include "cpl_wince.h"
00042 # include <wce_errno.h>
00043 # pragma warning(disable:4786)
00044 #endif
00045
00046 #include <map>
00047 #include <vector>
00048 #include <string>
00049
00050
00051
00052
00053
00054 class CPL_DLL VSIVirtualHandle {
00055 public:
00056 virtual int Seek( vsi_l_offset nOffset, int nWhence ) = 0;
00057 virtual vsi_l_offset Tell() = 0;
00058 virtual size_t Read( void *pBuffer, size_t nSize, size_t nMemb ) = 0;
00059 virtual int ReadMultiRange( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes );
00060 virtual size_t Write( const void *pBuffer, size_t nSize,size_t nMemb)=0;
00061 virtual int Eof() = 0;
00062 virtual int Flush() {return 0;}
00063 virtual int Close() = 0;
00064 virtual int Truncate( vsi_l_offset nNewSize ) { return -1; }
00065 virtual void *GetNativeFileDescriptor() { return NULL; }
00066 virtual ~VSIVirtualHandle() { }
00067 };
00068
00069
00070
00071
00072
00073 class CPL_DLL VSIFilesystemHandler {
00074
00075 public:
00076
00077 virtual ~VSIFilesystemHandler() {}
00078
00079 virtual VSIVirtualHandle *Open( const char *pszFilename,
00080 const char *pszAccess) = 0;
00081 virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags) = 0;
00082 virtual int Unlink( const char *pszFilename )
00083 { (void) pszFilename; errno=ENOENT; return -1; }
00084 virtual int Mkdir( const char *pszDirname, long nMode )
00085 {(void)pszDirname; (void)nMode; errno=ENOENT; return -1;}
00086 virtual int Rmdir( const char *pszDirname )
00087 { (void) pszDirname; errno=ENOENT; return -1; }
00088 virtual char **ReadDir( const char *pszDirname )
00089 { (void) pszDirname; return NULL; }
00090 virtual int Rename( const char *oldpath, const char *newpath )
00091 { (void) oldpath; (void)newpath; errno=ENOENT; return -1; }
00092 virtual int IsCaseSensitive( const char* pszFilename )
00093 { (void) pszFilename; return TRUE; }
00094 };
00095
00096
00097
00098
00099
00100 class CPL_DLL VSIFileManager
00101 {
00102 private:
00103 VSIFilesystemHandler *poDefaultHandler;
00104 std::map<std::string, VSIFilesystemHandler *> oHandlers;
00105
00106 VSIFileManager();
00107
00108 static VSIFileManager *Get();
00109
00110 public:
00111 ~VSIFileManager();
00112
00113 static VSIFilesystemHandler *GetHandler( const char * );
00114 static void InstallHandler( const std::string& osPrefix,
00115 VSIFilesystemHandler * );
00116 static void RemoveHandler( const std::string& osPrefix );
00117 };
00118
00119
00120
00121
00122
00123
00124
00125
00126 class VSIArchiveEntryFileOffset
00127 {
00128 public:
00129 virtual ~VSIArchiveEntryFileOffset();
00130 };
00131
00132 typedef struct
00133 {
00134 char *fileName;
00135 vsi_l_offset uncompressed_size;
00136 VSIArchiveEntryFileOffset* file_pos;
00137 int bIsDir;
00138 GIntBig nModifiedTime;
00139 } VSIArchiveEntry;
00140
00141 typedef struct
00142 {
00143 int nEntries;
00144 VSIArchiveEntry* entries;
00145 } VSIArchiveContent;
00146
00147 class VSIArchiveReader
00148 {
00149 public:
00150 virtual ~VSIArchiveReader();
00151
00152 virtual int GotoFirstFile() = 0;
00153 virtual int GotoNextFile() = 0;
00154 virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
00155 virtual GUIntBig GetFileSize() = 0;
00156 virtual CPLString GetFileName() = 0;
00157 virtual GIntBig GetModifiedTime() = 0;
00158 virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
00159 };
00160
00161 class VSIArchiveFilesystemHandler : public VSIFilesystemHandler
00162 {
00163 protected:
00164 void* hMutex;
00165
00166
00167
00168 std::map<CPLString,VSIArchiveContent*> oFileList;
00169
00170 virtual const char* GetPrefix() = 0;
00171 virtual std::vector<CPLString> GetExtensions() = 0;
00172 virtual VSIArchiveReader* CreateReader(const char* pszArchiveFileName) = 0;
00173
00174 public:
00175 VSIArchiveFilesystemHandler();
00176 virtual ~VSIArchiveFilesystemHandler();
00177
00178 virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags );
00179 virtual int Unlink( const char *pszFilename );
00180 virtual int Rename( const char *oldpath, const char *newpath );
00181 virtual int Mkdir( const char *pszDirname, long nMode );
00182 virtual int Rmdir( const char *pszDirname );
00183 virtual char **ReadDir( const char *pszDirname );
00184
00185 virtual const VSIArchiveContent* GetContentOfArchive(const char* archiveFilename, VSIArchiveReader* poReader = NULL);
00186 virtual char* SplitFilename(const char *pszFilename, CPLString &osFileInArchive, int bCheckMainFileExists);
00187 virtual VSIArchiveReader* OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName);
00188 virtual int FindFileInArchive(const char* archiveFilename, const char* fileInArchiveName, const VSIArchiveEntry** archiveEntry);
00189 };
00190
00191 VSIVirtualHandle* VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle);
00192 VSIVirtualHandle* VSICreateCachedFile( VSIVirtualHandle* poBaseHandle, size_t nChunkSize = 32768, size_t nCacheSize = 0 );
00193 VSIVirtualHandle* VSICreateGZipWritable( VSIVirtualHandle* poBaseHandle, int bRegularZLibIn, int bAutoCloseBaseHandle );
00194
00195 #endif