ScummVM API documentation
file_stream.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 AGS_SHARED_UTIL_FILE_STREAM_H
23#define AGS_SHARED_UTIL_FILE_STREAM_H
24
25#include "common/savefile.h"
26#include "common/stream.h"
27#include "common/std/functional.h"
28#include "ags/shared/util/data_stream.h"
29#include "ags/shared/util/file.h" // TODO: extract filestream mode constants
30
31namespace AGS3 {
32namespace AGS {
33namespace Shared {
34
35class FileStream : public DataStream {
36public:
38 String Filepath;
39 FileWorkMode WorkMode;
40 };
41
42 // Represents an open file object
43 // The constructor may raise std::runtime_error if
44 // - there is an issue opening the file (does not exist, locked, permissions, etc)
45 // - the open mode could not be determined
46 FileStream(const String &file_name, FileOpenMode open_mode, FileWorkMode work_mode,
47 DataEndianess stream_endianess = kLittleEndian);
48 ~FileStream() override;
49
50 FileWorkMode GetWorkMode() const { return _workMode; }
51
52 // Tells if there were errors during previous io operation(s);
53 // the call to GetError() *resets* the error record.
54 bool GetError() const override;
55 void Close() override;
56 bool Flush() override;
57
58 // Is stream valid (underlying data initialized properly)
59 bool IsValid() const override;
60 // Is end of stream
61 bool EOS() const override;
62 // Total length of stream (if known)
63 soff_t GetLength() const override;
64 // Current position (if known)
65 soff_t GetPosition() const override;
66 bool CanRead() const override;
67 bool CanWrite() const override;
68 bool CanSeek() const override;
69
70 size_t Read(void *buffer, size_t size) override;
71 int32_t ReadByte() override;
72 size_t Write(const void *buffer, size_t size) override;
73 int32_t WriteByte(uint8_t b) override;
74
75 soff_t Seek(soff_t offset, StreamSeek origin) override;
76
77private:
78 void Open(const String &file_name, FileOpenMode open_mode, FileWorkMode work_mode);
79 String getSaveName(const String &filename);
80 Common::OutSaveFile *openForWriting(const String &saveName, FileOpenMode open_mode, FileWorkMode work_mode);
81
82 Common::Stream *_file;
83 const FileWorkMode _workMode;
84};
85
86} // namespace Shared
87} // namespace AGS
88} // namespace AGS3
89
90#endif
Definition: data_stream.h:40
Definition: file_stream.h:35
Definition: string.h:60
Definition: savefile.h:54
Definition: stream.h:48