FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
vfs.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 by the FIFE team *
3  * http://www.fifengine.net *
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 <string>
27 #include <vector>
28 #include <set>
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);
86 
90  void addNewSource(const std::string& path);
91 
93  void addSource(VFSSource* source);
94 
96  void removeSource(VFSSource* source);
97  void removeSource(const std::string& path);
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 
159  bool hasSource(const std::string& path) const;
160 
161 
162  private:
163  typedef std::vector<VFSSourceProvider*> type_providers;
164  type_providers m_providers;
165 
166  typedef std::vector<VFSSource*> type_sources;
167  type_sources m_sources;
168 
169  std::set<std::string> filterList(const std::set<std::string>& list, const std::string& fregex) const;
170  VFSSource* getSourceForFile(const std::string& file) const;
171  };
172 
173 }
174 
175 #endif
bool exists(const std::string &file) const
Check if the given file exists.
Definition: vfs.cpp:146
std::set< std::string > listFiles(const std::string &path) const
Get a filelist of the given directory.
Definition: vfs.cpp:182
void addProvider(VFSSourceProvider *provider)
add new VFSSourceProvider
Definition: vfs.cpp:66
VFSSource abstract baseclass.
Definition: vfssource.h:46
VFSSource * getSourceForFile(const std::string &file) const
Definition: vfs.cpp:135
RawData * open(const std::string &path)
Open a file.
Definition: vfs.cpp:172
void cleanup()
Definition: vfs.cpp:53
bool hasSource(const std::string &path) const
Checks if a source is already present in a provider.
Definition: vfs.cpp:228
void removeSource(VFSSource *source)
remove a VFSSource
Definition: vfs.cpp:114
VFSSourceProvider abstract baseclass.
std::set< std::string > filterList(const std::set< std::string > &list, const std::string &fregex) const
Definition: vfs.cpp:214
Another Singleton.
Definition: singleton.h:82
void addSource(VFSSource *source)
Add a new VFSSource.
Definition: vfs.cpp:110
virtual ~VFS()
Destructor.
Definition: vfs.cpp:49
bool isDirectory(const std::string &path) const
Check if the given path is a directory.
Definition: vfs.cpp:150
VFS()
Constructor Called by the Engine on startup.
Definition: vfs.cpp:47
the main VFS (virtual file system) class
Definition: vfs.h:58
std::vector< VFSSourceProvider * > type_providers
Definition: vfs.h:163
void addNewSource(const std::string &path)
create a new Source and add it to VFS
Definition: vfs.cpp:101
VFSSource * createSource(const std::string &path)
tries to create a new VFSSource for the given file
Definition: vfs.cpp:72
type_providers m_providers
Definition: vfs.h:164
type_sources m_sources
Definition: vfs.h:167
Used to access diffrent kinds of data.
Definition: rawdata.h:48
std::vector< VFSSource * > type_sources
Definition: vfs.h:166
std::set< std::string > listDirectories(const std::string &path) const
Get a directorylist of the given directory.
Definition: vfs.cpp:198