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

Generated for GDAL by doxygen 1.8.11.