Skip to content

Commit

Permalink
Refactor: Disposed of the pure abstract AbstractFile
Browse files Browse the repository at this point in the history
As a pure abstract base class for a file is no longer necessary,
AbstractFile has been refactored into a concrete base class named
de::File1 (the '1' suffix so as to avoid collision with the class
of the same name (and purpose) in libdeng2).

The redundant GenericFile has been dumped.
  • Loading branch information
danij-deng committed Oct 18, 2012
1 parent 23512e9 commit 76d29ef
Show file tree
Hide file tree
Showing 30 changed files with 238 additions and 444 deletions.
6 changes: 3 additions & 3 deletions doomsday/engine/api/dfile.h
Expand Up @@ -49,7 +49,7 @@ struct filelist_s;
namespace de {

/// @todo Should not be visible outside the engine.
class AbstractFile;
class File1;
class DFileBuilder;

/**
Expand All @@ -75,8 +75,8 @@ class DFile
bool hasFile() const;

/// @todo Should not be visible outside the engine.
AbstractFile& file();
AbstractFile& file() const;
File1& file();
File1& file() const;

/// @return @c true iff this handle's internal state is valid.
bool isValid() const;
Expand Down
6 changes: 2 additions & 4 deletions doomsday/engine/engine.pro
Expand Up @@ -129,7 +129,6 @@ DENG_HEADERS += \

# Private headers.
DENG_HEADERS += \
portable/include/abstractfile.h \
portable/include/abstractresource.h \
portable/include/audiodriver.h \
portable/include/audiodriver_music.h \
Expand Down Expand Up @@ -209,6 +208,7 @@ DENG_HEADERS += \
portable/include/edit_bsp.h \
portable/include/edit_map.h \
portable/include/fi_main.h \
portable/include/file.h \
portable/include/filedirectory.h \
portable/include/fileinfo.h \
portable/include/finaleinterpreter.h \
Expand All @@ -219,7 +219,6 @@ DENG_HEADERS += \
portable/include/game.h \
portable/include/gamemap.h \
portable/include/generators.h \
portable/include/genericfile.h \
portable/include/gl_defer.h \
portable/include/gl_deferredapi.h \
portable/include/gl_draw.h \
Expand Down Expand Up @@ -441,7 +440,6 @@ deng_nodisplaymode {

# Platform-independent sources.
SOURCES += \
portable/src/abstractfile.cpp \
portable/src/abstractresource.c \
portable/src/animator.c \
portable/src/audiodriver.c \
Expand Down Expand Up @@ -501,6 +499,7 @@ SOURCES += \
portable/src/edit_bsp.cpp \
portable/src/edit_map.c \
portable/src/fi_main.c \
portable/src/file.cpp \
portable/src/filedirectory.cpp \
portable/src/fileid.cpp \
portable/src/finaleinterpreter.c \
Expand All @@ -510,7 +509,6 @@ SOURCES += \
portable/src/game.cpp \
portable/src/gamemap.c \
portable/src/generators.c \
portable/src/genericfile.cpp \
portable/src/gl_defer.c \
portable/src/gl_deferredapi.c \
portable/src/gl_draw.c \
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/portable/include/dfilebuilder.h
Expand Up @@ -36,20 +36,20 @@ class DFileBuilder
static void shutdown();

/**
* Create a new handle on the AbstractFile @a file.
* Create a new handle on the File @a file.
*
* @param af VFS object representing the file being opened.
*/
static DFile* fromFile(AbstractFile& file);
static DFile* fromFile(File1& file);

/**
* Create a new handle on a lump of AbstractFile @a file.
* Create a new handle on a lump of File @a file.
*
* @param af VFS object representing the container of the lump to be opened.
* @param lumpIdx Logical index of the lump within @a file to be opened.
* @param dontBuffer @c true= do not buffer a copy of the lump.
*/
static DFile* fromFileLump(AbstractFile& file, int lumpIdx, bool dontBuffer);
static DFile* fromFileLump(File1& file, int lumpIdx, bool dontBuffer);

/**
* Open a new handle on the specified native file.
Expand Down Expand Up @@ -79,10 +79,10 @@ extern "C" {
*/

/// @return File object represented by this handle.
struct abstractfile_s* DFile_File(DFile* hndl);
struct file1_s* DFile_File(DFile* hndl);

/// @return File object represented by this handle.
struct abstractfile_s* DFile_File_const(DFile const* hndl);
struct file1_s* DFile_File_const(DFile const* hndl);

#ifdef __cplusplus
} // extern "C"
Expand Down
@@ -1,7 +1,7 @@
/**
* @file abstractfile.h
* @file file.h
*
* Abstract base for all classes which represent opened files.
* Base for all classes which represent opened files.
*
* @ingroup fs
*
Expand All @@ -23,8 +23,8 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_FILESYS_ABSTRACTFILE_H
#define LIBDENG_FILESYS_ABSTRACTFILE_H
#ifndef LIBDENG_FILESYS_FILE_H
#define LIBDENG_FILESYS_FILE_H

#ifdef __cplusplus
extern "C" {
Expand All @@ -33,14 +33,14 @@ extern "C" {
// File types.
/// @todo Refactor away.
typedef enum {
FT_GENERICFILE,
FT_FILE, ///< Generic file
FT_ZIPFILE,
FT_WADFILE,
FT_LUMPFILE,
FILETYPE_COUNT
} filetype_t;

#define VALID_FILETYPE(v) ((v) >= FT_GENERICFILE && (v) < FILETYPE_COUNT)
#define VALID_FILETYPE(v) ((v) >= FT_FILE && (v) < FILETYPE_COUNT)

#ifdef __cplusplus
} // extern "C"
Expand All @@ -58,12 +58,12 @@ class LumpIndex;
class PathDirectoryNode;

/**
* Abstract File. Abstract File is a core component of the filesystem
* intended for use as the base for all types of (pseudo-)file resources.
* File. File is a core component of the filesystem intended for use as the base
* for all types of (pseudo-)file resources.
*
* @ingroup fs
*/
class AbstractFile
class File1
{
public:
/// Categorization flags.
Expand All @@ -81,21 +81,21 @@ class AbstractFile
Q_DECLARE_FLAGS(Flags, Flag)

private:
AbstractFile();
File1();

public:
/**
* @param type File type identifier.
* @param path Path to this file in the virtual file system.
* @param file Handle to the file. Ownership of the handle is given to this instance.
* @param hndl Handle to the file. Ownership of the handle is given to this instance.
* @param info Info descriptor for the file. A copy is made.
*/
AbstractFile(filetype_t _type, char const* _path, DFile& file, FileInfo const& _info);
File1(filetype_t _type, char const* _path, DFile& hndl, FileInfo const& _info);

/**
* Release all memory acquired for objects linked with this resource.
*/
virtual ~AbstractFile();
virtual ~File1();

/**
* @return Type of this resource @see filetype_t
Expand All @@ -109,7 +109,7 @@ class AbstractFile
bool isContained() const;

/// @return The file instance which contains this.
AbstractFile& container() const;
File1& container() const;

/// @return Load order index for this resource.
uint loadOrderIndex() const;
Expand Down Expand Up @@ -141,13 +141,13 @@ class AbstractFile
bool hasStartup() const;

/// Mark this resource as "startup".
AbstractFile& setStartup(bool yes);
File1& setStartup(bool yes);

/// @return @c true if the resource is marked "custom".
bool hasCustom() const;

/// Mark this resource as "custom".
AbstractFile& setCustom(bool yes);
File1& setCustom(bool yes);

DFile& handle();

Expand Down Expand Up @@ -193,7 +193,7 @@ class AbstractFile
*
* @throws de::Error If @a lumpIdx is not valid.
*/
virtual PathDirectoryNode const& lumpDirectoryNode(int lumpIdx) = 0;
virtual PathDirectoryNode const& lumpDirectoryNode(int lumpIdx);

/**
* Compose the absolute VFS path to a lump contained by this file.
Expand All @@ -206,7 +206,7 @@ class AbstractFile
*
* @return String containing the absolute path.
*/
virtual AutoStr* composeLumpPath(int lumpIdx, char delimiter = '/') = 0;
virtual AutoStr* composeLumpPath(int lumpIdx, char delimiter = '/');

/**
* Retrieve the FileInfo descriptor for a lump contained by this file.
Expand Down Expand Up @@ -234,11 +234,11 @@ class AbstractFile
* a better method of looking up multiple @ref FileInfo properties.
*
* @attention This default implementation assumes there is only one lump in
* the file and therefore its decriptor is that of the file itself. Subclasses
* the file and therefore its size is that of the file itself. Subclasses
* with multiple lumps should override this function accordingly.
*
*/
virtual size_t lumpSize(int lumpIdx) = 0;
virtual size_t lumpSize(int /*lumpIdx*/) { return size(); }

/**
* Read the data associated with lump @a lumpIdx into @a buffer.
Expand All @@ -252,7 +252,7 @@ class AbstractFile
*
* @see lumpSize() or lumpInfo() to determine the size of buffer needed.
*/
virtual size_t readLump(int lumpIdx, uint8_t* buffer, bool tryCache = true) = 0;
virtual size_t readLump(int lumpIdx, uint8_t* buffer, bool tryCache = true);

/**
* Read a subsection of the data associated with lump @a lumpIdx into @a buffer.
Expand All @@ -266,7 +266,7 @@ class AbstractFile
* @return Number of bytes read.
*/
virtual size_t readLump(int lumpIdx, uint8_t* buffer, size_t startOffset, size_t length,
bool tryCache = true) = 0;
bool tryCache = true);

