# cpl_vsi_virtual.h

    00001 /******************************************************************************
    00002  * $Id: cpl_vsi_virtual.h 27044 2014-03-16 23:41:27Z 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  * Copyright (c) 2010-2014, Even Rouault <even dot rouault at mines-paris dot org>
    00014  *
    00015  * Permission is hereby granted, free of charge, to any person obtaining a
    00016  * copy of this software and associated documentation files (the "Software"),
    00017  * to deal in the Software without restriction, including without limitation
    00018  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00019  * and/or sell copies of the Software, and to permit persons to whom the
    00020  * Software is furnished to do so, subject to the following conditions:
    00021  *
    00022  * The above copyright notice and this permission notice shall be included
    00023  * in all copies or substantial portions of the Software.
    00024  *
    00025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    00026  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00027  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    00028  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00029  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    00030  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    00031  * DEALINGS IN THE SOFTWARE.
    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) /* Remove annoying warnings in eVC++ and VC++ 6.0 */
    00044 #endif
    00045
    00046 #include <map>
    00047 #include <vector>
    00048 #include <string>
    00049
    00050 /************************************************************************/
    00051 /*                           VSIVirtualHandle                           */
    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 /*                         VSIFilesystemHandler                         */
    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 /*                            VSIFileManager                            */
    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 /*                       VSIArchiveFilesystemHandler                   */
    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     /* We use a cache that contains the list of files containes in a VSIArchive file as */
    00166     /* unarchive.c is quite inefficient in listing them. This speeds up access to VSIArchive files */
    00167     /* containing ~1000 files like a CADRG product */
    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 /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */

Generated for GDAL by 1.7.1.