FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vfs.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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 <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;
157 
158  typedef std::vector<VFSSource*> type_sources;
160 
161  typedef std::set<std::string> type_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
Check if the given file exists.
Definition: vfs.cpp:131
std::set< std::string > listFiles(const std::string &path) const
Get a filelist of the given directory.
Definition: vfs.cpp:167
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:120
RawData * open(const std::string &path)
Open a file.
Definition: vfs.cpp:157
void cleanup()
Definition: vfs.cpp:53
type_usedfiles m_usedfiles
Definition: vfs.h:162
VFSSource * createSource(const std::string &path) const
tries to create a new VFSSource for the given file
Definition: vfs.cpp:72
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:199
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:135
VFS()
Constructor Called by the Engine on startup.
Definition: vfs.cpp:47
std::set< std::string > type_usedfiles
Definition: vfs.h:161
the main VFS (virtual file system) class
Definition: vfs.h:58
std::vector< VFSSourceProvider * > type_providers
Definition: vfs.h:155
void addNewSource(const std::string &path)
create a new Source and add it to VFS
Definition: vfs.cpp:101
type_providers m_providers
Definition: vfs.h:156
type_sources m_sources
Definition: vfs.h:159
Used to access diffrent kinds of data.
Definition: rawdata.h:48
std::vector< VFSSource * > type_sources
Definition: vfs.h:158
std::set< std::string > listDirectories(const std::string &path) const
Get a directorylist of the given directory.
Definition: vfs.cpp:183