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 #include "util/base/singleton.h"
38 
39 
40 namespace FIFE {
41 
42  class RawData;
43 
44  class VFSSourceProvider;
45  class VFSSource;
46 
58  class VFS : public DynamicSingleton<VFS>{
59  public:
63  VFS();
64 
67  virtual ~VFS();
68 
69  void cleanup();
70 
77  void addProvider(VFSSourceProvider* provider);
78 
85  VFSSource* createSource(const std::string& path) const;
86 
90  void addNewSource(const std::string& path);
91 
92 
94  void addSource(VFSSource* source);
95 
97  void removeSource(VFSSource* source);
98 
104  bool exists(const std::string& file) const;
105 
111  bool isDirectory(const std::string& path) const;
112 
119  RawData* open(const std::string& path);
120 
126  std::set<std::string> listFiles(const std::string& path) const;
127 
137  std::set<std::string> listFiles(const std::string& path, const std::string& filterregex) const;
138 
144  std::set<std::string> listDirectories(const std::string& path) const;
145 
152  std::set<std::string> listDirectories(const std::string& path, const std::string& filterregex) const;
153 
154  private:
155  typedef std::vector<VFSSourceProvider*> type_providers;
156  type_providers m_providers;
157 
158  typedef std::vector<VFSSource*> type_sources;
159  type_sources m_sources;
160 
161  typedef std::set<std::string> type_usedfiles;
162  mutable type_usedfiles m_usedfiles;
163 
164  std::set<std::string> filterList(const std::set<std::string>& list, const std::string& fregex) const;
165  VFSSource* getSourceForFile(const std::string& file) const;
166  };
167 
168 }
169 
170 #endif
bool exists(const std::string &file) const
Definition: vfs.cpp:129
std::set< std::string > listFiles(const std::string &path) const
Definition: vfs.cpp:165
void addProvider(VFSSourceProvider *provider)
Definition: vfs.cpp:64
RawData * open(const std::string &path)
Definition: vfs.cpp:155
VFSSource * createSource(const std::string &path) const
Definition: vfs.cpp:70
void removeSource(VFSSource *source)
Definition: vfs.cpp:112
void addSource(VFSSource *source)
Definition: vfs.cpp:108
virtual ~VFS()
Definition: vfs.cpp:47
bool isDirectory(const std::string &path) const
Definition: vfs.cpp:133
VFS()
Definition: vfs.cpp:45
Definition: vfs.h:58
void addNewSource(const std::string &path)
Definition: vfs.cpp:99
std::set< std::string > listDirectories(const std::string &path) const
Definition: vfs.cpp:181