aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2007-02-20 17:52:02 +0000
committerMax Horn2007-02-20 17:52:02 +0000
commitfb9c08f1016bc5f92f6cc18e4489160c575a0e07 (patch)
tree1421277bcd9aa7ce4944c2ec4b97e49f0f2b0bd3 /common
parentb4b6adc11eb484d91e5db161657c2fd9888e91b1 (diff)
downloadscummvm-rg350-fb9c08f1016bc5f92f6cc18e4489160c575a0e07.tar.gz
scummvm-rg350-fb9c08f1016bc5f92f6cc18e4489160c575a0e07.tar.bz2
scummvm-rg350-fb9c08f1016bc5f92f6cc18e4489160c575a0e07.zip
Removed XORReadStream (it was unused); enhanced MemoryReadStream to be able to dispose the memory block it wraps (simplifies memory management)
svn-id: r25748
Diffstat (limited to 'common')
-rw-r--r--common/stream.h48
1 files changed, 13 insertions, 35 deletions
diff --git a/common/stream.h b/common/stream.h
index 7b64262d48..85b4315aed 100644
--- a/common/stream.h
+++ b/common/stream.h
@@ -279,40 +279,6 @@ public:
};
/**
- * XORReadStream is a wrapper around an arbitrary other ReadStream,
- * which 'decrypts' the data being read by XORing all data bytes with the given
- * encryption 'key'.
- *
- * Currently, this is not used anywhere, it's just a demo of how one can chain
- * streams if necessary.
- */
-class XORReadStream : public ReadStream {
-private:
- byte _encbyte;
- ReadStream *_realStream;
-public:
- XORReadStream(ReadStream *in = 0, byte enc = 0) : _encbyte(enc), _realStream(in) {}
- void setStream(ReadStream *in) { _realStream = in; }
- void setEnc(byte value) { _encbyte = value; }
-
- virtual bool eos() const { return _realStream->eos(); }
- virtual bool ioFailed() const { return _realStream->ioFailed(); }
- virtual void clearIOFailed() { _realStream->clearIOFailed(); }
-
- uint32 read(void *dataPtr, uint32 dataSize) {
- assert(_realStream);
- uint32 len = _realStream->read(dataPtr, dataSize);
- if (_encbyte) {
- byte *p = (byte *)dataPtr;
- byte *end = p + len;
- while (p < end)
- *p++ ^= _encbyte;
- }
- return len;
- }
-};
-
-/**
* Simple memory based 'stream', which implements the ReadStream interface for
* a plain memory block.
*/
@@ -323,9 +289,21 @@ private:
const uint32 _bufSize;
uint32 _pos;
byte _encbyte;
+ bool _disposeMemory;
public:
- MemoryReadStream(const byte *buf, uint32 len) : _ptr(buf), _ptrOrig(buf), _bufSize(len), _pos(0), _encbyte(0) {}
+ MemoryReadStream(const byte *buf, uint32 len, bool disposeMemory = false) :
+ _ptr(buf),
+ _ptrOrig(buf),
+ _bufSize(len),
+ _pos(0),
+ _encbyte(0),
+ _disposeMemory(disposeMemory) {}
+
+ ~MemoryReadStream() {
+ if (_disposeMemory)
+ free((void *)_ptrOrig);
+ }
void setEnc(byte value) { _encbyte = value; }