vfs.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_VFS_VFS_H
00023 #define FIFE_VFS_VFS_H
00024 
00025 // Standard C++ library includes
00026 #include <set>
00027 #include <string>
00028 #include <vector>
00029 
00030 // 3rd party library includes
00031 #include <boost/shared_ptr.hpp>
00032 
00033 // FIFE includes
00034 // These includes are split up in two parts, separated by one empty line
00035 // First block: files included from the FIFE root src directory
00036 // Second block: files included from the same folder
00037 #include "util/base/singleton.h"
00038 
00039 
00040 namespace FIFE {
00041 
00042     class RawData;
00043 
00044     class VFSSourceProvider;
00045     class VFSSource;
00046 
00058     class VFS : public DynamicSingleton<VFS>{
00059         public:
00063             VFS();
00064 
00067             virtual ~VFS();
00068 
00069             void cleanup();
00070 
00077             void addProvider(VFSSourceProvider* provider);
00078 
00085             VFSSource* createSource(const std::string& path) const;
00086 
00090             void addNewSource(const std::string& path);
00091 
00092 
00094             void addSource(VFSSource* source);
00095 
00097             void removeSource(VFSSource* source);
00098 
00104             bool exists(const std::string& file) const;
00105 
00111             bool isDirectory(const std::string& path) const;
00112 
00119             RawData* open(const std::string& path);
00120 
00126             std::set<std::string> listFiles(const std::string& path) const;
00127 
00137             std::set<std::string> listFiles(const std::string& path, const std::string& filterregex) const;
00138 
00144             std::set<std::string> listDirectories(const std::string& path) const;
00145 
00152             std::set<std::string> listDirectories(const std::string& path, const std::string& filterregex) const;
00153 
00154         private:
00155             typedef std::vector<VFSSourceProvider*> type_providers;
00156             type_providers m_providers;
00157 
00158             typedef std::vector<VFSSource*> type_sources;
00159             type_sources m_sources;
00160 
00161             typedef std::set<std::string> type_usedfiles;
00162             mutable type_usedfiles m_usedfiles;
00163 
00164             std::set<std::string> filterList(const std::set<std::string>& list, const std::string& fregex) const;
00165             VFSSource* getSourceForFile(const std::string& file) const;
00166     };
00167 
00168 }
00169 
00170 #endif