ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

FSDirectory models a directory tree from the filesystem and allows users to access it through the Archive interface. More...

#include <fs.h>

Inheritance diagram for Common::FSDirectory:
Collaboration diagram for Common::FSDirectory:

List of all members.

Public Member Functions

 FSDirectory (const String &name, int depth=1, bool flat=false)
 Create a FSDirectory representing a tree with the specified depth.
 FSDirectory (const FSNode &node, int depth=1, bool flat=false)
 FSDirectory (const String &prefix, const String &name, int depth=1, bool flat=false)
 Create a FSDirectory representing a tree with the specified depth.
 FSDirectory (const String &prefix, const FSNode &node, int depth=1, bool flat=false)
virtual ~FSDirectory ()
FSNode getFSNode () const
 This return the underlying FSNode of the FSDirectory.
FSDirectorygetSubDirectory (const String &name, int depth=1, bool flat=false)
 Create a new FSDirectory pointing to a sub directory of the instance.
FSDirectorygetSubDirectory (const String &prefix, const String &name, int depth=1, bool flat=false)
virtual bool hasFile (const String &name) const
 Checks for existence in the cache.
virtual int listMatchingMembers (ArchiveMemberList &list, const String &pattern) const
 Returns a list of matching file names.
virtual int listMembers (ArchiveMemberList &list) const
 Returns a list of all the files in the cache.
virtual const ArchiveMemberPtr getMember (const String &name) const
 Get a ArchiveMember representation of the specified file.
virtual SeekableReadStreamcreateReadStreamForMember (const String &name) const
 Open the specified file.

Private Types

typedef HashMap< String,
FSNode, IgnoreCase_Hash,
IgnoreCase_EqualTo
NodeCache

Private Member Functions

void setPrefix (const String &prefix)
FSNodelookupCache (NodeCache &cache, const String &name) const
void cacheDirectoryRecursive (FSNode node, int depth, const String &prefix) const
void ensureCached () const

Private Attributes

FSNode _node
String _prefix
NodeCache _fileCache
NodeCache _subDirCache
bool _cached
int _depth
bool _flat

Detailed Description

FSDirectory models a directory tree from the filesystem and allows users to access it through the Archive interface.

Searching is case-insensitive, since the intended goal is supporting retrieval of game data.

FSDirectory can represent a single directory, or a tree with specified depth, depending on the value passed to the 'depth' parameter in the constructors. In the default mode, filenames are cached with their relative path, with elements separated by slashes, e.g.:

c:.ext

would be cached as 'data/file.ext' if FSDirectory was created on 'c:/my' with depth > 1. If depth was 1, then the 'data' subdirectory would have been ignored, instead. Again, only SLASHES are used as separators independently from the underlying file system.

Relative paths can be specified when calling matching functions like createReadStreamForMember(), hasFile(), listMatchingMembers() and listMembers(). Please see the function specific comments for more information.

If the 'flat' argument to the constructor is true, files in subdirectories are cached without the relative path, so in the example above c:.ext would be cached as file.ext.

Client code can customize cache by using the constructors with the 'prefix' parameter. In this case, the prefix is prepended to each entry in the cache, and effectively treated as a 'virtual' parent subdirectory. FSDirectory adds a trailing slash to prefix if needed. Following on with the previous example and using 'your' as prefix, the cache entry would have been 'your/data/file.ext'. This is done both in non-flat and flat mode.

Definition at line 269 of file fs.h.


Member Typedef Documentation


Constructor & Destructor Documentation

Common::FSDirectory::FSDirectory ( const String name,
int  depth = 1,
bool  flat = false 
)

Create a FSDirectory representing a tree with the specified depth.

Will result in an unbound FSDirectory if name is not found on the filesystem or if the node is not a valid directory.

Definition at line 165 of file fs.cpp.

Common::FSDirectory::FSDirectory ( const FSNode node,
int  depth = 1,
bool  flat = false 
)

Definition at line 155 of file fs.cpp.

Common::FSDirectory::FSDirectory ( const String prefix,
const String name,
int  depth = 1,
bool  flat = false 
)

Create a FSDirectory representing a tree with the specified depth.

The parameter prefix is prepended to the keys in the cache. See class comment.

Definition at line 169 of file fs.cpp.

Common::FSDirectory::FSDirectory ( const String prefix,
const FSNode node,
int  depth = 1,
bool  flat = false 
)

Definition at line 159 of file fs.cpp.

Common::FSDirectory::~FSDirectory (  )  [virtual]

Definition at line 175 of file fs.cpp.


Member Function Documentation

void Common::FSDirectory::cacheDirectoryRecursive ( FSNode  node,
int  depth,
const String prefix 
) const [private]

Definition at line 255 of file fs.cpp.

SeekableReadStream * Common::FSDirectory::createReadStreamForMember ( const String name  )  const [virtual]

Open the specified file.

A full match of relative path and filename is needed for success.

Implements Common::Archive.

Definition at line 226 of file fs.cpp.

void Common::FSDirectory::ensureCached (  )  const [private]

Definition at line 292 of file fs.cpp.

FSNode Common::FSDirectory::getFSNode (  )  const

This return the underlying FSNode of the FSDirectory.

Definition at line 185 of file fs.cpp.

const ArchiveMemberPtr Common::FSDirectory::getMember ( const String name  )  const [virtual]

Get a ArchiveMember representation of the specified file.

A full match of relative path and filename is needed for success.

Implements Common::Archive.

Definition at line 209 of file fs.cpp.

FSDirectory * Common::FSDirectory::getSubDirectory ( const String name,
int  depth = 1,
bool  flat = false 
)

Create a new FSDirectory pointing to a sub directory of the instance.

See class comment for an explanation of the prefix parameter.

Returns:
a new FSDirectory instance

Definition at line 240 of file fs.cpp.

FSDirectory * Common::FSDirectory::getSubDirectory ( const String prefix,
const String name,
int  depth = 1,
bool  flat = false 
)

Definition at line 244 of file fs.cpp.

bool Common::FSDirectory::hasFile ( const String name  )  const [virtual]

Checks for existence in the cache.

A full match of relative path and filename is needed for success.

Implements Common::Archive.

Definition at line 201 of file fs.cpp.

int Common::FSDirectory::listMatchingMembers ( ArchiveMemberList list,
const String pattern 
) const [virtual]

Returns a list of matching file names.

Pattern can use GLOB wildcards.

Reimplemented from Common::Archive.

Definition at line 299 of file fs.cpp.

int Common::FSDirectory::listMembers ( ArchiveMemberList list  )  const [virtual]

Returns a list of all the files in the cache.

Implements Common::Archive.

Definition at line 322 of file fs.cpp.

FSNode * Common::FSDirectory::lookupCache ( NodeCache cache,
const String name 
) const [private]

Definition at line 189 of file fs.cpp.

void Common::FSDirectory::setPrefix ( const String prefix  )  [private]

Definition at line 178 of file fs.cpp.


Member Data Documentation

bool Common::FSDirectory::_cached [mutable, private]

Definition at line 279 of file fs.h.

int Common::FSDirectory::_depth [mutable, private]

Definition at line 280 of file fs.h.

Definition at line 278 of file fs.h.

bool Common::FSDirectory::_flat [mutable, private]

Definition at line 281 of file fs.h.

Definition at line 270 of file fs.h.

Definition at line 272 of file fs.h.

Definition at line 278 of file fs.h.


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


Generated on Sat Mar 23 2019 05:06:59 for ResidualVM by doxygen 1.7.1
curved edge   curved edge