cpl_vsi_virtual.h

00001 /******************************************************************************
00002  * $Id: cpl_vsi_virtual.h 20028 2010-07-11 18:20:55Z rouault $
00003  *
00004  * Project:  VSI Virtual File System
00005  * Purpose:  Declarations for classes related to the virtual filesystem.
00006  *           These would only be normally required by applications implmenting
00007  *           their own virtual file system classes which should be rare.  
00008  *           The class interface may be fragile through versions.
00009  * Author:   Frank Warmerdam, warmerdam@pobox.com
00010  *
00011  ******************************************************************************
00012  * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
00013  *
00014  * Permission is hereby granted, free of charge, to any person obtaining a
00015  * copy of this software and associated documentation files (the "Software"),
00016  * to deal in the Software without restriction, including without limitation
00017  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00018  * and/or sell copies of the Software, and to permit persons to whom the
00019  * Software is furnished to do so, subject to the following conditions:
00020  *
00021  * The above copyright notice and this permission notice shall be included
00022  * in all copies or substantial portions of the Software.
00023  *
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00025  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00026  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00027  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00028  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00029  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00030  * DEALINGS IN THE SOFTWARE.
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) /* Remove annoying warnings in eVC++ and VC++ 6.0 */
00043 #endif
00044 
00045 #include <map>
00046 #include <vector>
00047 #include <string>
00048 
00049 /************************************************************************/
00050 /*                           VSIVirtualHandle                           */
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 size_t    Write( const void *pBuffer, size_t nSize,size_t nMemb)=0;
00059     virtual int       Eof() = 0;
00060     virtual int       Flush() {return 0;}
00061     virtual int       Close() = 0;
00062     virtual           ~VSIVirtualHandle() { }
00063 };
00064 
00065 /************************************************************************/
00066 /*                         VSIFilesystemHandler                         */
00067 /************************************************************************/
00068 
00069 class CPL_DLL VSIFilesystemHandler {
00070 
00071 public:
00072 
00073     virtual ~VSIFilesystemHandler() {}
00074 
00075     virtual VSIVirtualHandle *Open( const char *pszFilename, 
00076                                     const char *pszAccess) = 0;
00077     virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf) = 0;
00078     virtual int Unlink( const char *pszFilename )
00079                       { errno=ENOENT; return -1; }
00080     virtual int Mkdir( const char *pszDirname, long nMode ) 
00081                      { errno=ENOENT; return -1; }
00082     virtual int Rmdir( const char *pszDirname ) 
00083                      { errno=ENOENT; return -1; }
00084     virtual char **ReadDir( const char *pszDirname ) 
00085                           { return NULL; }
00086     virtual int Rename( const char *oldpath, const char *newpath )
00087                       { errno=ENOENT; return -1; }
00088 };
00089 
00090 /************************************************************************/
00091 /*                            VSIFileManager                            */
00092 /************************************************************************/
00093 
00094 class CPL_DLL VSIFileManager 
00095 {
00096 private:
00097     VSIFilesystemHandler *poDefaultHandler;
00098     std::map<std::string, VSIFilesystemHandler *> oHandlers;
00099 
00100     VSIFileManager();
00101 
00102     static VSIFileManager *Get();
00103 
00104 public:
00105     ~VSIFileManager();
00106 
00107     static VSIFilesystemHandler *GetHandler( const char * );
00108     static void InstallHandler( const std::string& osPrefix, 
00109                                 VSIFilesystemHandler * );
00110     static void RemoveHandler( const std::string& osPrefix );
00111 };
00112 
00113 
00114 /************************************************************************/
00115 /* ==================================================================== */
00116 /*                       VSIArchiveFilesystemHandler                   */
00117 /* ==================================================================== */
00118 /************************************************************************/
00119 
00120 class VSIArchiveEntryFileOffset
00121 {
00122     public:
00123         virtual ~VSIArchiveEntryFileOffset();
00124 };
00125 
00126 typedef struct
00127 {
00128     char         *fileName;
00129     vsi_l_offset  uncompressed_size;
00130     VSIArchiveEntryFileOffset*      file_pos;
00131     int           bIsDir;
00132     GIntBig       nModifiedTime;
00133 } VSIArchiveEntry;
00134 
00135 typedef struct
00136 {
00137     int nEntries;
00138     VSIArchiveEntry* entries;
00139 } VSIArchiveContent;
00140 
00141 class VSIArchiveReader
00142 {
00143     public:
00144         virtual ~VSIArchiveReader();
00145 
00146         virtual int GotoFirstFile() = 0;
00147         virtual int GotoNextFile() = 0;
00148         virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
00149         virtual GUIntBig GetFileSize() = 0;
00150         virtual CPLString GetFileName() = 0;
00151         virtual GIntBig GetModifiedTime() = 0;
00152         virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
00153 };
00154 
00155 class VSIArchiveFilesystemHandler : public VSIFilesystemHandler 
00156 {
00157 private:
00158     void* hMutex;
00159     /* We use a cache that contains the list of files containes in a VSIArchive file as */
00160     /* unarchive.c is quite inefficient in listing them. This speeds up access to VSIArchive files */
00161     /* containing ~1000 files like a CADRG product */
00162     std::map<CPLString,VSIArchiveContent*>   oFileList;
00163 
00164     virtual const char* GetPrefix() = 0;
00165     virtual std::vector<CPLString> GetExtensions() = 0;
00166     virtual VSIArchiveReader* CreateReader(const char* pszArchiveFileName) = 0;
00167 
00168 public:
00169     VSIArchiveFilesystemHandler();
00170     virtual ~VSIArchiveFilesystemHandler();
00171 
00172     virtual int      Stat( const char *pszFilename, VSIStatBufL *pStatBuf );
00173     virtual int      Unlink( const char *pszFilename );
00174     virtual int      Rename( const char *oldpath, const char *newpath );
00175     virtual int      Mkdir( const char *pszDirname, long nMode );
00176     virtual int      Rmdir( const char *pszDirname );
00177     virtual char   **ReadDir( const char *pszDirname );
00178 
00179     virtual const VSIArchiveContent* GetContentOfArchive(const char* archiveFilename, VSIArchiveReader* poReader = NULL);
00180     virtual char* SplitFilename(const char *pszFilename, CPLString &osFileInArchive);
00181     virtual VSIArchiveReader* OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName);
00182     virtual int FindFileInArchive(const char* archiveFilename, const char* fileInArchiveName, const VSIArchiveEntry** archiveEntry);
00183 };
00184 
00185 VSIVirtualHandle* VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle);
00186 
00187 #endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */

Generated for GDAL by doxygen 1.5.6.