LCOV - code coverage report
Current view: directory - port - cpl_vsi_virtual.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 20 11 55.0 %
Date: 2012-12-26 Functions: 18 9 50.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: cpl_vsi_virtual.h 23995 2012-02-19 22:39:17Z rouault $
       3                 :  *
       4                 :  * Project:  VSI Virtual File System
       5                 :  * Purpose:  Declarations for classes related to the virtual filesystem.
       6                 :  *           These would only be normally required by applications implmenting
       7                 :  *           their own virtual file system classes which should be rare.  
       8                 :  *           The class interface may be fragile through versions.
       9                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
      10                 :  *
      11                 :  ******************************************************************************
      12                 :  * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
      13                 :  *
      14                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      15                 :  * copy of this software and associated documentation files (the "Software"),
      16                 :  * to deal in the Software without restriction, including without limitation
      17                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      18                 :  * and/or sell copies of the Software, and to permit persons to whom the
      19                 :  * Software is furnished to do so, subject to the following conditions:
      20                 :  *
      21                 :  * The above copyright notice and this permission notice shall be included
      22                 :  * in all copies or substantial portions of the Software.
      23                 :  *
      24                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      25                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      26                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      27                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      28                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      29                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      30                 :  * DEALINGS IN THE SOFTWARE.
      31                 :  ****************************************************************************/
      32                 : 
      33                 : #ifndef CPL_VSI_VIRTUAL_H_INCLUDED
      34                 : #define CPL_VSI_VIRTUAL_H_INCLUDED
      35                 : 
      36                 : #include "cpl_vsi.h"
      37                 : #include "cpl_string.h"
      38                 : 
      39                 : #if defined(WIN32CE)
      40                 : #  include "cpl_wince.h"
      41                 : #  include <wce_errno.h>
      42                 : #  pragma warning(disable:4786) /* Remove annoying warnings in eVC++ and VC++ 6.0 */
      43                 : #endif
      44                 : 
      45                 : #include <map>
      46                 : #include <vector>
      47                 : #include <string>
      48                 : 
      49                 : /************************************************************************/
      50                 : /*                           VSIVirtualHandle                           */
      51                 : /************************************************************************/
      52                 : 
      53           71394 : class CPL_DLL VSIVirtualHandle { 
      54                 :   public:
      55                 :     virtual int       Seek( vsi_l_offset nOffset, int nWhence ) = 0;
      56                 :     virtual vsi_l_offset Tell() = 0;
      57                 :     virtual size_t    Read( void *pBuffer, size_t nSize, size_t nMemb ) = 0;
      58                 :     virtual int       ReadMultiRange( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes );
      59                 :     virtual size_t    Write( const void *pBuffer, size_t nSize,size_t nMemb)=0;
      60                 :     virtual int       Eof() = 0;
      61            3257 :     virtual int       Flush() {return 0;}
      62                 :     virtual int       Close() = 0;
      63               0 :     virtual int       Truncate( vsi_l_offset nNewSize ) { return -1; }
      64           71393 :     virtual           ~VSIVirtualHandle() { }
      65                 : };
      66                 : 
      67                 : /************************************************************************/
      68                 : /*                         VSIFilesystemHandler                         */
      69                 : /************************************************************************/
      70                 : 
      71            8544 : class CPL_DLL VSIFilesystemHandler {
      72                 : 
      73                 : public:
      74                 : 
      75            8244 :     virtual ~VSIFilesystemHandler() {}
      76                 : 
      77                 :     virtual VSIVirtualHandle *Open( const char *pszFilename, 
      78                 :                                     const char *pszAccess) = 0;
      79                 :     virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags) = 0;
      80               0 :     virtual int Unlink( const char *pszFilename )
      81               0 :                       { (void) pszFilename; errno=ENOENT; return -1; }
      82               0 :     virtual int Mkdir( const char *pszDirname, long nMode ) 
      83               0 :                       {(void)pszDirname; (void)nMode; errno=ENOENT; return -1;}
      84               0 :     virtual int Rmdir( const char *pszDirname ) 
      85               0 :                       { (void) pszDirname; errno=ENOENT; return -1; }
      86               2 :     virtual char **ReadDir( const char *pszDirname ) 
      87               2 :                       { (void) pszDirname; return NULL; }
      88               0 :     virtual int Rename( const char *oldpath, const char *newpath )
      89               0 :                       { (void) oldpath; (void)newpath; errno=ENOENT; return -1; }
      90           11894 :     virtual int IsCaseSensitive( const char* pszFilename )
      91           11894 :                       { (void) pszFilename; return TRUE; }
      92                 : };
      93                 : 
      94                 : /************************************************************************/
      95                 : /*                            VSIFileManager                            */
      96                 : /************************************************************************/
      97                 : 
      98                 : class CPL_DLL VSIFileManager 
      99                 : {
     100                 : private:
     101                 :     VSIFilesystemHandler *poDefaultHandler;
     102                 :     std::map<std::string, VSIFilesystemHandler *> oHandlers;
     103                 : 
     104                 :     VSIFileManager();
     105                 : 
     106                 :     static VSIFileManager *Get();
     107                 : 
     108                 : public:
     109                 :     ~VSIFileManager();
     110                 : 
     111                 :     static VSIFilesystemHandler *GetHandler( const char * );
     112                 :     static void InstallHandler( const std::string& osPrefix, 
     113                 :                                 VSIFilesystemHandler * );
     114                 :     static void RemoveHandler( const std::string& osPrefix );
     115                 : };
     116                 : 
     117                 : 
     118                 : /************************************************************************/
     119                 : /* ==================================================================== */
     120                 : /*                       VSIArchiveFilesystemHandler                   */
     121                 : /* ==================================================================== */
     122                 : /************************************************************************/
     123                 : 
     124                 : class VSIArchiveEntryFileOffset
     125            2465 : {
     126                 :     public:
     127                 :         virtual ~VSIArchiveEntryFileOffset();
     128                 : };
     129                 : 
     130                 : typedef struct
     131                 : {
     132                 :     char         *fileName;
     133                 :     vsi_l_offset  uncompressed_size;
     134                 :     VSIArchiveEntryFileOffset*      file_pos;
     135                 :     int           bIsDir;
     136                 :     GIntBig       nModifiedTime;
     137                 : } VSIArchiveEntry;
     138                 : 
     139                 : typedef struct
     140                 : {
     141                 :     int nEntries;
     142                 :     VSIArchiveEntry* entries;
     143                 : } VSIArchiveContent;
     144                 : 
     145                 : class VSIArchiveReader
     146             376 : {
     147                 :     public:
     148                 :         virtual ~VSIArchiveReader();
     149                 : 
     150                 :         virtual int GotoFirstFile() = 0;
     151                 :         virtual int GotoNextFile() = 0;
     152                 :         virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
     153                 :         virtual GUIntBig GetFileSize() = 0;
     154                 :         virtual CPLString GetFileName() = 0;
     155                 :         virtual GIntBig GetModifiedTime() = 0;
     156                 :         virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
     157                 : };
     158                 : 
     159                 : class VSIArchiveFilesystemHandler : public VSIFilesystemHandler 
     160                 : {
     161                 : protected:
     162                 :     void* hMutex;
     163                 :     /* We use a cache that contains the list of files containes in a VSIArchive file as */
     164                 :     /* unarchive.c is quite inefficient in listing them. This speeds up access to VSIArchive files */
     165                 :     /* containing ~1000 files like a CADRG product */
     166                 :     std::map<CPLString,VSIArchiveContent*>   oFileList;
     167                 : 
     168                 :     virtual const char* GetPrefix() = 0;
     169                 :     virtual std::vector<CPLString> GetExtensions() = 0;
     170                 :     virtual VSIArchiveReader* CreateReader(const char* pszArchiveFileName) = 0;
     171                 : 
     172                 : public:
     173                 :     VSIArchiveFilesystemHandler();
     174                 :     virtual ~VSIArchiveFilesystemHandler();
     175                 : 
     176                 :     virtual int      Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags );
     177                 :     virtual int      Unlink( const char *pszFilename );
     178                 :     virtual int      Rename( const char *oldpath, const char *newpath );
     179                 :     virtual int      Mkdir( const char *pszDirname, long nMode );
     180                 :     virtual int      Rmdir( const char *pszDirname );
     181                 :     virtual char   **ReadDir( const char *pszDirname );
     182                 : 
     183                 :     virtual const VSIArchiveContent* GetContentOfArchive(const char* archiveFilename, VSIArchiveReader* poReader = NULL);
     184                 :     virtual char* SplitFilename(const char *pszFilename, CPLString &osFileInArchive, int bCheckMainFileExists);
     185                 :     virtual VSIArchiveReader* OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName);
     186                 :     virtual int FindFileInArchive(const char* archiveFilename, const char* fileInArchiveName, const VSIArchiveEntry** archiveEntry);
     187                 : };
     188                 : 
     189                 : VSIVirtualHandle* VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle);
     190                 : VSIVirtualHandle* VSICreateCachedFile( VSIVirtualHandle* poBaseHandle );
     191                 : VSIVirtualHandle* VSICreateGZipWritable( VSIVirtualHandle* poBaseHandle, int bRegularZLibIn, int bAutoCloseBaseHandle );
     192                 : 
     193                 : #endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */

Generated by: LCOV version 1.7