GDAL

cpl_vsi_virtual.h

00001 /******************************************************************************
00002  * $Id: cpl_vsi_virtual.h 21167 2010-11-24 15:19:51Z warmerdam $
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, int nFlags) = 0;
00078     virtual int Unlink( const char *pszFilename )
00079                       { (void) pszFilename; errno=ENOENT; return -1; }
00080     virtual int Mkdir( const char *pszDirname, long nMode ) 
00081                       {(void)pszDirname; (void)nMode; errno=ENOENT; return -1;}
00082     virtual int Rmdir( const char *pszDirname ) 
00083                       { (void) pszDirname; errno=ENOENT; return -1; }
00084     virtual char **ReadDir( const char *pszDirname ) 
00085                       { (void) pszDirname; return NULL; }
00086     virtual int Rename( const char *oldpath, const char *newpath )
00087                       { (void) oldpath; (void)newpath; errno=ENOENT; return -1; }
00088     virtual int IsCaseSensitive( const char* pszFilename )
00089                       { (void) pszFilename; return TRUE; }
00090 };
00091 
00092 /************************************************************************/
00093 /*                            VSIFileManager                            */
00094 /************************************************************************/
00095 
00096 class CPL_DLL VSIFileManager 
00097 {
00098 private:
00099     VSIFilesystemHandler *poDefaultHandler;
00100     std::map<std::string, VSIFilesystemHandler *> oHandlers;
00101 
00102     VSIFileManager();
00103 
00104     static VSIFileManager *Get();
00105 
00106 public:
00107     ~VSIFileManager();
00108 
00109     static VSIFilesystemHandler *GetHandler( const char * );
00110     static void InstallHandler( const std::string& osPrefix, 
00111                                 VSIFilesystemHandler * );
00112     static void RemoveHandler( const std::string& osPrefix );
00113 };
00114 
00115 
00116 /************************************************************************/
00117 /* ==================================================================== */
00118 /*                       VSIArchiveFilesystemHandler                   */
00119 /* ==================================================================== */
00120 /************************************************************************/
00121 
00122 class VSIArchiveEntryFileOffset
00123 {
00124     public:
00125         virtual ~VSIArchiveEntryFileOffset();
00126 };
00127 
00128 typedef struct
00129 {
00130     char         *fileName;
00131     vsi_l_offset  uncompressed_size;
00132     VSIArchiveEntryFileOffset*      file_pos;
00133     int           bIsDir;
00134     GIntBig       nModifiedTime;
00135 } VSIArchiveEntry;
00136 
00137 typedef struct
00138 {
00139     int nEntries;
00140     VSIArchiveEntry* entries;
00141 } VSIArchiveContent;
00142 
00143 class VSIArchiveReader
00144 {
00145     public:
00146         virtual ~VSIArchiveReader();
00147 
00148         virtual int GotoFirstFile() = 0;
00149         virtual int GotoNextFile() = 0;
00150         virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
00151         virtual GUIntBig GetFileSize() = 0;
00152         virtual CPLString GetFileName() = 0;
00153         virtual GIntBig GetModifiedTime() = 0;
00154         virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
00155 };
00156 
00157 class VSIArchiveFilesystemHandler : public VSIFilesystemHandler 
00158 {
00159 protected:
00160     void* hMutex;
00161     /* We use a cache that contains the list of files containes in a VSIArchive file as */
00162     /* unarchive.c is quite inefficient in listing them. This speeds up access to VSIArchive files */
00163     /* containing ~1000 files like a CADRG product */
00164     std::map<CPLString,VSIArchiveContent*>   oFileList;
00165 
00166     virtual const char* GetPrefix() = 0;
00167     virtual std::vector<CPLString> GetExtensions() = 0;
00168     virtual VSIArchiveReader* CreateReader(const char* pszArchiveFileName) = 0;
00169 
00170 public:
00171     VSIArchiveFilesystemHandler();
00172     virtual ~VSIArchiveFilesystemHandler();
00173 
00174     virtual int      Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags );
00175     virtual int      Unlink( const char *pszFilename );
00176     virtual int      Rename( const char *oldpath, const char *newpath );
00177     virtual int      Mkdir( const char *pszDirname, long nMode );
00178     virtual int      Rmdir( const char *pszDirname );
00179     virtual char   **ReadDir( const char *pszDirname );
00180 
00181     virtual const VSIArchiveContent* GetContentOfArchive(const char* archiveFilename, VSIArchiveReader* poReader = NULL);
00182     virtual char* SplitFilename(const char *pszFilename, CPLString &osFileInArchive, int bCheckMainFileExists);
00183     virtual VSIArchiveReader* OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName);
00184     virtual int FindFileInArchive(const char* archiveFilename, const char* fileInArchiveName, const VSIArchiveEntry** archiveEntry);
00185 };
00186 
00187 VSIVirtualHandle* VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle);
00188 
00189 #endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */

Generated for GDAL by doxygen 1.7.3.