Mercurial > fife-parpg
comparison engine/core/vfs/vfs.h @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 #ifndef FIFE_VFS_VFS_H | |
23 #define FIFE_VFS_VFS_H | |
24 | |
25 // Standard C++ library includes | |
26 #include <set> | |
27 #include <string> | |
28 #include <vector> | |
29 | |
30 // 3rd party library includes | |
31 #include <boost/shared_ptr.hpp> | |
32 | |
33 // FIFE includes | |
34 // These includes are split up in two parts, separated by one empty line | |
35 // First block: files included from the FIFE root src directory | |
36 // Second block: files included from the same folder | |
37 | |
38 namespace FIFE { | |
39 | |
40 class RawData; | |
41 | |
42 class VFSSourceProvider; | |
43 class VFSSource; | |
44 | |
45 /** the main VFS (virtual file system) class | |
46 * | |
47 * The VFS is intended to provide transparent and portable access to files. | |
48 * @note The VFS searches for a provider in the order they are added to the | |
49 * VFS. Since the VFSHostSystem is added first, this implies, that host filesystem | |
50 * files will override whatever might be in other VFS Sources (e.g. the DAT files) | |
51 */ | |
52 class VFS { | |
53 public: | |
54 /** Constructor | |
55 * Called by the Engine on startup. Never create one yourself. | |
56 */ | |
57 VFS(); | |
58 | |
59 /** Destructor | |
60 */ | |
61 virtual ~VFS(); | |
62 | |
63 void cleanup(); | |
64 | |
65 /** add new VFSSourceProvider | |
66 * | |
67 * @NOTE VFS assumes ownership over the given provider - so don't do anything with it | |
68 * after you call this function, especialy don't delete it! | |
69 * @param provider the new provider | |
70 */ | |
71 void addProvider(VFSSourceProvider* provider); | |
72 | |
73 /** tries to create a new VFSSource for the given file | |
74 * | |
75 * all currently known VFSSourceProviders are tried until one succeeds - if no provider succeeds 0 is returned | |
76 * @param file the archive-file | |
77 * @return the new VFSSource or 0 if no provider was succesfull or the file was already used as source | |
78 */ | |
79 VFSSource* createSource(const std::string& path) const; | |
80 | |
81 /** create a new Source and add it to VFS | |
82 * @see VFSSource* createSource(const std::string& file) const | |
83 */ | |
84 void addNewSource(const std::string& path); | |
85 | |
86 | |
87 /** Add a new VFSSource */ | |
88 void addSource(VFSSource* source); | |
89 | |
90 /** remove a VFSSource */ | |
91 void removeSource(VFSSource* source); | |
92 | |
93 /** Check if the given file exists | |
94 * | |
95 * @param file the filename | |
96 * @return true if it exists, false if not | |
97 */ | |
98 bool exists(const std::string& file) const; | |
99 | |
100 /** Check if the given path is a directory | |
101 * | |
102 * @param path to check | |
103 * @return true if it is a directory, false if not | |
104 */ | |
105 bool isDirectory(const std::string& path) const; | |
106 | |
107 /** Open a file | |
108 * | |
109 * @param path the file to open | |
110 * @return the opened file; delete this when done. | |
111 * @throws NotFound if the file cannot be found | |
112 */ | |
113 RawData* open(const std::string& path); | |
114 | |
115 /** Get a filelist of the given directory | |
116 * | |
117 * @param path the directory | |
118 * @return the filelist | |
119 */ | |
120 std::set<std::string> listFiles(const std::string& path) const; | |
121 | |
122 /** List the files of a given directory matching a regex | |
123 * | |
124 * The whole string has to match the regex, this means if you want all files that end with .map don't search for | |
125 * "\.map" but ".*\.map" (and escape the \) | |
126 * | |
127 * @param path the directory | |
128 * @param filterregex the regex the files have to match | |
129 * @return the filelist | |
130 */ | |
131 std::set<std::string> listFiles(const std::string& path, const std::string& filterregex) const; | |
132 | |
133 /** Get a directorylist of the given directory | |
134 * | |
135 * @param path the directory | |
136 * @return the directorylist | |
137 */ | |
138 std::set<std::string> listDirectories(const std::string& path) const; | |
139 | |
140 /** List the subdirectorys of a given directory matching a regex | |
141 * | |
142 * @param path the directory | |
143 * @param filterregex the regex the files have to match | |
144 * @return the filelist | |
145 */ | |
146 std::set<std::string> listDirectories(const std::string& path, const std::string& filterregex) const; | |
147 | |
148 private: | |
149 typedef std::vector<VFSSourceProvider*> type_providers; | |
150 type_providers m_providers; | |
151 | |
152 typedef std::vector<VFSSource*> type_sources; | |
153 type_sources m_sources; | |
154 | |
155 typedef std::set<std::string> type_usedfiles; | |
156 mutable type_usedfiles m_usedfiles; | |
157 | |
158 std::set<std::string> filterList(const std::set<std::string>& list, const std::string& fregex) const; | |
159 std::string lower(const std::string&) const; | |
160 VFSSource* getSourceForFile(const std::string& file) const; | |
161 }; | |
162 | |
163 } | |
164 | |
165 #endif |