FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
vfs.h
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 *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library 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 GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, 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 
56  class VFS {
57  public:
61  VFS();
62 
65  virtual ~VFS();
66 
67  void cleanup();
68 
75  void addProvider(VFSSourceProvider* provider);
76 
83  VFSSource* createSource(const std::string& path) const;
84 
88  void addNewSource(const std::string& path);
89 
90 
92  void addSource(VFSSource* source);
93 
95  void removeSource(VFSSource* source);
96 
102  bool exists(const std::string& file) const;
103 
109  bool isDirectory(const std::string& path) const;
110 
117  RawData* open(const std::string& path);
118 
124  std::set<std::string> listFiles(const std::string& path) const;
125 
135  std::set<std::string> listFiles(const std::string& path, const std::string& filterregex) const;
136 
142  std::set<std::string> listDirectories(const std::string& path) const;
143 
150  std::set<std::string> listDirectories(const std::string& path, const std::string& filterregex) const;
151 
152  private:
153  typedef std::vector<VFSSourceProvider*> type_providers;
154  type_providers m_providers;
155 
156  typedef std::vector<VFSSource*> type_sources;
157  type_sources m_sources;
158 
159  typedef std::set<std::string> type_usedfiles;
160  mutable type_usedfiles m_usedfiles;
161 
162  std::set<std::string> filterList(const std::set<std::string>& list, const std::string& fregex) const;
163  VFSSource* getSourceForFile(const std::string& file) const;
164  };
165 
166 }
167 
168 #endif