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 
32 namespace Titanic {
33 
34 class Decompressor;
35 class DecompressorData;
36 
41 class File : public Common::File {
42 public:
43  bool open(const Common::Path &filename) override;
44 };
45 
49 class SimpleFile {
50 private:
54  void skipSpaces();
55 protected:
56  Common::SeekableReadStream *_inStream;
57  Common::OutSaveFile *_outStream;
58  int _lineCount;
59 public:
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 
108  uint readUint16LE();
109 
113  uint readUint32LE();
114 
119 
123  int readNumber();
124 
128  double readFloat();
129 
133  Point readPoint();
134 
138  Rect readRect();
139 
143  Rect readBounds();
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 
240  bool isClassStart();
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 
264 class CompressedFile : public SimpleFile {
265 public:
266  CompressedFile() : SimpleFile() {}
267  ~CompressedFile() override {}
268 
272  void open(Common::SeekableReadStream *stream) override {
274  }
275 
279  void open(Common::OutSaveFile *stream) override {
281  }
282 };
283 
287 class StdCWadFile : public SimpleFile {
288 public:
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 
316 CString readStringFromStream(Common::SeekableReadStream *s);
317 
318 } // End of namespace Titanic
319 
320 #endif /* TITANIC_SIMPLE_FILE_H */
virtual int64 size() const =0
SeekableReadStream * wrapCompressedReadStream(SeekableReadStream *toBeWrapped, DisposeAfterUse::Flag disposeParent=DisposeAfterUse::YES, uint64 knownSize=0)
Definition: str.h:59
virtual int64 pos() const =0
uint16 readUint16LE()
Definition: stream.h:459
void open(Common::SeekableReadStream *stream) override
Definition: simple_file.h:272
Definition: stream.h:77
Definition: savefile.h:54
String readString(char terminator=0, size_t len=String::npos)
WriteStream * wrapCompressedWriteStream(WriteStream *toBeWrapped)
uint32 readUint32LE()
Definition: stream.h:473
Definition: path.h:52
Definition: stream.h:745
Definition: simple_file.h:49
void open(Common::OutSaveFile *stream) override
Definition: simple_file.h:305
byte readByte()
Definition: stream.h:434
Definition: file.h:47
void writeByte(byte b)
Definition: simple_file.h:158
Definition: rect.h:35
Common::SeekableReadStream * readStream() const
Definition: simple_file.h:310
Definition: rect.h:45
Definition: arm.h:30
Definition: string.h:40
virtual void close()
void open(Common::SeekableReadStream *stream) override
Definition: simple_file.h:300
Definition: simple_file.h:41
void open(Common::OutSaveFile *stream) override
Definition: simple_file.h:279
Definition: simple_file.h:287
virtual void open(Common::SeekableReadStream *stream)
bool open(const Common::Path &filename) override
bool seek(int64 offs, int whence=SEEK_SET) override
Definition: simple_file.h:264
bool eos() const
Definition: simple_file.h:255