/*
* Lump caching interface:
Expand All @@ -279,7 +279,7 @@ class AbstractFile
*
* @return Pointer to the cached copy of the associated data.
*/
virtual uint8_t const* cacheLump(int lumpIdx) = 0;
virtual uint8_t const* cacheLump(int lumpIdx);

/**
* Remove a lock on a cached data lump.
Expand All @@ -288,7 +288,7 @@ class AbstractFile
*
* @return This instance.
*/
virtual AbstractFile& unlockLump(int lumpIdx) = 0;
virtual File1& unlockLump(int lumpIdx);

/**
* Clear any cached data for lump @a lumpIdx from the lump cache.
Expand All @@ -299,14 +299,14 @@ class AbstractFile
*
* @return This instance.
*/
//virtual AbstractFile& clearCachedLump(int lumpIdx, bool* retCleared = 0) = 0;
//virtual File1& clearCachedLump(int lumpIdx, bool* retCleared = 0) = 0;

/**
* Purge the lump cache, clearing all cached data lumps.
*
* @return This instance.
*/
//virtual AbstractFile& clearLumpCache() = 0;
//virtual File1& clearLumpCache() = 0;

protected:
/// File stream handle/wrapper.
Expand All @@ -329,18 +329,18 @@ class AbstractFile
uint order;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractFile::Flags)
Q_DECLARE_OPERATORS_FOR_FLAGS(File1::Flags)

} // namespace de

