IFileSystem.h

00001 /***************************************************************************
00002  *                                                                         *
00003  *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
00004  *       mailto: <tevs@mpi-sb.mpg.de>                                      *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  ***************************************************************************/
00012 
00013 
00014 #ifndef _NR_I_FILESYSTEM_H_
00015 #define _NR_I_FILESYSTEM_H_
00016 
00017 
00018 //----------------------------------------------------------------------------------
00019 // Includes
00020 //----------------------------------------------------------------------------------
00021 #include "Prerequisities.h"
00022 #include "Property.h"
00023 #include "FileStream.h"
00024 
00025 namespace nrEngine{
00026 
00027         //! File system module interface that are managed by file system manager
00028         /**
00029          * Each file system has it's own handling routines and access controls.
00030          * So this class provide an interface for abstract using of such file systems.
00031          * Modules derived from this interface can be registered by the file system manager
00032          * so they are used to access files.
00033          *
00034          * Each file system does have a type. A type is unique for each kind of fs.
00035          * The name of the type is used to allow user to specify directly the fs he
00036          * want to use to access the files. So calling "file:/.." force a local file
00037          * system to be used and "http:/..." will access the files through htpp-interface.
00038          * Accessing the files without any fs specified force the manager to look
00039          * for the file under each registered file system.
00040          *
00041          * User can also specify parameters to the file system by accessing the files.
00042          * The parameters are separated through ':' and are given in the file name.
00043          * You can also specify parameters by setting them directly. The parameters
00044          * are always states. i.e. if parameter 1 is set to the value A, so this
00045          * value will be used until it is changed. Parameters specified in the filename
00046          * are local parameters used only for the current access and they overload
00047          * the global parameters of the file system.
00048          * 
00049          * \ingroup vfs
00050         **/
00051         class _NRExport IFileSystem{
00052                 public:
00053         
00054                         //! Initalize the file system
00055                         IFileSystem();
00056         
00057                         //! Release used memory and force all files to close
00058                         virtual ~IFileSystem();
00059 
00060                         /**
00061                          * Each file has more info about it than only a name.
00062                          * So we store file info in a structure.
00063                          **/
00064                         struct FileInfo{
00065                                 //! The file system to which one this file belongs
00066                                 IFileSystem* fsParent;
00067 
00068                                 //! full name of the file
00069                                 std::string name;
00070 
00071                                 //! virtual path of the file separated by '/' and ending with '/'
00072                                 std::string path;
00073 
00074                                 //! real file path, in the file system specific manner
00075                                 std::string realPath;
00076                                 
00077                                 //! size of the file
00078                                 size_t size;
00079                                 
00080                         };
00081                         
00082                         //! Vector containing file info information
00083                         typedef std::vector<FileInfo> FileInfoList;
00084                         typedef SharedPtr<FileInfoList> FileInfoListPtr;
00085 
00086                         
00087                         /**
00088                          * Check whenever such a file exists in that file system.
00089                          * @param fileName
00090                          **/
00091                         virtual bool exists(const std::string& fileName) = 0;
00092 
00093                         /**
00094                          * Returns true if this filesystem is case sensitive by matching the filenames
00095                          **/
00096                         virtual bool isCaseSensitive() const = 0;
00097 
00098                         /**
00099                          * List all files in the archive. You get the file info list containing
00100                          * information about each file in the archive
00101                          *
00102                          * @param recursive if true so search for the files recursively
00103                          **/
00104                         virtual FileInfoListPtr listFiles(bool recursive = true) = 0;
00105                         
00106                         /**
00107                          * Find a file by the given pattern. Wildcard '*' is allowed.
00108                          *
00109                          * @param pattern filename pattern including wildcards
00110                          * @param recursive if true so search recursively
00111                          **/
00112                         virtual FileInfoListPtr findFiles(const std::string& pattern, bool recursive = true) = 0;
00113 
00114                         /**
00115                          * Initialize the file system.
00116                          **/
00117                         virtual Result initialize() = 0;
00118 
00119                         /**
00120                          * Release the file system and close all opened files.
00121                          **/
00122                         virtual Result deinitialize() = 0;
00123 
00124                         /**
00125                          * Open a file by the given filename. The method returns a smart pointer
00126                          * on the file stream. So as soon as the pointer is not used anymore the file will
00127                          * be closed automaticaly behaving to the file stream.
00128                          *
00129                          * @param filename Name of the file (without parameters)
00130                          * @param params Local parameters for this access
00131                          **/
00132                         virtual SharedPtr<FileStream> open(const std::string& filename, PropertyList* params = NULL) = 0;
00133 
00134                         /**
00135                          * File system type. This type is used to allow users to access directly
00136                          * to the files on this filesystem.
00137                          **/
00138                         virtual const std::string& getType() { return mType; }
00139 
00140                         /**
00141                          * Set global parameters for this file system
00142                          * @param param Parameter number
00143                          * @param value Value of the parameter
00144                          **/
00145                         virtual Result set(uint32 param, const std::string& value);
00146 
00147                         /**
00148                          * This method allows to setup the parameters by their names.
00149                          * The file system modules should specifiy somehow the parameter
00150                          * names which can be used to setup them
00151                          *
00152                          * @param name Name of the paramter (i.e. by ftp access "username")
00153                          * @param value Value of the parameter
00154                          **/
00155                         virtual Result set(const std::string& name, const std::string& value);
00156                         
00157                 protected:
00158 
00159                         //! Unique type name for this file system
00160                         std::string mType;
00161 
00162                         //! Map containing the parameters and their values
00163                         PropertyList    mParameter;
00164 
00165         };
00166 
00167 };
00168 
00169 #endif

Generated on Wed Sep 12 23:19:42 2007 for nrEngine by  doxygen 1.5.1