Resource files management II

Resource files management. Part I

Last time I've described resource files and their data structure. Let's continue with management of resource files.

Lump and ResourceFile objects
Resource files are implemented as objects and may be included in other programs to utilize resource files. I'm using C++, though the provided concept may be written in any other programming language.

In the previous post we have learned that resource file consists of header, lump's data and lump's information. Therefore, we'll need two classes: Lump and ResourceFile and two additional data structures: ResFileHeader, LumpInfo:

// Structure defining the header of our resource files.
struct ResFileHeader
{
    unsigned long Version;                  // Resource file version
    unsigned long LumpCount;                // Number of lumps in res.file
    unsigned long LumpListOffset;           // Position of the first

                                            // Lump info list element
};


// Structure of each element in the lump info list.
// Stores information which can be used to retrieve the contents of a lump.
struct LumpInfo
{
    unsigned long Size;                     // Size of the lump, in bytes
    unsigned long Position;                 // Position in the res.file
    std::string   Name;                     // Name of the lump
};


// Class representing single resource stored in a resource file.
// Stores lump information and lump contents
class Lump
{
protected:
    LumpInfo mLumpInfo;                     // Our lump information
    void*    mData;                         // Lump's contents
...
};


// Class representing single resource file.
// Stores resource file header and list of lumps
class ResourceFile
{
protected:
    ResFileHeader mFileHeader;
    std::vector<Lump*> mLumpList;
...
};


That's it. We'll discuss functionality of two classes later, right now we know the structure of our resource file. Once again, from abstract view the structure of resource file looks like:
[Resource File]
-   [ResFileHeader]
-   [Lump]
    -   [LumpInfo]
    -   [Data]
-   [Lump]
    -   [LumpInfo]
    -   [Data]
    ...


whereas in practice LumpInfo is separated from Lump:
[Resource File]
-   [ResFileHeader]
-   [Lump]
    -   [Data]
-   [Lump]
    -   [Data]
    ...    
-   [LumpInfo]
-   [LumpInfo]
    ...


Next time I'll write about basic functionality that Lump and ResourceFile implement.

Resource file management. Part III
Resource file management. Part IV

0 comments: (+add yours?)

Post a Comment