diff options
author | Max Horn | 2007-02-19 21:11:13 +0000 |
---|---|---|
committer | Max Horn | 2007-02-19 21:11:13 +0000 |
commit | 7290d1b18c82511b2e3b9339100e882c3e1fc8b5 (patch) | |
tree | 6b2c2ed2ef387077617aa2608fb1750b25ea6cd4 | |
parent | 60e0f7624af149529b30d5d1b96364cd4b6db12a (diff) | |
download | scummvm-rg350-7290d1b18c82511b2e3b9339100e882c3e1fc8b5.tar.gz scummvm-rg350-7290d1b18c82511b2e3b9339100e882c3e1fc8b5.tar.bz2 scummvm-rg350-7290d1b18c82511b2e3b9339100e882c3e1fc8b5.zip |
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
-rw-r--r-- | common/stream.cpp | 4 | ||||
-rw-r--r-- | 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; } |