Skip to content

Commit

Permalink
libdoomsday|FS1: Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 18, 2014
1 parent 9c94d2c commit 4e3464b
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 159 deletions.
11 changes: 1 addition & 10 deletions doomsday/libdoomsday/include/doomsday/filesys/filehandle.h
Expand Up @@ -120,7 +120,7 @@ class LIBDOOMSDAY_PUBLIC FileHandle
* @param lump The lump to be opened.
* @param dontBuffer @c true= do not buffer a copy of the lump.
*/
static FileHandle *fromLump(File1 &lump, bool dontBuffer);
static FileHandle *fromLump(File1 &lump, bool dontBuffer = false);

/**
* Create a new handle on the specified native file.
Expand All @@ -130,15 +130,6 @@ class LIBDOOMSDAY_PUBLIC FileHandle
*/
static FileHandle *fromNativeFile(FILE &nativeFile, size_t baseOffset);

/**
* Create a duplicate of handle @a hndl. Note that the duplicate is in
* fact a "reference" to the original, so all changes to the file which they
* represent are implicitly shared.
*
* @param hndl Handle to be duplicated.
*/
static FileHandle *dup(FileHandle const &hndl);

private:
FileHandle();

Expand Down
51 changes: 21 additions & 30 deletions doomsday/libdoomsday/src/filesys/filehandle.cpp
Expand Up @@ -70,28 +70,6 @@ static void errorIfNotValid(FileHandle const &file, char const * /*callerName*/)
if(!file.isValid()) exit(1);
}

FileHandle *FileHandle::fromLump(File1 &lump, bool dontBuffer)
{
LOG_AS("FileHandle::fromLump");

FileHandle *hndl = new FileHandle();
// Init and load in the lump data.
hndl->d->file = &lump;
hndl->d->flags.open = true;
if(!dontBuffer)
{
hndl->d->size = lump.size();
hndl->d->pos = hndl->d->data = (uint8_t *) M_Malloc(hndl->d->size);

LOGDEV_RES_XVERBOSE_DEBUGONLY("[%p] Buffering \"%s:%s\"...", dintptr(hndl)
<< NativePath(lump.container().composePath()).pretty()
<< NativePath(lump.composePath()).pretty());

lump.read((uint8_t *)hndl->d->data, 0, lump.size());
}
return hndl;
}

FileHandle::FileHandle()
{
d = new Instance();
Expand Down Expand Up @@ -297,7 +275,7 @@ FileHandle &FileHandle::rewind()
return *this;
}

FileHandle *FileHandle::fromFile(File1 &file)
FileHandle *FileHandle::fromFile(File1 &file) // static
{
FileHandle *hndl = new FileHandle();
hndl->d->file = &file;
Expand All @@ -306,7 +284,7 @@ FileHandle *FileHandle::fromFile(File1 &file)
return hndl;
}

FileHandle *FileHandle::fromNativeFile(FILE &file, size_t baseOffset)
FileHandle *FileHandle::fromNativeFile(FILE &file, size_t baseOffset) // static
{
FileHandle *hndl = new FileHandle();
hndl->d->flags.open = true;
Expand All @@ -315,13 +293,26 @@ FileHandle *FileHandle::fromNativeFile(FILE &file, size_t baseOffset)
return hndl;
}

FileHandle *FileHandle::dup(FileHandle const &hndl)
FileHandle *FileHandle::fromLump(File1 &lump, bool dontBuffer) // static
{
FileHandle *clone = new FileHandle();
clone->d->flags.open = true;
clone->d->flags.reference = true;
clone->d->file = &hndl.file();
return clone;
LOG_AS("FileHandle::fromLump");

FileHandle *hndl = new FileHandle();
// Init and load in the lump data.
hndl->d->file = &lump;
hndl->d->flags.open = true;
if(!dontBuffer)
{
hndl->d->size = lump.size();
hndl->d->pos = hndl->d->data = (uint8_t *) M_Malloc(hndl->d->size);

LOGDEV_RES_XVERBOSE_DEBUGONLY("[%p] Buffering \"%s:%s\"...", dintptr(hndl)
<< NativePath(lump.container().composePath()).pretty()
<< NativePath(lump.composePath()).pretty());

lump.read((uint8_t *)hndl->d->data, 0, lump.size());
}
return hndl;
}

} // namespace de

0 comments on commit 4e3464b

Please sign in to comment.