From 7290d1b18c82511b2e3b9339100e882c3e1fc8b5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 19 Feb 2007 21:11:13 +0000 Subject: 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 --- common/stream.cpp | 4 ++-- common/stream.h | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/common/stream.cpp b/common/stream.cpp index afc21ebca2..3926fc30f6 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -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); diff --git a/common/stream.h b/common/stream.h index 84eac2ac44..7b64262d48 100644 --- a/common/stream.h +++ b/common/stream.h @@ -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; } -- cgit v1.2.3