00001 /****************************************************************************** 00002 * $Id: cpl_vsi_private.h,v 1.7 2006/03/27 15:24:41 fwarmerdam Exp $ 00003 * 00004 * Project: VSI Virtual File System 00005 * Purpose: Private declarations for classes related to the virtual filesystem 00006 * Author: Frank Warmerdam, warmerdam@pobox.com 00007 * 00008 ****************************************************************************** 00009 * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com> 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a 00012 * copy of this software and associated documentation files (the "Software"), 00013 * to deal in the Software without restriction, including without limitation 00014 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00015 * and/or sell copies of the Software, and to permit persons to whom the 00016 * Software is furnished to do so, subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be included 00019 * in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00022 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00024 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00026 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00027 * DEALINGS IN THE SOFTWARE. 00028 ****************************************************************************** 00029 * 00030 * $Log: cpl_vsi_private.h,v $ 00031 * Revision 1.7 2006/03/27 15:24:41 fwarmerdam 00032 * buffer in FWrite is const 00033 * 00034 * Revision 1.6 2006/02/19 21:54:34 mloskot 00035 * [WINCE] Changes related to Windows CE port of CPL. Most changes are #ifdef wrappers. 00036 * 00037 * Revision 1.5 2006/01/10 17:03:56 fwarmerdam 00038 * added VSI Rename support 00039 * 00040 * Revision 1.4 2005/09/15 18:39:00 fwarmerdam 00041 * fixedup filemanager cleanup 00042 * 00043 * Revision 1.3 2005/09/13 15:17:52 dron 00044 * Unneeded semicolon removed. 00045 * 00046 * Revision 1.2 2005/09/13 15:16:44 dron 00047 * Added virtual destructor to VSIVirtualHandle and VSIFilesystemHandler classes. 00048 * 00049 * Revision 1.1 2005/09/11 18:00:49 fwarmerdam 00050 * New 00051 * 00052 */ 00053 00054 #ifndef CPL_VSI_VIRTUAL_H_INCLUDED 00055 #define CPL_VSI_VIRTUAL_H_INCLUDED 00056 00057 #include "cpl_vsi.h" 00058 00059 #if defined(WIN32CE) 00060 # include "cpl_wince.h" 00061 # include <wce_errno.h> 00062 # pragma warning(disable:4786) /* Remove annoying warnings in eVC++ and VC++ 6.0 */ 00063 #endif 00064 00065 #include <map> 00066 #include <vector> 00067 #include <string> 00068 00069 /************************************************************************/ 00070 /* VSIVirtualHandle */ 00071 /************************************************************************/ 00072 00073 class VSIVirtualHandle { 00074 public: 00075 virtual int Seek( vsi_l_offset nOffset, int nWhence ) = 0; 00076 virtual vsi_l_offset Tell() = 0; 00077 virtual size_t Read( void *pBuffer, size_t nSize, size_t nMemb ) = 0; 00078 virtual size_t Write( const void *pBuffer, size_t nSize,size_t nMemb)=0; 00079 virtual int Eof() = 0; 00080 virtual int Flush() {return 0;} 00081 virtual int Close() = 0; 00082 virtual ~VSIVirtualHandle() { } 00083 }; 00084 00085 /************************************************************************/ 00086 /* VSIFilesystemHandler */ 00087 /************************************************************************/ 00088 00089 class VSIFilesystemHandler { 00090 00091 public: 00092 virtual VSIVirtualHandle *Open( const char *pszFilename, 00093 const char *pszAccess) = 0; 00094 virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf) = 0; 00095 virtual int Unlink( const char *pszFilename ) 00096 { errno=ENOENT; return -1; } 00097 virtual int Mkdir( const char *pszDirname, long nMode ) 00098 { errno=ENOENT; return -1; } 00099 virtual int Rmdir( const char *pszDirname ) 00100 { errno=ENOENT; return -1; } 00101 virtual char **ReadDir( const char *pszDirname ) 00102 { return NULL; } 00103 virtual ~VSIFilesystemHandler() {} 00104 virtual int Rename( const char *oldpath, const char *newpath ) 00105 { errno=ENOENT; return -1; } 00106 }; 00107 00108 /************************************************************************/ 00109 /* VSIFileManager */ 00110 /************************************************************************/ 00111 00112 class VSIFileManager 00113 { 00114 private: 00115 VSIFilesystemHandler *poDefaultHandler; 00116 std::map<std::string,VSIFilesystemHandler *> oHandlers; 00117 00118 VSIFileManager(); 00119 00120 static VSIFileManager *Get(); 00121 00122 public: 00123 ~VSIFileManager(); 00124 00125 static VSIFilesystemHandler *GetHandler( const char * ); 00126 static void InstallHandler( std::string osPrefix, 00127 VSIFilesystemHandler * ); 00128 static void RemoveHandler( std::string osPrefix ); 00129 }; 00130 00131 #endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */