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:
Max Horn 2007-02-19 21:11:13 +00:00
parent 60e0f7624a
commit 7290d1b18c
2 changed files with 12 additions and 5 deletions

View File

@ -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);

View File

@ -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; }