extern "C" {
#endif // __cplusplus

struct abstractfile_s; // The abstractfile instance (opaque)
typedef struct abstractfile_s AbstractFile;
struct file1_s; // The file instance (opaque)
typedef struct file1_s File1;

#ifdef __cplusplus
} // extern "C"
#endif

#endif /* LIBDENG_FILESYS_ABSTRACTFILE_H */
#endif /* LIBDENG_FILESYS_FILE_H */
7 changes: 4 additions & 3 deletions doomsday/engine/portable/include/fileinfo.h
Expand Up @@ -29,10 +29,11 @@
#include <algorithm>

#include <de/types.h>
#include "abstractfile.h"

namespace de {

class File1;

/**
* FileInfo record.
* @ingroup fs
Expand All @@ -46,10 +47,10 @@ struct FileInfo
size_t compressedSize; /// Size of the original file compressed.

/// @todo Move this property up to file level.
AbstractFile* container; /// Owning package else @c NULL.
File1* container; /// Owning package else @c NULL.

FileInfo(uint _lastModified = 0, int _lumpIdx = 0, size_t _baseOffset = 0,
size_t _size = 0, size_t _compressedSize = 0, AbstractFile* _container = 0)
size_t _size = 0, size_t _compressedSize = 0, File1* _container = 0)
: lastModified(_lastModified), lumpIdx(_lumpIdx), baseOffset(_baseOffset),
size(_size), compressedSize(_compressedSize), container(_container)
{}
Expand Down

0 comments on commit 76d29ef

Please sign in to comment.