34 #ifndef AGS_SHARED_UTIL_STREAM_H 35 #define AGS_SHARED_UTIL_STREAM_H 37 #include "ags/shared/util/iags_stream.h" 38 #include "ags/lib/allegro/file.h" 39 #include "common/stream.h" 40 #include "common/types.h" 57 virtual bool HasErrors()
const {
61 virtual bool Flush() = 0;
66 int8_t ReadInt8()
override {
70 size_t WriteInt8(int8_t val)
override {
71 int32_t ival = WriteByte(val);
72 return ival >= 0 ? ival : 0;
75 bool ReadBool()
override {
76 return ReadInt8() != 0;
79 size_t WriteBool(
bool val)
override {
80 return WriteInt8(val ? 1 : 0);
85 size_t ReadArrayOfInt8(int8_t *buffer,
size_t count)
override {
86 return Read(buffer, count);
88 size_t WriteArrayOfInt8(
const int8_t *buffer,
size_t count)
override {
89 return Write(buffer, count);
93 size_t WriteByteCount(uint8_t b,
size_t count);
99 DisposeAfterUse::Flag _disposeAfterUse;
102 DisposeAfterUse::YES) : _stream(src), _disposeAfterUse(disposeAfterUse) {
105 if (_disposeAfterUse == DisposeAfterUse::YES)
109 bool eos()
const override {
110 return _stream->EOS();
113 uint32
read(
void *dataPtr, uint32 dataSize)
override {
114 return _stream->Read(dataPtr, dataSize);
117 int64
pos()
const override {
118 return _stream->GetPosition();
122 return _stream->GetLength();
125 bool seek(int64 offset,
int whence = SEEK_SET)
override {
126 StreamSeek origin = kSeekBegin;
127 if (whence == SEEK_CUR)
128 origin = kSeekCurrent;
129 if (whence == SEEK_END)
132 return _stream->Seek(offset, origin);
140 DisposeAfterUse::Flag _disposeAfterUse;
143 DisposeAfterUse::YES) : _file(src), _disposeAfterUse(disposeAfterUse) {
146 if (_disposeAfterUse == DisposeAfterUse::YES)
150 bool eos()
const override {
151 return _file->pack_feof();
154 uint32
read(
void *dataPtr, uint32 dataSize)
override {
155 return _file->pack_fread(dataPtr, dataSize);
158 int64
pos()
const override {
159 error(
"Unsupported");
163 error(
"Unsupported");
166 bool seek(int64 offset,
int whence = SEEK_SET)
override {
167 error(
"Unsupported");
174 DisposeAfterUse::Flag _disposeAfterUse;
177 DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::NO) :
178 _stream(stream), _disposeAfterUse(disposeAfterUse) {
184 void Close()
override {
185 if (_disposeAfterUse == DisposeAfterUse::YES)
190 bool IsValid()
const override {
191 return _stream !=
nullptr;
193 bool EOS()
const override {
194 return _stream->
eos();
196 soff_t GetLength()
const override {
197 return _stream->
size();
199 soff_t GetPosition()
const override {
200 return _stream->
pos();
202 bool CanRead()
const override {
205 bool CanWrite()
const override {
208 bool CanSeek()
const override {
212 size_t Read(
void *buffer,
size_t size)
override {
213 return _stream->
read(buffer, size);
215 int32_t ReadByte()
override {
218 size_t Write(
const void *buffer,
size_t size)
override {
221 int32_t WriteByte(uint8_t b)
override {
225 int8_t ReadInt8()
override {
228 int16_t ReadInt16()
override {
231 int32_t ReadInt32()
override {
234 int64_t ReadInt64()
override {
237 bool ReadBool()
override {
240 size_t ReadArray(
void *buffer,
size_t elem_size,
size_t count)
override {
241 return _stream->
read(buffer, elem_size * count) / elem_size;
243 size_t ReadArrayOfInt8(int8_t *buffer,
size_t count)
override {
244 return _stream->
read(buffer, count);
246 size_t ReadArrayOfInt16(int16_t *buffer,
size_t count)
override {
247 for (
size_t i = 0; i < count; ++i)
251 size_t ReadArrayOfInt32(int32_t *buffer,
size_t count)
override {
252 for (
size_t i = 0; i < count; ++i)
256 size_t ReadArrayOfInt64(int64_t *buffer,
size_t count)
override {
257 for (
size_t i = 0; i < count; ++i)
262 size_t WriteInt8(int8_t val)
override {
265 size_t WriteInt16(int16_t val)
override {
268 size_t WriteInt32(int32_t val)
override {
271 size_t WriteInt64(int64_t val)
override {
274 size_t WriteBool(
bool val)
override {
277 size_t WriteArray(
const void *buffer,
size_t elem_size,
size_t count)
override {
280 size_t WriteArrayOfInt8(
const int8_t *buffer,
size_t count)
override {
283 size_t WriteArrayOfInt16(
const int16_t *buffer,
size_t count)
override {
286 size_t WriteArrayOfInt32(
const int32_t *buffer,
size_t count)
override {
289 size_t WriteArrayOfInt64(
const int64_t *buffer,
size_t count)
override {
293 bool Seek(soff_t offset, StreamSeek origin = kSeekCurrent)
override {
294 return _stream->
seek(offset, origin);
297 bool HasErrors()
const override {
298 return _stream->
err();
300 bool Flush()
override {
Definition: achievements_tables.h:27
uint32 read(void *dataPtr, uint32 dataSize) override
Definition: stream.h:113
virtual int64 size() const =0
uint32 read(void *dataPtr, uint32 dataSize) override
Definition: stream.h:154
virtual int64 pos() const =0
virtual bool err() const
Definition: stream.h:61
FORCEINLINE int32 readSint32LE()
Definition: stream.h:555
int64 size() const override
Definition: stream.h:121
Definition: iags_stream.h:53
virtual bool seek(int64 offset, int whence=SEEK_SET)=0
virtual bool eos() const =0
bool eos() const override
Definition: stream.h:150
bool eos() const override
Definition: stream.h:109
byte readByte()
Definition: stream.h:434
bool seek(int64 offset, int whence=SEEK_SET) override
Definition: stream.h:125
int64 size() const override
Definition: stream.h:162
FORCEINLINE int64 readSint64LE()
Definition: stream.h:567
bool seek(int64 offset, int whence=SEEK_SET) override
Definition: stream.h:166
int64 pos() const override
Definition: stream.h:158
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
FORCEINLINE int16 readSint16LE()
Definition: stream.h:543
int64 pos() const override
Definition: stream.h:117
virtual uint32 read(void *dataPtr, uint32 dataSize)=0