aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorColin Snover2017-08-03 23:32:10 -0500
committerColin Snover2017-08-20 11:36:14 -0500
commit1d844978d675e1c4d875cc86c9ac86ad0fef04cb (patch)
tree9d5cf7fa7282b6b53dbd1fc6fe0184092f910bc0 /common
parentd139d65c8020f92a96e41d4c05972a2a00bbd7a0 (diff)
downloadscummvm-rg350-1d844978d675e1c4d875cc86c9ac86ad0fef04cb.tar.gz
scummvm-rg350-1d844978d675e1c4d875cc86c9ac86ad0fef04cb.tar.bz2
scummvm-rg350-1d844978d675e1c4d875cc86c9ac86ad0fef04cb.zip
COMMON: Implement SeekableReadStream interface for MemoryReadWriteStream
This allows MemoryReadWriteStream to be passed successfully to functions that use the SeekableReadStream type so that they can call the `pos` method, like the DPCMStream class of the VMD decoder.
Diffstat (limited to 'common')
-rw-r--r--common/memstream.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/common/memstream.h b/common/memstream.h
index 25fdde91c7..0338d35378 100644
--- a/common/memstream.h
+++ b/common/memstream.h
@@ -212,13 +212,14 @@ public:
/**
* MemoryStream based on RingBuffer. Grows if has insufficient buffer size.
*/
-class MemoryReadWriteStream : public WriteStream {
+class MemoryReadWriteStream : public SeekableReadStream, public WriteStream {
private:
uint32 _capacity;
uint32 _size;
byte *_data;
uint32 _writePos, _readPos, _pos, _length;
DisposeAfterUse::Flag _disposeMemory;
+ bool _eos;
void ensureCapacity(uint32 new_len) {
if (new_len <= _capacity)
@@ -246,7 +247,7 @@ private:
}
}
public:
- MemoryReadWriteStream(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : _capacity(0), _size(0), _data(0), _writePos(0), _readPos(0), _pos(0), _length(0), _disposeMemory(disposeMemory) {}
+ MemoryReadWriteStream(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : _capacity(0), _size(0), _data(0), _writePos(0), _readPos(0), _pos(0), _length(0), _disposeMemory(disposeMemory), _eos(false) {}
~MemoryReadWriteStream() {
if (_disposeMemory)
@@ -271,8 +272,10 @@ public:
}
virtual uint32 read(void *dataPtr, uint32 dataSize) {
- uint32 length = _length;
- if (length < dataSize) dataSize = length;
+ if (_length < dataSize) {
+ dataSize = _length;
+ _eos = true;
+ }
if (dataSize == 0 || _capacity == 0) return 0;
if (_readPos + dataSize < _capacity) {
memcpy(dataPtr, _data + _readPos, dataSize);
@@ -287,7 +290,10 @@ public:
}
int32 pos() const { return _pos - _length; } //'read' position in the stream
- uint32 size() const { return _size; } //that's also 'write' position in the stream, as it's append-only
+ int32 size() const { return _size; } //that's also 'write' position in the stream, as it's append-only
+ bool seek(int32, int) { return false; }
+ bool eos() const { return _eos; }
+ void clearErr() { _eos = false; }
byte *getData() { return _data; }
};