Skip to content

Commit

Permalink
Refactor|FileSys: Removed redundant (duplicated) file system search a…
Browse files Browse the repository at this point in the history
…lgorithms

FS::collectFiles() has been replaced with FS::findAll(), which returns
a FileList instead of an array of AbstractFile pointers.

FS::collectPaths() has been replaced with a variant of FS::findAll()
that takes a "match predicate" function pointer which is called to
decide if a file is included in the result.

FS::collectLocalPaths() is no longer a public API function and is
now used internally by the FS class only.
  • Loading branch information
danij-deng committed Oct 12, 2012
1 parent 39dc865 commit b5c84e0
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 163 deletions.
45 changes: 15 additions & 30 deletions doomsday/engine/portable/include/fs_main.h
Expand Up @@ -58,21 +58,6 @@ typedef QList<DFile*> FileList;
*/
class FS
{
public:
struct PathListItem
{
String path;
int attrib;
PathListItem(QString const& _path, int _attrib = 0)
: path(_path), attrib(_attrib)
{}
bool operator < (PathListItem const& other) const
{
return path.compareWithoutCase(other.path) < 0;
}
};
typedef QList<PathListItem> PathList;

public:
FS();

Expand Down Expand Up @@ -104,14 +89,14 @@ class FS
void mapPath(char const* source, char const* destination);

/// @note Should be called after WADs have been processed.
void initLumpDirectoryMappings();
void initLumpPathMap();

/**
* Add a new lump mapping so that @a lumpName becomes visible as @a symbolicPath
* throughout the vfs.
* @note @a symbolicPath will be transformed into an absolute path if needed.
*/
void addLumpDirectoryMapping(char const* lumpName, char const* symbolicPath);
void mapPathToLump(char const* symbolicPath, char const* lumpName);

/**
* Reset known fileId records so that the next time F_CheckFileId() is
Expand Down Expand Up @@ -292,27 +277,27 @@ class FS
void closeAuxiliary();

/**
* @param count If not @c NULL the number of elements in the resultant
* array is written back here (for convenience).
* Finds all files.
*
* @param found Set of files that match the result.
*
* @return Array of ptrs to files in this system or @c NULL if empty.
* Ownership of the array passes to the caller who should ensure to
* release it with free() when no longer needed.
* @return Number of files found.
*/
AbstractFile** collectFiles(int* count);

/// Collect a list of paths including those which have been mapped.
PathList collectLocalPaths(ddstring_t const* searchPath, bool includeSearchPath);
int findAll(FileList& found);

/**
* Collect a list of loaded file paths.
* Finds all files which meet the supplied @a predicate.
*
* @param predicate If not @c NULL, this predicate evaluator callback must
* return @c true for a given path to be included in the
* resultant list.
* return @c true for a given file to be included in the
* @a found FileList.
* @param parameters Passed to the predicate evaluator callback.
* @param found Set of files that match the result.
*
* @return Number of files found.
*/
PathList collectPaths(bool (*predicate)(DFile* hndl, void* parameters) = 0, void* parameters = 0);
int findAll(bool (*predicate)(DFile* hndl, void* parameters), void* parameters,
FileList& found);

/**
* Print contents of the specified directory of the virtual file system.
Expand Down

0 comments on commit b5c84e0

Please sign in to comment.