FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FIFE::VFS Class Reference

the main VFS (virtual file system) class More...

#include <vfs.h>

+ Inheritance diagram for FIFE::VFS:
+ Collaboration diagram for FIFE::VFS:

Public Member Functions

 VFS ()
 Constructor Called by the Engine on startup. More...
 
virtual ~VFS ()
 Destructor. More...
 
void cleanup ()
 
void addProvider (VFSSourceProvider *provider)
 add new VFSSourceProvider More...
 
VFSSourcecreateSource (const std::string &path) const
 tries to create a new VFSSource for the given file More...
 
void addNewSource (const std::string &path)
 create a new Source and add it to VFS More...
 
void addSource (VFSSource *source)
 Add a new VFSSource. More...
 
void removeSource (VFSSource *source)
 remove a VFSSource More...
 
bool exists (const std::string &file) const
 Check if the given file exists. More...
 
bool isDirectory (const std::string &path) const
 Check if the given path is a directory. More...
 
RawDataopen (const std::string &path)
 Open a file. More...
 
std::set< std::string > listFiles (const std::string &path) const
 Get a filelist of the given directory. More...
 
std::set< std::string > listFiles (const std::string &path, const std::string &filterregex) const
 List the files of a given directory matching a regex. More...
 
std::set< std::string > listDirectories (const std::string &path) const
 Get a directorylist of the given directory. More...
 
std::set< std::string > listDirectories (const std::string &path, const std::string &filterregex) const
 List the subdirectorys of a given directory matching a regex. More...
 
- Public Member Functions inherited from FIFE::DynamicSingleton< VFS >
 DynamicSingleton ()
 
virtual ~DynamicSingleton ()
 

Private Types

typedef std::vector
< VFSSourceProvider * > 
type_providers
 
typedef std::vector< VFSSource * > type_sources
 
typedef std::set< std::string > type_usedfiles
 

Private Member Functions

std::set< std::string > filterList (const std::set< std::string > &list, const std::string &fregex) const
 
VFSSourcegetSourceForFile (const std::string &file) const
 

Private Attributes

type_providers m_providers
 
type_sources m_sources
 
type_usedfiles m_usedfiles
 

Additional Inherited Members

- Static Public Member Functions inherited from FIFE::DynamicSingleton< VFS >
static VFSinstance ()
 

Detailed Description

the main VFS (virtual file system) class

The VFS is intended to provide transparent and portable access to files.

Note
The VFS searches for a provider in the order they are added to the VFS. Since the VFSHostSystem is added first, this implies, that host filesystem files will override whatever might be in other VFS Sources (e.g. the DAT files)
All filenames have to be lowercase. The VFS will convert them to lowercase and emit a warning. This is done to avoid problems with filesystems which are not case sensitive.

Definition at line 58 of file vfs.h.

Member Typedef Documentation

typedef std::vector<VFSSourceProvider*> FIFE::VFS::type_providers
private

Definition at line 155 of file vfs.h.

typedef std::vector<VFSSource*> FIFE::VFS::type_sources
private

Definition at line 158 of file vfs.h.

typedef std::set<std::string> FIFE::VFS::type_usedfiles
private

Definition at line 161 of file vfs.h.

Constructor & Destructor Documentation

FIFE::VFS::VFS ( )

Constructor Called by the Engine on startup.

Never create one yourself.

Definition at line 47 of file vfs.cpp.

FIFE::VFS::~VFS ( )
virtual

Destructor.

Definition at line 49 of file vfs.cpp.

References cleanup().

Member Function Documentation

void FIFE::VFS::addNewSource ( const std::string &  path)

create a new Source and add it to VFS

See Also
VFSSource* createSource(const std::string& file) const

Definition at line 101 of file vfs.cpp.

References FIFE::_log, addSource(), createSource(), and FL_WARN.

void FIFE::VFS::addProvider ( VFSSourceProvider provider)

add new VFSSourceProvider

Note
VFS assumes ownership over the given provider - so don't do anything with it after you call this function, especialy don't delete it!
Parameters
providerthe new provider

Definition at line 66 of file vfs.cpp.

References FIFE::_log, FL_LOG, FIFE::VFSSourceProvider::getName(), m_providers, and FIFE::VFSSourceProvider::setVFS().

Referenced by FIFE::Engine::init().

+ Here is the caller graph for this function:

void FIFE::VFS::addSource ( VFSSource source)

Add a new VFSSource.

Definition at line 110 of file vfs.cpp.

References m_sources.

Referenced by addNewSource(), and FIFE::Engine::init().

+ Here is the caller graph for this function:

void FIFE::VFS::cleanup ( )

Definition at line 53 of file vfs.cpp.

References m_providers, and m_sources.

Referenced by ~VFS().

+ Here is the caller graph for this function:

VFSSource * FIFE::VFS::createSource ( const std::string &  path) const

tries to create a new VFSSource for the given file

