From 264dc1349bc1f61c5f27383d4293b4c2dcf34b87 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 24 Jun 2004 14:06:22 +0000 Subject: Extended ReadMemoryStream class with seek method svn-id: r14030 --- common/stream.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'common') diff --git a/common/stream.h b/common/stream.h index d30fa63a6d..3b6d7a8d34 100644 --- a/common/stream.h +++ b/common/stream.h @@ -143,6 +143,35 @@ public: _size = _sizeOrig; _pos = 0; } + + void seek(uint32 offs, int whence = SEEK_SET) { + switch (whence) { + case SEEK_SET: + rewind(); + if (offs > _size) + offs = _size; + _size -= offs; + _ptr += offs; + _pos += offs; + break; + + case SEEK_CUR: + _size -= offs; + _ptr += offs; + _pos += offs; + break; + + case SEEK_END: + rewind(); + if (offs > _size) + offs = 0; + offs = _size - offs; + _size -= offs; + _ptr += offs; + _pos += offs; + break; + } + } }; } // End of namespace Common -- cgit v1.2.3