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