all currently known VFSSourceProviders are tried until one succeeds - if no provider succeeds 0 is returned

Parameters
paththe archive-file
Returns
the new VFSSource or 0 if no provider was succesfull or the file was already used as source

Definition at line 72 of file vfs.cpp.

References FIFE::_log, FIFE::VFSSourceProvider::createSource(), FL_WARN, FIFE::VFSSourceProvider::getName(), FIFE::VFSSourceProvider::isReadable(), m_providers, m_usedfiles, and FIFE::Exception::what().

Referenced by addNewSource().

+ Here is the caller graph for this function:

bool FIFE::VFS::exists ( const std::string &  file) const

Check if the given file exists.

Parameters
filethe filename
Returns
true if it exists, false if not

Definition at line 131 of file vfs.cpp.

References getSourceForFile().

Referenced by FIFE::ZipProvider::isReadable().

+ Here is the caller graph for this function:

std::set< std::string > FIFE::VFS::filterList ( const std::set< std::string > &  list,
const std::string &  fregex 
) const
private

Definition at line 199 of file vfs.cpp.

Referenced by listDirectories(), and listFiles().

+ Here is the caller graph for this function:

VFSSource * FIFE::VFS::getSourceForFile ( const std::string &  file) const
private

Definition at line 120 of file vfs.cpp.

References FIFE::_log, FIFE::VFSSource::fileExists(), FL_WARN, and m_sources.

Referenced by exists(), and open().

+ Here is the caller graph for this function:

bool FIFE::VFS::isDirectory ( const std::string &  path) const

Check if the given path is a directory.

Parameters
pathto check
Returns
true if it is a directory, false if not

Definition at line 135 of file vfs.cpp.

References listDirectories().

std::set< std::string > FIFE::VFS::listDirectories ( const std::string &  path) const

Get a directorylist of the given directory.

Parameters
paththe directory
Returns
the directorylist

Definition at line 183 of file vfs.cpp.

References m_sources.

Referenced by isDirectory(), listDirectories(), and FIFE::MapLoader::loadImportDirectory().

+ Here is the caller graph for this function:

std::set< std::string > FIFE::VFS::listDirectories ( const std::string &  path,
const std::string &  filterregex 
) const

List the subdirectorys of a given directory matching a regex.

Parameters
paththe directory
filterregexthe regex the files have to match
Returns
the filelist

Definition at line 194 of file vfs.cpp.

References filterList(), and listDirectories().

std::set< std::string > FIFE::VFS::listFiles ( const std::string &  path) const

Get a filelist of the given directory.

Parameters
paththe directory
Returns
the filelist

Definition at line 167 of file vfs.cpp.

References m_sources.

Referenced by listFiles(), and FIFE::MapLoader::loadImportDirectory().

+ Here is the caller graph for this function:

std::set< std::string > FIFE::VFS::listFiles ( const std::string &  path,
const std::string &  filterregex 
) const

List the files of a given directory matching a regex.

The whole string has to match the regex, this means if you want all files that end with .map don't search for "\.map" but ".*\.map" (and escape the )

Parameters
paththe directory
filterregexthe regex the files have to match
Returns
the filelist

Definition at line 178 of file vfs.cpp.

References filterList(), and listFiles().

RawData * FIFE::VFS::open ( const std::string &  path)

Open a file.

Parameters
paththe file to open
Returns
the opened file; delete this when done.
Exceptions
NotFoundif the file cannot be found

Definition at line 157 of file vfs.cpp.

References FIFE::_log, FL_DBG, getSourceForFile(), and FIFE::VFSSource::open().

Referenced by FIFE::AnimationLoader::isLoadable(), FIFE::ObjectLoader::isLoadable(), FIFE::MapLoader::isLoadable(), FIFE::AtlasLoader::isLoadable(), FIFE::ImageLoader::load(), FIFE::OggLoader::load(), FIFE::AnimationLoader::load(), FIFE::ObjectLoader::load(), FIFE::MapLoader::load(), FIFE::AtlasLoader::load(), FIFE::RawDataDAT1::RawDataDAT1(), and FIFE::RawDataDAT2::RawDataDAT2().

+ Here is the caller graph for this function:

void FIFE::VFS::removeSource ( VFSSource source)

remove a VFSSource

Definition at line 114 of file vfs.cpp.

References m_sources.

Referenced by FIFE::VFSSource::~VFSSource().

+ Here is the caller graph for this function:

Member Data Documentation

type_providers FIFE::VFS::m_providers
private

Definition at line 156 of file vfs.h.

Referenced by addProvider(), cleanup(), and createSource().

type_sources FIFE::VFS::m_sources
private

Definition at line 159 of file vfs.h.

Referenced by addSource(), cleanup(), getSourceForFile(), listDirectories(), listFiles(), and removeSource().

type_usedfiles FIFE::VFS::m_usedfiles
mutableprivate

Definition at line 162 of file vfs.h.

Referenced by createSource().


The documentation for this class was generated from the following files: