ScummVM API documentation
iags_stream.h
1 //=============================================================================
2 //
3 /* ScummVM - Graphic Adventure Engine
4  *
5  * ScummVM is the legal property of its developers, whose names
6  * are too numerous to list here. Please refer to the COPYRIGHT
7  * file distributed with this source distribution.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23 
24 //=============================================================================
25 //
26 // IAGSStream is a contract for stream class, provided by engine to plugin
27 // on the need, such as saving/restoring the game.
28 // The user is advised to use advanced helper methods, such as Read/WriteX
29 // and Read/WriteArrayOfX to allow the stream implementation properly control
30 // endianness conversions and data padding, when needed.
31 //
32 //=============================================================================
33 
34 #ifndef AGS_SHARED_API_STREAM_API_H
35 #define AGS_SHARED_API_STREAM_API_H
36 
37 // TODO: it would probably be better to not include core definition headers
38 // in API class headers, but make separate core headers specifically for
39 // plugins, and let plugin developers include them manually in plugin sources.
40 #include "ags/shared/core/types.h"
41 
42 namespace AGS3 {
43 
44 namespace AGS {
45 namespace Shared {
46 
47 enum StreamSeek {
48  kSeekBegin,
49  kSeekCurrent,
50  kSeekEnd
51 };
52 
53 class IAGSStream {
54 public:
55  virtual ~IAGSStream() {}
56 
57  virtual void Close() = 0;
58 
59  virtual bool IsValid() const = 0;
60  virtual bool EOS() const = 0;
61  virtual soff_t GetLength() const = 0;
62  virtual soff_t GetPosition() const = 0;
63  virtual bool CanRead() const = 0;
64  virtual bool CanWrite() const = 0;
65  virtual bool CanSeek() const = 0;
66 
67  // Reads number of bytes in the provided buffer
68  virtual size_t Read(void *buffer, size_t size) = 0;
69  // ReadByte conforms to fgetc behavior:
70  // - if stream is valid, then returns an *unsigned char* packed in the int
71  // - if EOS, then returns -1
72  virtual int32_t ReadByte() = 0;
73  // Writes number of bytes from the provided buffer
74  virtual size_t Write(const void *buffer, size_t size) = 0;
75  // WriteByte conforms to fputc behavior:
76  // - on success, returns the unsigned char packed in the int
77  // - on failure, returns -1
78  virtual int32_t WriteByte(uint8_t b) = 0;
79 
80  // Convenience methods for reading values of particular size
81  virtual int8_t ReadInt8() = 0;
82  virtual int16_t ReadInt16() = 0;
83  virtual int32_t ReadInt32() = 0;
84  virtual int64_t ReadInt64() = 0;
85  virtual bool ReadBool() = 0;
86  virtual size_t ReadArray(void *buffer, size_t elem_size, size_t count) = 0;
87  virtual size_t ReadArrayOfInt8(int8_t *buffer, size_t count) = 0;
88  virtual size_t ReadArrayOfInt16(int16_t *buffer, size_t count) = 0;
89  virtual size_t ReadArrayOfInt32(int32_t *buffer, size_t count) = 0;
90  virtual size_t ReadArrayOfInt64(int64_t *buffer, size_t count) = 0;
91 
92  // Convenience methods for writing values of particular size
93  virtual size_t WriteInt8(int8_t val) = 0;
94  virtual size_t WriteInt16(int16_t val) = 0;
95  virtual size_t WriteInt32(int32_t val) = 0;
96  virtual size_t WriteInt64(int64_t val) = 0;
97  virtual size_t WriteBool(bool val) = 0;
98  virtual size_t WriteArray(const void *buffer, size_t elem_size, size_t count) = 0;
99  virtual size_t WriteArrayOfInt8(const int8_t *buffer, size_t count) = 0;
100  virtual size_t WriteArrayOfInt16(const int16_t *buffer, size_t count) = 0;
101  virtual size_t WriteArrayOfInt32(const int32_t *buffer, size_t count) = 0;
102  virtual size_t WriteArrayOfInt64(const int64_t *buffer, size_t count) = 0;
103 
104  virtual bool Seek(soff_t offset, StreamSeek origin = kSeekCurrent) = 0;
105 };
106 
107 } // namespace Shared
108 } // namespace AGS
109 } // namespace AGS3
110 
111 #endif
Definition: achievements_tables.h:27
Definition: iags_stream.h:53
Definition: ags.h:40