cpl_vsi_private.h

00001 /******************************************************************************
00002  * $Id: cpl_vsi_private.h,v 1.4 2005/09/15 18:39:00 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.4  2005/09/15 18:39:00  fwarmerdam
00032  * fixedup filemanager cleanup
00033  *
00034  * Revision 1.3  2005/09/13 15:17:52  dron
00035  * Unneeded semicolon removed.
00036  *
00037  * Revision 1.2  2005/09/13 15:16:44  dron
00038  * Added virtual destructor to VSIVirtualHandle and VSIFilesystemHandler classes.
00039  *
00040  * Revision 1.1  2005/09/11 18:00:49  fwarmerdam
00041  * New
00042  *
00043  */
00044 
00045 #ifndef CPL_VSI_VIRTUAL_H_INCLUDED
00046 #define CPL_VSI_VIRTUAL_H_INCLUDED
00047 
00048 #include "cpl_vsi.h"
00049 
00050 #include <map>
00051 #include <vector>
00052 #include <string>
00053 
00054 /************************************************************************/
00055 /*                           VSIVirtualHandle                           */
00056 /************************************************************************/
00057 
00058 class VSIVirtualHandle { 
00059   public:
00060     virtual int       Seek( vsi_l_offset nOffset, int nWhence ) = 0;
00061     virtual vsi_l_offset Tell() = 0;
00062     virtual size_t    Read( void *pBuffer, size_t nSize, size_t nMemb ) = 0;
00063     virtual size_t    Write( void *pBuffer, size_t nSize, size_t nMemb ) = 0;
00064     virtual int       Eof() = 0;
00065     virtual int       Flush() {return 0;}
00066     virtual int       Close() = 0;
00067     virtual           ~VSIVirtualHandle() { }
00068 };
00069 
00070 /************************************************************************/
00071 /*                         VSIFilesystemHandler                         */
00072 /************************************************************************/
00073 
00074 class VSIFilesystemHandler {
00075 
00076 public:
00077     virtual VSIVirtualHandle *Open( const char *pszFilename, 
00078                                     const char *pszAccess) = 0;
00079     virtual int      Stat( const char *pszFilename, VSIStatBufL *pStatBuf) = 0;
00080     virtual int      Unlink( const char *pszFilename ) 
00081                         { errno=ENOENT; return -1; }
00082     virtual int      Mkdir( const char *pszDirname, long nMode ) 
00083                         { errno=ENOENT; return -1; }
00084     virtual int      Rmdir( const char *pszDirname ) 
00085                         { errno=ENOENT; return -1; }
00086     virtual char   **ReadDir( const char *pszDirname ) 
00087                         { return NULL; }
00088     virtual          ~VSIFilesystemHandler() {}
00089 };
00090 
00091 /************************************************************************/
00092 /*                            VSIFileManager                            */
00093 /************************************************************************/
00094 
00095 class VSIFileManager 
00096 {
00097 private:
00098     VSIFilesystemHandler         *poDefaultHandler;
00099     std::map<std::string,VSIFilesystemHandler *>   oHandlers;
00100 
00101     VSIFileManager();
00102 
00103     static VSIFileManager *Get();
00104 
00105 public:
00106     ~VSIFileManager();
00107 
00108     static VSIFilesystemHandler *GetHandler( const char * );
00109     static void                InstallHandler( std::string osPrefix, 
00110                                                VSIFilesystemHandler * );
00111     static void                RemoveHandler( std::string osPrefix );
00112 };
00113 
00114 #endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */

Generated on Sun Jul 2 22:18:26 2006 for GDAL by  doxygen 1.4.6