Skip to content

Commit

Permalink
Refactor|libdoomsday|FS1|Wad: Cleanup Wad construction
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 16, 2014
1 parent ee9ff22 commit fb30b69
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 177 deletions.
72 changes: 37 additions & 35 deletions doomsday/libdoomsday/include/doomsday/filesys/wad.h
Expand Up @@ -50,8 +50,8 @@ class LIBDOOMSDAY_PUBLIC Wad : public File1
* File system object for a lump in the WAD.
*
* The purpose of this abstraction is to redirect various File1 methods to the
* containing WAD file. Such a mechanism would be unnecessary in file system in
* which proper OO design is used for the package / file abstaction. -ds
* containing Wad file. Such a mechanism would be unnecessary in a file system
* in which proper OO design is used for the package / file abstraction. -ds
*/
class LumpFile : public File1
{
Expand Down Expand Up @@ -122,26 +122,6 @@ class LIBDOOMSDAY_PUBLIC Wad : public File1
Wad &wad() const;
};

/**
* Models an entry in the internal lump tree.
*/
struct Entry : public PathTree::Node
{
QScopedPointer<LumpFile> lumpFile; ///< File system object for the lump data.
uint crc; ///< CRC for the lump data.

Entry(PathTree::NodeArgs const &args)
: Node(args)
, crc (0)
{}

LumpFile &file() const {
DENG2_ASSERT(!lumpFile.isNull());
return *lumpFile;
}
};
typedef PathTreeT<Entry> LumpTree;

public:
Wad(FileHandle &hndl, String path, FileInfo const &info, File1 *container = 0);

Expand All @@ -165,19 +145,12 @@ class LIBDOOMSDAY_PUBLIC Wad : public File1
*/
inline bool isEmpty() { return !lumpCount(); }

/**
* Returns the Entry for the specified @a lumpIndex.
*
* @throws NotFoundError If @a lumpIndex is not valid.
*/
Entry &lumpEntry(int lumpIndex) const;

/**
* Convenient method of looking up the LumpFile for a given @a lumpIndex.
*
* @see lumpEntry(), Entry::file()
*/
inline LumpFile &lump(int lumpIndex) const { return lumpEntry(lumpIndex).file(); }
LumpFile &lump(int lumpIndex) const;

/**
* Read the data associated with lump @a lumpIndex into @a buffer.
Expand Down Expand Up @@ -251,11 +224,6 @@ class LIBDOOMSDAY_PUBLIC Wad : public File1
*/
uint calculateCRC();

/**
* Provides access to the internal LumpTree, for efficient traversal.
*/
LumpTree const &lumps() const;

public:
/**
* Determines whether a File looks like it could be accessed using Wad.
Expand All @@ -266,6 +234,40 @@ class LIBDOOMSDAY_PUBLIC Wad : public File1
*/
static bool recognise(FileHandle &file);

protected:
/**
* Models an entry in the internal lump tree.
*/
struct Entry : public PathTree::Node
{
dint32 offset;
dint32 size;
QScopedPointer<LumpFile> lumpFile; ///< File system object for the lump data.
uint crc; ///< CRC for the lump data.

Entry(PathTree::NodeArgs const &args)
: Node(args), offset(0), size(0), crc(0)
{}

LumpFile &file() const;

/// Recalculates CRC of the entry.
void update();
};
typedef PathTreeT<Entry> LumpTree;

/**
* Returns the Entry for the specified @a lumpIndex.
*
* @throws NotFoundError If @a lumpIndex is not valid.
*/
Entry &lumpEntry(int lumpIndex) const;

/**
* Provides access to the internal LumpTree, for efficient traversal.
*/
LumpTree const &lumps() const;

private:
DENG2_PRIVATE(d)
};
Expand Down

0 comments on commit fb30b69

Please sign in to comment.