FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
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)
 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...
 
void removeSource (const std::string &path)
 
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...
 
bool hasSource (const std::string &path) const
 Checks if a source is already present in a provider. 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
 

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
 

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

◆ type_providers

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

Definition at line 163 of file vfs.h.

◆ type_sources

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

Definition at line 166 of file vfs.h.

Constructor & Destructor Documentation

◆ VFS()

FIFE::VFS::VFS ( )

Constructor Called by the Engine on startup.

Never create one yourself.

Definition at line 47 of file vfs.cpp.

◆ ~VFS()

FIFE::VFS::~VFS ( )
virtual

Destructor.

Definition at line 49 of file vfs.cpp.

References cleanup().

Member Function Documentation

◆ addNewSource()

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)

Definition at line 101 of file vfs.cpp.

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

◆ addProvider()

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:

◆ addSource()

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:

◆ cleanup()

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:

◆ createSource()

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

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(), hasSource(), FIFE::VFSSourceProvider::isReadable(), m_providers, and FIFE::Exception::what().

Referenced by addNewSource().

+ Here is the caller graph for this function:

◆ exists()

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 146 of file vfs.cpp.

References getSourceForFile().

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

+ Here is the caller graph for this function:

◆ filterList()

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

Definition at line 214 of file vfs.cpp.

Referenced by listDirectories(), and listFiles().

+ Here is the caller graph for this function:

◆ getSourceForFile()

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

Definition at line 135 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:

◆ hasSource()

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

Checks if a source is already present in a provider.

Parameters
paththe directory
Returns
true if the source is present, false if not

Definition at line 228 of file vfs.cpp.

References FIFE::VFSSourceProvider::getSource(), FIFE::VFSSourceProvider::hasSource(), m_providers, and m_sources.

Referenced by createSource().

+ Here is the caller graph for this function:

◆ isDirectory()

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 150 of file vfs.cpp.

References listDirectories().

◆ listDirectories() [1/2]

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 198 of file vfs.cpp.

References m_sources.

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

+ Here is the caller graph for this function:

◆ listDirectories() [2/2]

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 209 of file vfs.cpp.

References filterList(), and listDirectories().

◆ listFiles() [1/2]

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 182 of file vfs.cpp.

References m_sources.

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

+ Here is the caller graph for this function:

◆ listFiles() [2/2]

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 193 of file vfs.cpp.

References filterList(), and listFiles().

◆ open()

◆ removeSource() [1/2]

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

remove a VFSSource

Definition at line 114 of file vfs.cpp.

References m_sources.

Referenced by removeSource(), and FIFE::VFSSource::~VFSSource().

+ Here is the caller graph for this function:

◆ removeSource() [2/2]

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

Member Data Documentation

◆ m_providers

type_providers FIFE::VFS::m_providers
private

Definition at line 164 of file vfs.h.

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

◆ m_sources

type_sources FIFE::VFS::m_sources
private

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