/
lumpfileadaptor.h
154 lines (135 loc) · 4.93 KB
/
lumpfileadaptor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* @file lumpfileadaptor.h
*
* Specialization of AbstractFile for working with the lumps of container
* file instances (such as Wad and Zip).
*
* Design wise a LumpFileAdaptorAdaptor is an Adapter, in that it provides an
* AbstractFile-derived object instance through which a lump of a contained
* file may be manipulated.
*
* @ingroup fs
*
* @see abstractfile.h, AbstractFile
*
* @author Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright © 2006-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef LIBDENG_FILESYS_LUMPFILEADAPTOR_H
#define LIBDENG_FILESYS_LUMPFILEADAPTOR_H
#ifdef __cplusplus
#include "abstractfile.h"
#include "fileinfo.h"
namespace de {
class DFile;
class LumpIndex;
class PathDirectoryNode;
/**
* LumpFileAdaptor. AbstractFile adaptor class allowing lumps to be interfaced with as
* if they were "real" files.
*/
class LumpFileAdaptor : public AbstractFile
{
public:
LumpFileAdaptor(DFile& file, char const* path, FileInfo const& info);
~LumpFileAdaptor();
/**
* Retrieve the directory node for a lump contained by this file.
*
* @param lumpIdx Ignored. Required argument.
*
* @return Directory node for this lump.
*/
PathDirectoryNode const& lumpDirectoryNode(int lumpIdx);
/**
* Compose the absolute VFS path to a lump contained by this file.
*
* @note Always returns a valid string object. If @a lumpIdx is not valid a
* zero-length string is returned.
*
* @param lumpIdx Logical index for the lump.
* @param delimiter Delimit directory separators using this character.
*
* @return String containing the absolute path.
*/
AutoStr* composeLumpPath(int lumpIdx, char delimiter = '/');
/**
* Lookup the uncompressed size of lump contained by this file.
*
* @param lumpIdx Logical index for the lump in this file's directory.
*
* @return Size of the lump in bytes.
*
* @note This method is intended mainly for convenience. @see lumpInfo() for
* a better method of looking up multiple @ref FileInfo properties.
*/
size_t lumpSize(int lumpIdx);
/**
* Read the data associated with lump @a lumpIdx into @a buffer.
*
* @param lumpIdx Lump index associated with the data to be read.
* @param buffer Buffer to read into. Must be at least large enough to
* contain the whole lump.
* @param tryCache @c true= try the lump cache first.
*
* @return Number of bytes read.
*
* @see lumpSize() or lumpInfo() to determine the size of buffer needed.
*/
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.
*
* @param lumpIdx Lump index associated with the data to be read.
* @param buffer Buffer to read into. Must be at least @a length bytes.
* @param startOffset Offset from the beginning of the lump to start reading.
* @param length Number of bytes to read.
* @param tryCache @c true= try the lump cache first.
*
* @return Number of bytes read.
*/
size_t readLump(int lumpIdx, uint8_t* buffer, size_t startOffset, size_t length,
bool tryCache = true);
/**
* Read the data associated with lump @a lumpIdx into the cache.
*
* @param lumpIdx Lump index associated with the data to be cached.
*
* @return Pointer to the cached copy of the associated data.
*/
uint8_t const* cacheLump(int lumpIdx);
/**
* Remove a lock on a cached data lump.
*
* @param lumpIdx Lump index associated with the cached data to be changed.
*
* @return This instance.
*/
LumpFileAdaptor& unlockLump(int lumpIdx);
private:
struct Instance;
Instance* d;
};
} // namespace de
extern "C" {
#endif // __cplusplus
struct lumpfileadaptor_s; // The lumpfileadaptor instance (opaque)
//typedef struct lumpfileadaptor_s LumpFileAdaptor;
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* LIBDENG_FILESYS_LUMPFILEADAPTOR_H */