aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2009-10-18 19:41:59 +0000
committerMax Horn2009-10-18 19:41:59 +0000
commit2bbf708deaf2d60c70786ec1ef2f9ea0d1f0bd4a (patch)
tree3aac193c0b0419c50f72690bdfa77016ea413464 /common
parent64861f1e40ee5084bcbfa3e5bd3adbe746d7dfc5 (diff)
downloadscummvm-rg350-2bbf708deaf2d60c70786ec1ef2f9ea0d1f0bd4a.tar.gz
scummvm-rg350-2bbf708deaf2d60c70786ec1ef2f9ea0d1f0bd4a.tar.bz2
scummvm-rg350-2bbf708deaf2d60c70786ec1ef2f9ea0d1f0bd4a.zip
Introduced new type Common::DisposeAfterUse::Flag
svn-id: r45233
Diffstat (limited to 'common')
-rw-r--r--common/stream.cpp8
-rw-r--r--common/stream.h30
-rw-r--r--common/unarj.cpp4
-rw-r--r--common/unzip.cpp2
-rw-r--r--common/xmlparser.cpp2
-rw-r--r--common/xmlparser.h2
6 files changed, 27 insertions, 21 deletions
diff --git a/common/stream.cpp b/common/stream.cpp
index 9329ddea6c..07ca37555d 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -37,7 +37,7 @@ MemoryReadStream *ReadStream::readStream(uint32 dataSize) {
void *buf = malloc(dataSize);
dataSize = read(buf, dataSize);
assert(dataSize > 0);
- return new MemoryReadStream((byte *)buf, dataSize, true);
+ return new MemoryReadStream((byte *)buf, dataSize, DisposeAfterUse::YES);
}
@@ -188,7 +188,7 @@ uint32 SubReadStream::read(void *dataPtr, uint32 dataSize) {
return dataSize;
}
-SeekableSubReadStream::SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream)
+SeekableSubReadStream::SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream)
: SubReadStream(parentStream, end, disposeParentStream),
_parentStream(parentStream),
_begin(begin) {
@@ -222,7 +222,7 @@ bool SeekableSubReadStream::seek(int32 offset, int whence) {
return ret;
}
-BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize, bool disposeParentStream)
+BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream)
: _parentStream(parentStream),
_disposeParentStream(disposeParentStream),
_pos(0),
@@ -279,7 +279,7 @@ uint32 BufferedReadStream::read(void *dataPtr, uint32 dataSize) {
return alreadyRead + dataSize;
}
-BufferedSeekableReadStream::BufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, bool disposeParentStream)
+BufferedSeekableReadStream::BufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream)
: BufferedReadStream(parentStream, bufSize, disposeParentStream),
_parentStream(parentStream) {
}
diff --git a/common/stream.h b/common/stream.h
index edc1c3e35a..3a1391e2ba 100644
--- a/common/stream.h
+++ b/common/stream.h
@@ -396,6 +396,11 @@ public:
virtual String readLine();
};
+
+namespace DisposeAfterUse {
+ enum Flag { NO, YES };
+}
+
/**
* SubReadStream provides access to a ReadStream restricted to the range
* [currentPosition, currentPosition+end).
@@ -407,12 +412,12 @@ public:
class SubReadStream : virtual public ReadStream {
protected:
ReadStream *_parentStream;
- bool _disposeParentStream;
+ DisposeAfterUse::Flag _disposeParentStream;
uint32 _pos;
uint32 _end;
bool _eos;
public:
- SubReadStream(ReadStream *parentStream, uint32 end, bool disposeParentStream = false)
+ SubReadStream(ReadStream *parentStream, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO)
: _parentStream(parentStream),
_disposeParentStream(disposeParentStream),
_pos(0),
@@ -421,7 +426,8 @@ public:
assert(parentStream);
}
~SubReadStream() {
- if (_disposeParentStream) delete _parentStream;
+ if (_disposeParentStream)
+ delete _parentStream;
}
virtual bool eos() const { return _eos; }
@@ -443,7 +449,7 @@ protected:
SeekableReadStream *_parentStream;
uint32 _begin;
public:
- SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool disposeParentStream = false);
+ SeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO);
virtual int32 pos() const { return _pos - _begin; }
virtual int32 size() const { return _end - _begin; }
@@ -463,7 +469,7 @@ private:
const bool _bigEndian;
public:
- SeekableSubReadStreamEndian(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool bigEndian = false, bool disposeParentStream = false)
+ SeekableSubReadStreamEndian(SeekableReadStream *parentStream, uint32 begin, uint32 end, bool bigEndian = false, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO)
: SeekableSubReadStream(parentStream, begin, end, disposeParentStream), _bigEndian(bigEndian) {
}
@@ -496,14 +502,14 @@ public:
class BufferedReadStream : virtual public ReadStream {
protected:
ReadStream *_parentStream;
- bool _disposeParentStream;
+ DisposeAfterUse::Flag _disposeParentStream;
byte *_buf;
uint32 _pos;
uint32 _bufSize;
uint32 _realBufSize;
public:
- BufferedReadStream(ReadStream *parentStream, uint32 bufSize, bool disposeParentStream = false);
+ BufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO);
~BufferedReadStream();
virtual bool eos() const { return (_pos == _bufSize) && _parentStream->eos(); }
@@ -521,7 +527,7 @@ class BufferedSeekableReadStream : public BufferedReadStream, public SeekableRea
protected:
SeekableReadStream *_parentStream;
public:
- BufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, bool disposeParentStream = false);
+ BufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO);
virtual int32 pos() const { return _parentStream->pos() - (_bufSize - _pos); }
virtual int32 size() const { return _parentStream->size(); }
@@ -542,7 +548,7 @@ private:
const uint32 _size;
uint32 _pos;
byte _encbyte;
- bool _disposeMemory;
+ DisposeAfterUse::Flag _disposeMemory;
bool _eos;
public:
@@ -552,7 +558,7 @@ public:
* wraps it. If disposeMemory is true, the MemoryReadStream takes ownership
* of the buffer and hence free's it when destructed.
*/
- MemoryReadStream(const byte *dataPtr, uint32 dataSize, bool disposeMemory = false) :
+ MemoryReadStream(const byte *dataPtr, uint32 dataSize, DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) :
_ptrOrig(dataPtr),
_ptr(dataPtr),
_size(dataSize),
@@ -649,7 +655,7 @@ private:
byte *_ptr;
byte *_data;
uint32 _pos;
- bool _disposeMemory;
+ DisposeAfterUse::Flag _disposeMemory;
void ensureCapacity(uint32 new_len) {
if (new_len <= _capacity)
@@ -670,7 +676,7 @@ private:
_size = new_len;
}
public:
- MemoryWriteStreamDynamic(bool disposeMemory = false) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {}
+ MemoryWriteStreamDynamic(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {}
~MemoryWriteStreamDynamic() {
if (_disposeMemory)
diff --git a/common/unarj.cpp b/common/unarj.cpp
index 0312cc5b08..793012946e 100644
--- a/common/unarj.cpp
+++ b/common/unarj.cpp
@@ -379,7 +379,7 @@ bool ArjFile::open(const Common::String &filename) {
// If reading from archiveFile directly is too slow to be usable,
// maybe the filesystem code should instead wrap its files
// in a BufferedReadStream.
- decoder->_compressed = new BufferedReadStream(&archiveFile, 4096, false);
+ decoder->_compressed = new BufferedReadStream(&archiveFile, 4096);
decoder->_outstream = new MemoryWriteStream(uncompressedData, hdr->origSize);
if (hdr->method == 1 || hdr->method == 2 || hdr->method == 3)
@@ -391,7 +391,7 @@ bool ArjFile::open(const Common::String &filename) {
}
- _uncompressed = new MemoryReadStream(uncompressedData, hdr->origSize, true);
+ _uncompressed = new MemoryReadStream(uncompressedData, hdr->origSize, DisposeAfterUse::YES);
assert(_uncompressed);
return true;
diff --git a/common/unzip.cpp b/common/unzip.cpp
index 1b0a09deeb..5c57736d4d 100644
--- a/common/unzip.cpp
+++ b/common/unzip.cpp
@@ -1442,7 +1442,7 @@ Common::SeekableReadStream *ZipArchive::createReadStreamForMember(const Common::
assert(buffer);
unzReadCurrentFile(_zipFile, buffer, fileInfo.uncompressed_size);
unzCloseCurrentFile(_zipFile);
- return new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size+1, true);
+ return new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size+1, DisposeAfterUse::YES);
// FIXME: instead of reading all into a memory stream, we could
// instead create a new ZipStream class. But then we have to be
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp
index 534007b03d..aee44666f3 100644
--- a/common/xmlparser.cpp
+++ b/common/xmlparser.cpp
@@ -48,7 +48,7 @@ bool XMLParser::loadFile(const FSNode &node) {
return true;
}
-bool XMLParser::loadBuffer(const byte *buffer, uint32 size, bool disposable) {
+bool XMLParser::loadBuffer(const byte *buffer, uint32 size, DisposeAfterUse::Flag disposable) {
_stream = new MemoryReadStream(buffer, size, disposable);
_fileName = "Memory Stream";
return true;
diff --git a/common/xmlparser.h b/common/xmlparser.h
index 0f859ecf14..344fd4068d 100644
--- a/common/xmlparser.h
+++ b/common/xmlparser.h
@@ -198,7 +198,7 @@ public:
* i.e. if it can be freed safely after it's
* no longer needed by the parser.
*/
- bool loadBuffer(const byte *buffer, uint32 size, bool disposable = false);
+ bool loadBuffer(const byte *buffer, uint32 size, DisposeAfterUse::Flag disposable = DisposeAfterUse::NO);
bool loadStream(Common::SeekableReadStream *stream);