Skip to content

Commit

Permalink
Refactor|FileSys: Minor cleanup refactorings
Browse files Browse the repository at this point in the history
The findAll() methods of de::FS1 which take a predicate callback
function now use a de::File1 reference rather than a FileHandle
(because users of this class do not need to know that the loaded
file list uses handles).

Reordered de::File1 constructor arguments.
  • Loading branch information
danij-deng committed Oct 21, 2012
1 parent d5830bb commit f320c6f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/file.h
Expand Up @@ -69,12 +69,12 @@ class File1

public:
/**
* @param path Path to this file in the virtual file system.
* @param hndl Handle to the file. Ownership of the handle is given to this instance.
* @param path Path to this file in the virtual file system.
* @param info Info descriptor for the file. A copy is made.
* @param container Container of this file. Can be @c NULL.
*/
File1(char const* _path, FileHandle& hndl, FileInfo const& _info, File1* container = 0);
File1(FileHandle& hndl, char const* _path, FileInfo const& _info, File1* container = 0);

/**
* Release all memory acquired for objects linked with this resource.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/fs_main.h
Expand Up @@ -260,7 +260,7 @@ namespace de
*
* @return Number of files found.
*/
int findAll(bool (*predicate)(FileHandle* hndl, void* parameters), void* parameters,
int findAll(bool (*predicate)(File1& file, void* parameters), void* parameters,
FileList& found) const;

/**
Expand All @@ -276,7 +276,7 @@ namespace de
* @return Number of files found.
*/
template <typename Type>
int findAll(bool (*predicate)(FileHandle* hndl, void* parameters), void* parameters,
int findAll(bool (*predicate)(File1& file, void* parameters), void* parameters,
FileList& found) const
{
findAll(predicate, parameters, found);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/file.cpp
Expand Up @@ -30,7 +30,7 @@

namespace de {

File1::File1(char const* _path, FileHandle& hndl, FileInfo const& _info, File1* _container)
File1::File1(FileHandle& hndl, char const* _path, FileInfo const& _info, File1* _container)
: handle_(&hndl), info_(_info), container_(_container), flags(DefaultFlags)
{
// Used to favor newer files when duplicates are pruned.
Expand Down
9 changes: 4 additions & 5 deletions doomsday/engine/portable/src/fs_main.cpp
Expand Up @@ -931,14 +931,14 @@ int FS1::findAll(FS1::FileList& found) const
return numFound;
}

int FS1::findAll(bool (*predicate)(de::FileHandle* hndl, void* parameters), void* parameters,
int FS1::findAll(bool (*predicate)(de::File1& file, void* parameters), void* parameters,
FS1::FileList& found) const
{
int numFound = 0;
DENG2_FOR_EACH(i, d->loadedFiles, FS1::FileList::const_iterator)
{
// Interested in this file?
if(predicate && !predicate(*i, parameters)) continue; // Nope.
if(predicate && !predicate((*i)->file(), parameters)) continue; // Nope.

found.push_back(*i);
numFound += 1;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ de::File1& FS1::interpret(de::FileHandle& hndl, char const* path, FileInfo const
}
else
{
interpretedFile = new File1(path, hndl, info);
interpretedFile = new File1(hndl, path, info);
}
}

Expand Down Expand Up @@ -1971,9 +1971,8 @@ static ddstring_t* composeFilePathString(FS1::FileList& files, int flags = DEFAU
return str;
}

static bool findCustomFilesPredicate(de::FileHandle* hndl, void* /*parameters*/)
static bool findCustomFilesPredicate(de::File1& file, void* /*parameters*/)
{
de::File1& file = hndl->file();
if(file.hasCustom())
{
ddstring_t const* path = file.path();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/lumpfileadaptor.cpp
Expand Up @@ -27,7 +27,7 @@ namespace de {

LumpFileAdaptor::LumpFileAdaptor(FileHandle& hndl, char const* path,
FileInfo const& info, File1* container)
: File1(path, hndl, info, container)
: File1(hndl, path, info, container)
{}

LumpFileAdaptor::~LumpFileAdaptor()
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/wad.cpp
Expand Up @@ -59,7 +59,7 @@ class WadFile : public File1
{
public:
WadFile::WadFile(FileHandle& hndl, char const* path, FileInfo const& info, File1* container)
: File1(path, hndl, info, container), crc_(0)
: File1(hndl, path, info, container), crc_(0)
{}

uint crc() const { return crc_; }
Expand Down Expand Up @@ -289,7 +289,7 @@ struct Wad::Instance
};

Wad::Wad(FileHandle& hndl, char const* path, FileInfo const& info, File1* container)
: File1(path, hndl, info, container)
: File1(hndl, path, info, container)
{
d = new Instance(this, hndl, path);
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/zip.cpp
Expand Up @@ -142,7 +142,7 @@ class ZipFile : public File1
{
public:
ZipFile::ZipFile(FileHandle& hndl, char const* path, FileInfo const& info, File1* container)
: File1(path, hndl, info, container)
: File1(hndl, path, info, container)
{}
};

Expand Down Expand Up @@ -458,7 +458,7 @@ struct Zip::Instance
};

Zip::Zip(FileHandle& hndl, char const* path, FileInfo const& info, File1* container)
: File1(path, hndl, info, container)
: File1(hndl, path, info, container)
{
d = new Instance(this);
}
Expand Down

0 comments on commit f320c6f

Please sign in to comment.