]> icculus.org git repositories - divverent/netradiant.git/blob - include/ifilesystem.h
local variables ALSO work better when declared
[divverent/netradiant.git] / include / ifilesystem.h
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #if !defined(INCLUDED_IFILESYSTEM_H)
23 #define INCLUDED_IFILESYSTEM_H
24
25 #include <cstddef>
26 #include "generic/constant.h"
27 #include "generic/callbackfwd.h"
28
29 typedef Callback1<const char*> ArchiveNameCallback;
30 typedef Callback1<const char*> FileNameCallback;
31
32 class ArchiveFile;
33 class ArchiveTextFile;
34 class Archive;
35
36 class ModuleObserver;
37
38 typedef struct _GSList GSList;
39
40 /// The Virtual File System.
41 class VirtualFileSystem
42 {
43 public:
44   INTEGER_CONSTANT(Version, 1);
45   STRING_CONSTANT(Name, "VFS");
46
47   /// \brief Adds a root search \p path.
48   /// Called before \c initialise.
49   virtual void initDirectory(const char *path) = 0;
50   /// \brief Initialises the filesystem.
51   /// Called after all root search paths have been added.
52   virtual void initialise() = 0;
53   /// \brief Shuts down the filesystem.
54   virtual void shutdown() = 0;
55
56   /// \brief Returns the file identified by \p filename opened in binary mode, or 0 if not found.
57   /// The caller must \c release() the file returned if it is not 0.
58   virtual ArchiveFile* openFile(const char* filename) = 0;
59   /// \brief Returns the file identified by \p filename opened in text mode, or 0 if not found.
60   /// The caller must \c release() the file returned if it is not 0.
61   virtual ArchiveTextFile* openTextFile(const char* filename) = 0;
62
63   /// \brief Opens the file identified by \p filename and reads it into \p buffer, or sets *\p buffer to 0 if not found.
64   /// Returns the size of the buffer allocated, or undefined value if *\p buffer is 0;
65   /// The caller must free the allocated buffer by calling \c freeFile
66   /// \deprecated Deprecated - use \c openFile.
67   virtual std::size_t loadFile(const char *filename, void **buffer) = 0;
68   /// \brief Frees the buffer returned by \c loadFile.
69   /// \deprecated Deprecated.
70   virtual void freeFile(void *p) = 0;
71
72   /// \brief Calls \p callback for each directory under \p basedir.
73   virtual void forEachDirectory(const char* basedir, const FileNameCallback& callback, std::size_t depth = 1) = 0;
74   /// \brief Calls \p callback for each file under \p basedir matching \p extension.
75   /// Use "*" as \p extension to match all file extensions.
76   virtual void forEachFile(const char* basedir, const char* extension, const FileNameCallback& callback, std::size_t depth = 1) = 0;
77
78   /// \brief Returns a list containing the relative names of all the directories under \p basedir.
79   /// The caller must free the returned list by calling \c clearFileDirList;
80   /// \deprecated Deprecated - use \c forEachDirectory.
81   virtual GSList* getDirList(const char *basedir) = 0;
82   /// \brief Returns a list containing the relative names of the files under \p basedir (\p extension can be "*" for all files).
83   /// The caller must free the returned list by calling \c clearFileDirList.
84   /// \deprecated Deprecated - use \c forEachFile.
85   virtual GSList* getFileList(const char *basedir, const char *extension) = 0;
86   /// \brief Frees the \p list returned from \c getDirList or \c getFileList.
87   /// \deprecated Deprecated.
88   virtual void clearFileDirList(GSList **list) = 0;
89
90   /// \brief Returns the absolute filename for a relative \p name, or "" if not found.
91   virtual const char* findFile(const char* name) = 0;
92   /// \brief Returns the filesystem root for an absolute \p name, or "" if not found.
93   /// This can be used to convert an absolute name to a relative name.
94   virtual const char* findRoot(const char* name) = 0;
95
96   /// \brief Attach an \p observer whose realise() and unrealise() methods will be called when the filesystem is initialised or shut down.
97   virtual void attach(ModuleObserver& observer) = 0;
98   /// \brief Detach an \p observer previously-attached by calling \c attach.
99   virtual void detach(ModuleObserver& observer) = 0;
100
101   virtual Archive* getArchive(const char* archiveName, bool pakonly=true) = 0;
102   virtual void forEachArchive(const ArchiveNameCallback& callback, bool pakonly=true, bool reverse=false) = 0;
103 };
104
105 #include "modulesystem.h"
106
107 template<typename Type>
108 class GlobalModule;
109 typedef GlobalModule<VirtualFileSystem> GlobalFileSystemModule;
110
111 template<typename Type>
112 class GlobalModuleRef;
113 typedef GlobalModuleRef<VirtualFileSystem> GlobalFileSystemModuleRef;
114
115 inline VirtualFileSystem& GlobalFileSystem()
116 {
117   return GlobalFileSystemModule::getTable();
118 }
119
120
121 /// \deprecated Use \c openFile.
122 inline int vfsLoadFile(const char* filename, void** buffer, int index = 0)
123 {
124         return static_cast<int>(GlobalFileSystem().loadFile(filename, buffer));
125 };
126
127 /// \deprecated Deprecated.
128 inline void vfsFreeFile(void* p)
129 {
130         GlobalFileSystem().freeFile(p);
131 }
132
133 #endif