mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-02 23:26:44 +00:00
Enhance (Seekable)SubReadStream so be able to (optionally) dispose the parent stream after it's been used (simplifies memory management for client code)
svn-id: r25732
This commit is contained in:
parent
60e0f7624a
commit
7290d1b18c
@ -128,8 +128,8 @@ uint32 SubReadStream::read(void *dataPtr, uint32 dataSize) {
|
||||
return dataSize;
|
||||
}
|
||||
|
||||
SeekableSubReadStream::SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end)
|
||||
: SubReadStream(parentStream, end),
|
||||
SeekableSubReadStream::SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream)
|
||||
: SubReadStream(parentStream, end, disposeParentStream),
|
||||
_parentStream(parentStream),
|
||||
_begin(begin) {
|
||||
assert(_begin <= _end);
|
||||
|
@ -245,9 +245,16 @@ protected:
|
||||
ReadStream *_parentStream;
|
||||
uint32 _pos;
|
||||
uint32 _end;
|
||||
bool _disposeParentStream;
|
||||
public:
|
||||
SubReadStream(ReadStream *parentStream, uint32 end)
|
||||
: _parentStream(parentStream), _pos(0), _end(end) {}
|
||||
SubReadStream(ReadStream *parentStream, uint32 end, bool disposeParentStream = false)
|
||||
: _parentStream(parentStream),
|
||||
_pos(0),
|
||||
_end(end),
|
||||
_disposeParentStream(disposeParentStream) {}
|
||||
~SubReadStream() {
|
||||
if (_disposeParentStream) delete _parentStream;
|
||||
}
|
||||
|
||||
virtual bool eos() const { return _pos == _end; }
|
||||
virtual uint32 read(void *dataPtr, uint32 dataSize);
|
||||
@ -263,7 +270,7 @@ protected:
|
||||
SeekableReadStream *_parentStream;
|
||||
uint32 _begin;
|
||||
public:
|
||||
SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end);
|
||||
SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream = false);
|
||||
|
||||
virtual uint32 pos() const { return _pos - _begin; }
|
||||
virtual uint32 size() const { return _end - _begin; }
|
||||
|
Loading…
Reference in New Issue
Block a user