ScummVM API documentation
simple_file.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef TITANIC_SIMPLE_FILE_H
23#define TITANIC_SIMPLE_FILE_H
24
25#include "common/file.h"
26#include "titanic/support/rect.h"
27#include "common/savefile.h"
28#include "common/stream.h"
29#include "common/compression/deflate.h"
30#include "titanic/support/string.h"
31
32namespace Titanic {
33
34class Decompressor;
35class DecompressorData;
36
41class File : public Common::File {
42public:
43 bool open(const Common::Path &filename) override;
44};
45
50private:
54 void skipSpaces();
55protected:
57 Common::OutSaveFile *_outStream;
58 int _lineCount;
59public:
60 SimpleFile();
61 virtual ~SimpleFile();
62
63 operator Common::SeekableReadStream &() { return *_inStream; }
64 operator Common::WriteStream &() { return *_outStream; }
65
69 virtual void open(Common::SeekableReadStream *stream);
70
74 virtual void open(Common::OutSaveFile *stream);
75
79 virtual void close();
80
84 virtual void safeRead(void *dst, size_t count);
85
89 virtual size_t unsafeRead(void *dst, size_t count);
90
94 virtual size_t write(const void *src, size_t count) const;
95
99 virtual void seek(int offset, int origin);
103 byte readByte();
104
109
114
119
124
128 double readFloat();
129
134
139
144
148 void readBuffer(char *buffer = nullptr, size_t count = 0);
149
153 bool scanf(const char *format, ...);
154
158 void writeByte(byte b) { write(&b, 1); }
159
163 void writeUint16LE(uint val);
164
168 void writeUint32LE(uint val);
169
173 void writeLine(const CString &str) const;
174
178 void writeString(const CString &str) const;
179
183 void writeQuotedString(const CString &str) const;
184
188 void writeQuotedLine(const CString &str, int indent) const;
189
193 void writeNumber(int val) const;
194
198 void writeNumberLine(int val, int indent) const;
199
203 void writeFloat(double val) const;
204
208 void writeFloatLine(double val, int indent) const;
209
213 void writePoint(const Point &pt, int indent)const;
214
218 void writeRect(const Rect &r, int indent) const;
219
223 void writeBounds(const Rect &r, int indent) const;
224
228 void writeFormat(const char *format, ...) const;
229
233 void writeIndent(uint indent) const;
234
241
245 void writeClassStart(const CString &classStr, int indent);
246
250 void writeClassEnd(int indent);
251
255 bool eos() const {
256 assert(_inStream);
257 return _inStream->pos() >= _inStream->size();
258 }
259};
260
265public:
267 ~CompressedFile() override {}
268
272 void open(Common::SeekableReadStream *stream) override {
274 }
275
279 void open(Common::OutSaveFile *stream) override {
281 }
282};
283
287class StdCWadFile : public SimpleFile {
288public:
289 StdCWadFile() : SimpleFile() {}
290 ~StdCWadFile() override {}
291
295 virtual bool open(const Common::String &filename);
296
300 void open(Common::SeekableReadStream *stream) override {}
301
305 void open(Common::OutSaveFile *stream) override {}
306
310 Common::SeekableReadStream *readStream() const { return _inStream; }
311};
312
316CString readStringFromStream(Common::SeekableReadStream *s);
317
318} // End of namespace Titanic
319
320#endif /* TITANIC_SIMPLE_FILE_H */
Definition: file.h:47
Definition: savefile.h:54
Definition: path.h:52
Definition: stream.h:745
virtual int64 pos() const =0
virtual int64 size() const =0
Definition: str.h:59
Definition: stream.h:77
Definition: string.h:40
Definition: simple_file.h:264
void open(Common::OutSaveFile *stream) override
Definition: simple_file.h:279
void open(Common::SeekableReadStream *stream) override
Definition: simple_file.h:272
Definition: simple_file.h:41
bool open(const Common::Path &filename) override
Definition: rect.h:35
Definition: simple_file.h:49
virtual void close()
void writeUint16LE(uint val)
void writeIndent(uint indent) const
void writeString(const CString &str) const
virtual size_t write(const void *src, size_t count) const
void writeBounds(const Rect &r, int indent) const
void writeQuotedLine(const CString &str, int indent) const
void writeNumberLine(int val, int indent) const
virtual void open(Common::SeekableReadStream *stream)
void readBuffer(char *buffer=nullptr, size_t count=0)
void writeFloatLine(double val, int indent) const
void writeLine(const CString &str) const
virtual void safeRead(void *dst, size_t count)
void writeByte(byte b)
Definition: simple_file.h:158
void writeClassEnd(int indent)
void writePoint(const Point &pt, int indent) const
void writeFormat(const char *format,...) const
virtual size_t unsafeRead(void *dst, size_t count)
void writeFloat(double val) const
void writeRect(const Rect &r, int indent) const
void writeClassStart(const CString &classStr, int indent)
void writeNumber(int val) const
void writeQuotedString(const CString &str) const
bool eos() const
Definition: simple_file.h:255
bool scanf(const char *format,...)
void writeUint32LE(uint val)
virtual void seek(int offset, int origin)
virtual void open(Common::OutSaveFile *stream)
Definition: simple_file.h:287
void open(Common::SeekableReadStream *stream) override
Definition: simple_file.h:300
void open(Common::OutSaveFile *stream) override
Definition: simple_file.h:305
virtual bool open(const Common::String &filename)
Common::SeekableReadStream * readStream() const
Definition: simple_file.h:310
SeekableReadStream * wrapCompressedReadStream(SeekableReadStream *toBeWrapped, DisposeAfterUse::Flag disposeParent=DisposeAfterUse::YES, uint64 knownSize=0)
WriteStream * wrapCompressedWriteStream(WriteStream *toBeWrapped)
Definition: rect.h:144