FileSystem.h

Go to the documentation of this file.
00001 /*
00002  *      FileSystem.h - The Pentagram File System
00003  *
00004  *  Copyright (C) 2002-2005  The Pentagram Team
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  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifndef FILESYSTEM_H
00022 #define FILESYSTEM_H
00023 
00024 #include <fstream>
00025 #include <string>
00026 #include <map>
00027 #include <list>
00028 
00029 #include "IDataSource.h"
00030 #include "ODataSource.h"
00031 
00032 class FileSystem
00033 {
00034  public:
00036         FileSystem(bool noforcedvpaths = false);
00037         ~FileSystem();
00038 
00040         void initBuiltinData(bool allowoverride);
00041 
00042         static FileSystem* get_instance() { return filesystem; }
00043 
00048         IDataSource *ReadFile(const std::string &vfn, bool is_text=false);
00049 
00054         ODataSource *WriteFile(const std::string &vfn, bool is_text=false);
00055 
00062         bool AddVirtualPath(const std::string &vpath, const std::string &realpath,
00063                                                 bool create=false);
00064 
00066         bool RemoveVirtualPath(const std::string &vpath);
00067 
00071         int MkDir(const std::string& path); // can handle both paths and vpaths
00072 
00073         typedef std::list<std::string> FileList;
00074 
00079         int ListFiles(const std::string mask, FileList& files);
00080 
00081  private:
00082         void switch_slashes(std::string &name);
00083         bool base_to_uppercase(std::string& str, int count);
00084 
00085         bool rawopen
00086         (
00087         std::ifstream& in,                      // Input stream to open.
00088         const std::string &fname,       // May be converted to upper-case.
00089         bool is_text = false            // Should the file be opened in text mode
00090         );
00091                 
00092         bool rawopen
00093         (
00094         std::ofstream& out,                     // Output stream to open.
00095         const std::string &fname,       // May be converted to upper-case.
00096         bool is_text = false            // Should the file be opened in text mode
00097         );
00098         
00099         bool IsDir(const std::string& path);
00100 
00101         static FileSystem* filesystem;
00102 
00103         // This will disable the usage of forced virtual paths.
00104         // It's useful for 'tools'
00105         bool    noforcedvpaths;
00106 
00107         // This enables/disables overriding builtin data files with external ones
00108         bool    allowdataoverride;
00109 
00110         // rewrite virtual path in-place (i.e., fvn is replaced)
00111         // returns false if no rewriting was done
00112         bool rewrite_virtual_path(std::string& vfn);
00113 
00114         std::map<std::string, std::string> virtualpaths;
00115 
00118         IDataSource* checkBuiltinData(const std::string& vfn, bool is_text=false);
00119 
00120         struct MemoryFile
00121         {
00122                 MemoryFile(const uint8* _data, const uint32 _len)
00123                         : data(_data), len(_len) { } 
00124                 const uint8             *data;
00125                 const uint32    len;
00126         };
00127         std::map<std::string, MemoryFile*> memoryfiles; // Files mounted in memory
00128 
00129 };
00130 
00131 
00132 
00133 #endif

Generated on Fri Jul 27 22:27:14 2007 for pentagram by  doxygen 1.4.7