GDAL

- Main Page
- Related Pages
- Classes
- Files
- Download
- Issue Tracker

- File List
- File Members

cpl_vsi_virtual.h
1 /******************************************************************************
2 * $Id: cpl_vsi_virtual.h 36501 2016-11-25 14:09:24Z 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 implementing
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_vsi_error.h"
39 #include "cpl_string.h"
40 #include "cpl_multiproc.h"
41
42 #include <map>
43 #include <vector>
44 #include <string>
45
46 // To avoid aliasing to GetDiskFreeSpace to GetDiskFreeSpaceA on Windows
47 #ifdef GetDiskFreeSpace
48 #undef GetDiskFreeSpace
49 #endif
50
51 /************************************************************************/
52 /* VSIVirtualHandle */
53 /************************************************************************/
54
56 class CPL_DLL VSIVirtualHandle {
57 public:
58 virtual int Seek( vsi_l_offset nOffset, int nWhence ) = 0;
59 virtual vsi_l_offset Tell() = 0;
60 virtual size_t Read( void *pBuffer, size_t nSize, size_t nCount ) = 0;
61 virtual int ReadMultiRange( int nRanges, void ** ppData,
62 const vsi_l_offset* panOffsets,
63 const size_t* panSizes );
64 virtual size_t Write( const void *pBuffer, size_t nSize,size_t nCount)=0;
65 virtual int Eof() = 0;
66 virtual int Flush() {return 0;}
67 virtual int Close() = 0;
68 // Base implementation that only supports file extension.
69 virtual int Truncate( vsi_l_offset nNewSize );
70 virtual void *GetNativeFileDescriptor() { return NULL; }
71 virtual VSIRangeStatus GetRangeStatus( CPL_UNUSED vsi_l_offset nOffset,
72 CPL_UNUSED vsi_l_offset nLength )
73 { return VSI_RANGE_STATUS_UNKNOWN; }
74
75 virtual ~VSIVirtualHandle() { }
76 };
77
78 /************************************************************************/
79 /* VSIFilesystemHandler */
80 /************************************************************************/
81
82 #ifndef DOXYGEN_SKIP
83 class CPL_DLL VSIFilesystemHandler {
84
85 public:
86
87 virtual ~VSIFilesystemHandler() {}
88
89 VSIVirtualHandle *Open( const char *pszFilename,
90 const char *pszAccess );
91
92 virtual VSIVirtualHandle *Open( const char *pszFilename,
93 const char *pszAccess,
94 bool bSetError ) = 0;
95 virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags) = 0;
96 virtual int Unlink( const char *pszFilename )
97 { (void) pszFilename; errno=ENOENT; return -1; }
98 virtual int Mkdir( const char *pszDirname, long nMode )
99 {(void)pszDirname; (void)nMode; errno=ENOENT; return -1;}
100 virtual int Rmdir( const char *pszDirname )
101 { (void) pszDirname; errno=ENOENT; return -1; }
102 virtual char **ReadDir( const char *pszDirname )
103 { (void) pszDirname; return NULL; }
104 virtual char **ReadDirEx( const char *pszDirname, int /* nMaxFiles */ )
105 { return ReadDir(pszDirname); }
106 virtual int Rename( const char *oldpath, const char *newpath )
107 { (void) oldpath; (void)newpath; errno=ENOENT; return -1; }
108 virtual int IsCaseSensitive( const char* pszFilename )
109 { (void) pszFilename; return TRUE; }
110 virtual GIntBig GetDiskFreeSpace( const char* /* pszDirname */ ) { return -1; }
111 virtual int SupportsSparseFiles( const char* /* pszPath */ ) { return FALSE; }
112 };
113 #endif /* #ifndef DOXYGEN_SKIP */
114
115 /************************************************************************/
116 /* VSIFileManager */
117 /************************************************************************/
118
119 #ifndef DOXYGEN_SKIP
120 class CPL_DLL VSIFileManager
121 {
122 private:
123 VSIFilesystemHandler *poDefaultHandler;
124 std::map<std::string, VSIFilesystemHandler *> oHandlers;
125
126 VSIFileManager();
127
128 static VSIFileManager *Get();
129
130 public:
131 ~VSIFileManager();
132
133 static VSIFilesystemHandler *GetHandler( const char * );
134 static void InstallHandler( const std::string& osPrefix,
135 VSIFilesystemHandler * );
136 /* RemoveHandler is never defined. */
137 /* static void RemoveHandler( const std::string& osPrefix ); */
138 };
139 #endif /* #ifndef DOXYGEN_SKIP */
140
141 /************************************************************************/
142 /* ==================================================================== */
143 /* VSIArchiveFilesystemHandler */
144 /* ==================================================================== */
145 /************************************************************************/
146
147 #ifndef DOXYGEN_SKIP
148
149 class VSIArchiveEntryFileOffset
150 {
151 public:
152 virtual ~VSIArchiveEntryFileOffset();
153 };
154
155 typedef struct
156 {
157 char *fileName;
158 vsi_l_offset uncompressed_size;
159 VSIArchiveEntryFileOffset* file_pos;
160 int bIsDir;
161 GIntBig nModifiedTime;
162 } VSIArchiveEntry;
163
164 class VSIArchiveContent
165 {
166 public:
167 time_t mTime;
168 vsi_l_offset nFileSize;
169 int nEntries;
170 VSIArchiveEntry* entries;
171
172 VSIArchiveContent() : mTime(0), nFileSize(0), nEntries(0), entries(NULL) {}
173 ~VSIArchiveContent();
174 };
175
176 class VSIArchiveReader
177 {
178 public:
179 virtual ~VSIArchiveReader();
180
181 virtual int GotoFirstFile() = 0;
182 virtual int GotoNextFile() = 0;
183 virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
184 virtual GUIntBig GetFileSize() = 0;
185 virtual CPLString GetFileName() = 0;
186 virtual GIntBig GetModifiedTime() = 0;
187 virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
188 };
189
190 class VSIArchiveFilesystemHandler : public VSIFilesystemHandler
191 {
192 protected:
193 CPLMutex* hMutex;
194 /* We use a cache that contains the list of files contained in a VSIArchive file as */
195 /* unarchive.c is quite inefficient in listing them. This speeds up access to VSIArchive files */
196 /* containing ~1000 files like a CADRG product */
197 std::map<CPLString,VSIArchiveContent*> oFileList;
198
199 virtual const char* GetPrefix() = 0;
200 virtual std::vector<CPLString> GetExtensions() = 0;
201 virtual VSIArchiveReader* CreateReader(const char* pszArchiveFileName) = 0;
202
203 public:
204 VSIArchiveFilesystemHandler();
205 virtual ~VSIArchiveFilesystemHandler();
206
207 virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags ) CPL_OVERRIDE;
208 virtual int Unlink( const char *pszFilename ) CPL_OVERRIDE;
209 virtual int Rename( const char *oldpath, const char *newpath ) CPL_OVERRIDE;
210 virtual int Mkdir( const char *pszDirname, long nMode ) CPL_OVERRIDE;
211 virtual int Rmdir( const char *pszDirname ) CPL_OVERRIDE;
212 virtual char **ReadDirEx( const char *pszDirname, int nMaxFiles ) CPL_OVERRIDE;
213
214 virtual const VSIArchiveContent* GetContentOfArchive(const char* archiveFilename, VSIArchiveReader* poReader = NULL);
215 virtual char* SplitFilename(const char *pszFilename, CPLString &osFileInArchive, int bCheckMainFileExists);
216 virtual VSIArchiveReader* OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName);
217 virtual int FindFileInArchive(const char* archiveFilename, const char* fileInArchiveName, const VSIArchiveEntry** archiveEntry);
218 };
219
220 #endif /* #ifndef DOXYGEN_SKIP */
221
222 VSIVirtualHandle CPL_DLL *VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle);
223 VSIVirtualHandle* VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle,
224 const GByte* pabyBeginningContent,
225 vsi_l_offset nCheatFileSize);
226 VSIVirtualHandle CPL_DLL *VSICreateCachedFile( VSIVirtualHandle* poBaseHandle, size_t nChunkSize = 32768, size_t nCacheSize = 0 );
227 VSIVirtualHandle CPL_DLL *VSICreateGZipWritable( VSIVirtualHandle* poBaseHandle, int bRegularZLibIn, int bAutoCloseBaseHandle );
228
229 #endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */
VSIRangeStatus
VSIRangeStatus
Range status.
Definition: cpl_vsi.h:173
cpl_vsi.h
Standard C Covers.
CPL_OVERRIDE
#define CPL_OVERRIDE
To be used in public headers only.
Definition: cpl_port.h:1055
VSIVirtualHandle::GetRangeStatus
virtual VSIRangeStatus GetRangeStatus(vsi_l_offset nOffset, vsi_l_offset nLength)
Return if a given file range contains data or holes filled with zeroes.
Definition: cpl_vsi_virtual.h:71
GByte
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:207
VSIVirtualHandle
Virtual file handle.
Definition: cpl_vsi_virtual.h:56
VSIVirtualHandle::GetNativeFileDescriptor
virtual void * GetNativeFileDescriptor()
Returns the "native" file descriptor for the virtual handle.
Definition: cpl_vsi_virtual.h:70
CPLString
Convenient string class based on std::string.
Definition: cpl_string.h:338
cpl_string.h
Various convenience functions for working with strings and string lists.
VSIStatBufL
struct VSI_STAT64_T VSIStatBufL
Type for VSIStatL()
Definition: cpl_vsi.h:190
VSI_RANGE_STATUS_UNKNOWN
Unknown.
Definition: cpl_vsi.h:175
GUIntBig
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:253
CPL_UNUSED
#define CPL_UNUSED
Qualifier for an argument that is unused.
Definition: cpl_port.h:1008
vsi_l_offset
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:138
GIntBig
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:250
VSIVirtualHandle::Flush
virtual int Flush()
Flush pending writes to disk.
Definition: cpl_vsi_virtual.h:66

Generated for GDAL by 1.8.9.1.