ifilesystem.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2001-2006, William Joseph.
00003  All Rights Reserved.
00004 
00005  This file is part of GtkRadiant.
00006 
00007  GtkRadiant is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  GtkRadiant is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with GtkRadiant; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #if !defined(INCLUDED_IFILESYSTEM_H)
00023 #define INCLUDED_IFILESYSTEM_H
00024 
00025 #include <cstddef>
00026 #include "generic/constant.h"
00027 #include "generic/callbackfwd.h"
00028 #include <string>
00029 
00030 typedef Callback1<const char*> ArchiveNameCallback;
00031 typedef Callback1<const char*> FileNameCallback;
00032 
00033 class ArchiveFile;
00034 class ArchiveTextFile;
00035 class Archive;
00036 
00037 class ModuleObserver;
00038 
00039 typedef struct _GSList GSList;
00040 
00042 class VirtualFileSystem
00043 {
00044     public:
00045         INTEGER_CONSTANT(Version, 1);
00046         STRING_CONSTANT(Name, "VFS");
00047 
00048         virtual ~VirtualFileSystem ()
00049         {
00050         }
00051 
00054         virtual void initDirectory (const std::string& path) = 0;
00057         virtual void initialise () = 0;
00059         virtual void shutdown () = 0;
00060 
00063         virtual ArchiveFile* openFile (const std::string& filename) = 0;
00066         virtual ArchiveTextFile* openTextFile (const std::string& filename) = 0;
00067 
00072         virtual std::size_t loadFile (const std::string& filename, void **buffer) = 0;
00075         virtual void freeFile (void *p) = 0;
00076 
00078         virtual void forEachDirectory (const char* basedir, const FileNameCallback& callback, std::size_t depth = 1) = 0;
00081         virtual void forEachFile (const char* basedir, const char* extension, const FileNameCallback& callback,
00082                 std::size_t depth = 1) = 0;
00083 
00085         virtual std::string findFile (const std::string& name) = 0;
00088         virtual std::string findRoot (const std::string& name) = 0;
00090         virtual std::string getRelative (const std::string& name) = 0;
00091 
00093         virtual void attach (ModuleObserver& observer) = 0;
00095         virtual void detach (ModuleObserver& observer) = 0;
00096 
00097         virtual Archive* getArchive (const char* archiveName) = 0;
00098         virtual void forEachArchive (const ArchiveNameCallback& callback) = 0;
00099 };
00100 
00101 #include "modulesystem.h"
00102 
00103 template<typename Type>
00104 class GlobalModule;
00105 typedef GlobalModule<VirtualFileSystem> GlobalFileSystemModule;
00106 
00107 template<typename Type>
00108 class GlobalModuleRef;
00109 typedef GlobalModuleRef<VirtualFileSystem> GlobalFileSystemModuleRef;
00110 
00111 inline VirtualFileSystem& GlobalFileSystem ()
00112 {
00113     return GlobalFileSystemModule::getTable();
00114 }
00115 
00117 inline int vfsLoadFile (const std::string& filename, void** buffer, int index = 0)
00118 {
00119     return static_cast<int> (GlobalFileSystem().loadFile(filename, buffer));
00120 }
00121 
00123 inline void vfsFreeFile (void* p)
00124 {
00125     GlobalFileSystem().freeFile(p);
00126 }
00127 
00128 #endif

Generated by  doxygen 1.6.2