diff options
author | Eugene Sandulenko | 2013-07-04 04:58:54 -0700 |
---|---|---|
committer | Eugene Sandulenko | 2013-07-04 04:58:54 -0700 |
commit | 49210a803a53b84bcabe42fd339a1b205236c34d (patch) | |
tree | d5916067b55404324fb70a3d3ee0a8f672f92679 /common/memstream.h | |
parent | 2b980e86e3db2ebc2279761ba29c0be4f24e03dc (diff) | |
parent | b286a6d033287dce11dfa4216ad11728b892667d (diff) | |
download | scummvm-rg350-49210a803a53b84bcabe42fd339a1b205236c34d.tar.gz scummvm-rg350-49210a803a53b84bcabe42fd339a1b205236c34d.tar.bz2 scummvm-rg350-49210a803a53b84bcabe42fd339a1b205236c34d.zip |
Merge pull request #331 from sev-/gsoc2012-eventsrecorder
GSoC2012: Event Recorder (reworked)
Diffstat (limited to 'common/memstream.h')
-rw-r--r-- | common/memstream.h | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/common/memstream.h b/common/memstream.h index 260fb64d84..7fa6500753 100644 --- a/common/memstream.h +++ b/common/memstream.h @@ -89,8 +89,9 @@ public: */ class MemoryWriteStream : public WriteStream { private: - byte *_ptr; const uint32 _bufSize; +protected: + byte *_ptr; uint32 _pos; bool _err; public: @@ -117,6 +118,40 @@ public: }; /** + * MemoryWriteStream subclass with ability to set stream position indicator. + */ +class SeekableMemoryWriteStream : public MemoryWriteStream { +private: + byte *_ptrOrig; +public: + SeekableMemoryWriteStream(byte *buf, uint32 len) : MemoryWriteStream(buf, len), _ptrOrig(buf) {} + uint32 seek(uint32 offset, int whence = SEEK_SET) { + switch (whence) { + case SEEK_END: + // SEEK_END works just like SEEK_SET, only 'reversed', + // i.e. from the end. + offset = size() + offset; + // Fall through + case SEEK_SET: + _ptr = _ptrOrig + offset; + _pos = offset; + break; + case SEEK_CUR: + _ptr += offset; + _pos += offset; + break; + } + // Post-Condition + if (_pos > size()) { + _pos = size(); + _ptr = _ptrOrig + _pos; + } + return _pos; + } +}; + + +/** * A sort of hybrid between MemoryWriteStream and Array classes. A stream * that grows as it's written to. */ |