/
abstractfile.h
211 lines (157 loc) · 5.42 KB
/
abstractfile.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/**
* @file abstractfile.h
*
* Abstract base for all classes which represent opened files.
*
* @ingroup fs
*
* @author Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright © 2005-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_ABSTRACTFILE_H
#define LIBDENG_FILESYS_ABSTRACTFILE_H
#include "dfile.h"
#include "lumpinfo.h"
#ifdef __cplusplus
extern "C" {
#endif
// File types.
typedef enum {
FT_UNKNOWNFILE,
FT_ZIPFILE,
FT_WADFILE,
FT_LUMPFILE,
FILETYPE_COUNT
} filetype_t;
#define VALID_FILETYPE(v) ((v) >= FT_UNKNOWNFILE && (v) < FILETYPE_COUNT)
#ifdef __cplusplus
} // extern "C"
#endif
#ifdef __cplusplus
namespace de {
/**
* Abstract File. Abstract 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
{
public:
/// @see filetype_t
filetype_t _type;
struct abstractfile_flags_s
{
uint startup:1; ///< Loaded during the startup process.
uint custom:1; /// < Not an original game resource.
} _flags;
/// protected: File stream handle/wrapper.
DFile* _file;
/// Absolute variable-length path in the vfs.
ddstring_t _path;
/// Info descriptor (file metadata).
LumpInfo _info;
/// Load order depth index.
uint _order;
/**
* @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 info Lump info descriptor for the file. A copy is made.
*/
AbstractFile(filetype_t type_, char const* path_, DFile* file, LumpInfo const* info_);
/**
* Release all memory acquired for objects linked with this resource.
*/
~AbstractFile();
/**
* @return Type of this resource @see filetype_t
*/
filetype_t type() const;
/**
* @return Immutable copy of the info descriptor for this resource.
*/
LumpInfo const* info() const;
/**
* @return Owning package else @c NULL if not contained.
*/
AbstractFile* container() const;
/**
* Accessors:
*/
/// @return Absolute (i.e., resolved but possibly virtual/mapped) path to this resource.
ddstring_t const* path() const;
/// @return Load order index for this resource.
uint loadOrderIndex() const;
/// @return "Last modified" timestamp of the resource.
uint lastModified() const;
/// @return @c true if the resource is marked "startup".
bool hasStartup() const;
/// Mark this resource as "startup".
void setStartup(bool yes);
/// @return @c true if the resource is marked "custom".
bool hasCustom() const;
/// Mark this resource as "custom".
void setCustom(bool yes);
size_t baseOffset() const;
DFile* handle();
/**
* Abstract interface (minimal, data caching interface not expected):
*/
/**
* Read the data associated with the specified lump index into @a buffer.
*
* @param lumpIdx Lump index associated with the data being read.
* @param buffer Buffer to read into. Must be at least W_LumpLength() bytes.
* @return Number of bytes read.
*/
size_t readLump(int lumpIdx, uint8_t* buffer);
/**
* Accessors:
*/
/// @return Number of "lumps" contained within this resource.
int lumpCount();
};
} // namespace de
extern "C" {
#endif // __cplusplus
/**
* C wrapper API:
*/
struct abstractfile_s; // The abstractfile instance (opaque)
typedef struct abstractfile_s AbstractFile;
filetype_t AbstractFile_Type(AbstractFile const* af);
LumpInfo const* AbstractFile_Info(AbstractFile const* af);
AbstractFile* AbstractFile_Container(AbstractFile const* af);
ddstring_t const* AbstractFile_Path(AbstractFile const* af);
uint AbstractFile_LoadOrderIndex(AbstractFile const* af);
uint AbstractFile_LastModified(AbstractFile const* af);
boolean AbstractFile_HasStartup(AbstractFile const* af);
void AbstractFile_SetStartup(AbstractFile* af, boolean yes);
boolean AbstractFile_HasCustom(AbstractFile const* af);
void AbstractFile_SetCustom(AbstractFile* af, boolean yes);
size_t AbstractFile_BaseOffset(AbstractFile const* af);
DFile* AbstractFile_Handle(AbstractFile* af);
size_t AbstractFile_ReadLump(AbstractFile* af, int lumpIdx, uint8_t* buffer);
int AbstractFile_LumpCount(AbstractFile* af);
/// @todo Refactor away:
AbstractFile* UnknownFile_New(DFile* file, char const* path, LumpInfo const* info);
void UnknownFile_Delete(AbstractFile* af);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* LIBDENG_FILESYS_ABSTRACTFILE_H */