ifilesystem.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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