aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2017-09-24 06:21:54 +0200
committerGitHub2017-09-24 06:21:54 +0200
commit25d66b2a08f6a1ad09c7ad7dc9db11ad3a4c76cf (patch)
tree9b28c0382e0c7362e2d88e73b8e312f8a8bbbdd8
parent75026dba8cb3a9870e1e8f35b2625410ff49a131 (diff)
parentbe67f0d8bfb4148e014931cce63b52e84ed95ee6 (diff)
downloadscummvm-rg350-25d66b2a08f6a1ad09c7ad7dc9db11ad3a4c76cf.tar.gz
scummvm-rg350-25d66b2a08f6a1ad09c7ad7dc9db11ad3a4c76cf.tar.bz2
scummvm-rg350-25d66b2a08f6a1ad09c7ad7dc9db11ad3a4c76cf.zip
Merge pull request #1027 from bgK/memstream-default-arg
COMMON: Remove the DisposeAfterUse default value from dynamic write memory streams constructors
-rw-r--r--audio/decoders/quicktime.cpp2
-rw-r--r--audio/midiparser_qt.cpp2
-rw-r--r--backends/networking/curl/networkreadstream.cpp23
-rw-r--r--backends/networking/curl/networkreadstream.h46
-rw-r--r--common/memstream.h4
-rw-r--r--engines/agi/sound_midi.cpp2
-rw-r--r--engines/dm/eventman.cpp2
-rw-r--r--engines/fullpipe/statesaver.cpp2
-rw-r--r--engines/gnap/menu.cpp2
-rw-r--r--engines/pegasus/ai/ai_area.cpp2
-rw-r--r--engines/scumm/saveload.cpp2
-rw-r--r--engines/sword1/control.cpp2
-rw-r--r--engines/sword25/gfx/screenshot.cpp6
-rw-r--r--engines/sword25/script/luascript.cpp2
-rw-r--r--engines/xeen/saves.cpp25
-rw-r--r--engines/xeen/saves.h9
-rw-r--r--engines/zvision/file/save_manager.cpp4
17 files changed, 82 insertions, 55 deletions
diff --git a/audio/decoders/quicktime.cpp b/audio/decoders/quicktime.cpp
index b8eccb664b..4b0d5e078f 100644
--- a/audio/decoders/quicktime.cpp
+++ b/audio/decoders/quicktime.cpp
@@ -344,7 +344,7 @@ bool QuickTimeAudioDecoder::QuickTimeAudioTrack::isOldDemuxing() const {
AudioStream *QuickTimeAudioDecoder::QuickTimeAudioTrack::readAudioChunk(uint chunk) {
AudioSampleDesc *entry = (AudioSampleDesc *)_parentTrack->sampleDescs[0];
- Common::MemoryWriteStreamDynamic *wStream = new Common::MemoryWriteStreamDynamic();
+ Common::MemoryWriteStreamDynamic *wStream = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::NO);
_decoder->_fd->seek(_parentTrack->chunkOffsets[chunk]);
diff --git a/audio/midiparser_qt.cpp b/audio/midiparser_qt.cpp
index 3078be9186..8821dbfaa8 100644
--- a/audio/midiparser_qt.cpp
+++ b/audio/midiparser_qt.cpp
@@ -455,7 +455,7 @@ void MidiParser_QT::initCommon() {
byte *MidiParser_QT::readWholeTrack(Common::QuickTimeParser::Track *track, uint32 &trackSize) {
// This just goes through all chunks and appends them together
- Common::MemoryWriteStreamDynamic output;
+ Common::MemoryWriteStreamDynamic output(DisposeAfterUse::NO);
uint32 curSample = 0;
// Read in the note request data first
diff --git a/backends/networking/curl/networkreadstream.cpp b/backends/networking/curl/networkreadstream.cpp
index e4fc5492b5..d3859cebc2 100644
--- a/backends/networking/curl/networkreadstream.cpp
+++ b/backends/networking/curl/networkreadstream.cpp
@@ -29,35 +29,35 @@
namespace Networking {
-static size_t curlDataCallback(char *d, size_t n, size_t l, void *p) {
+size_t NetworkReadStream::curlDataCallback(char *d, size_t n, size_t l, void *p) {
NetworkReadStream *stream = (NetworkReadStream *)p;
if (stream)
- return stream->write(d, n * l);
+ return stream->_backingStream.write(d, n * l);
return 0;
}
-static size_t curlReadDataCallback(char *d, size_t n, size_t l, void *p) {
+size_t NetworkReadStream::curlReadDataCallback(char *d, size_t n, size_t l, void *p) {
NetworkReadStream *stream = (NetworkReadStream *)p;
if (stream)
return stream->fillWithSendingContents(d, n * l);
return 0;
}
-static size_t curlHeadersCallback(char *d, size_t n, size_t l, void *p) {
+size_t NetworkReadStream::curlHeadersCallback(char *d, size_t n, size_t l, void *p) {
NetworkReadStream *stream = (NetworkReadStream *)p;
if (stream)
return stream->addResponseHeaders(d, n * l);
return 0;
}
-static int curlProgressCallback(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) {
+int NetworkReadStream::curlProgressCallback(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) {
NetworkReadStream *stream = (NetworkReadStream *)p;
if (stream)
stream->setProgress(dlnow, dltotal);
return 0;
}
-static int curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow) {
+int NetworkReadStream::curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow) {
// for libcurl older than 7.32.0 (CURLOPT_PROGRESSFUNCTION)
return curlProgressCallback(p, (curl_off_t)dltotal, (curl_off_t)dlnow, (curl_off_t)ultotal, (curl_off_t)ulnow);
}
@@ -178,15 +178,18 @@ void NetworkReadStream::init(const char *url, curl_slist *headersList, Common::H
ConnMan.registerEasyHandle(_easy);
}
-NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields, bool uploading, bool usingPatch) {
+NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields, bool uploading, bool usingPatch) :
+ _backingStream(DisposeAfterUse::YES) {
init(url, headersList, (const byte *)postFields.c_str(), postFields.size(), uploading, usingPatch, false);
}
-NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::HashMap<Common::String, Common::String> formFields, Common::HashMap<Common::String, Common::String> formFiles) {
+NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::HashMap<Common::String, Common::String> formFields, Common::HashMap<Common::String, Common::String> formFiles) :
+ _backingStream(DisposeAfterUse::YES) {
init(url, headersList, formFields, formFiles);
}
-NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post) {
+NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post) :
+ _backingStream(DisposeAfterUse::YES) {
init(url, headersList, buffer, bufferSize, uploading, usingPatch, post);
}
@@ -201,7 +204,7 @@ bool NetworkReadStream::eos() const {
}
uint32 NetworkReadStream::read(void *dataPtr, uint32 dataSize) {
- uint32 actuallyRead = MemoryReadWriteStream::read(dataPtr, dataSize);
+ uint32 actuallyRead = _backingStream.read(dataPtr, dataSize);
if (actuallyRead == 0) {
if (_requestComplete)
diff --git a/backends/networking/curl/networkreadstream.h b/backends/networking/curl/networkreadstream.h
index 8e59429a0a..c0ed5ee1c6 100644
--- a/backends/networking/curl/networkreadstream.h
+++ b/backends/networking/curl/networkreadstream.h
@@ -34,8 +34,9 @@ struct curl_slist;
namespace Networking {
-class NetworkReadStream: public Common::MemoryReadWriteStream {
+class NetworkReadStream: public Common::ReadStream {
CURL *_easy;
+ Common::MemoryReadWriteStream _backingStream;
bool _eos, _requestComplete;
const byte *_sendingContentsBuffer;
uint32 _sendingContentsSize;
@@ -46,6 +47,30 @@ class NetworkReadStream: public Common::MemoryReadWriteStream {
void init(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post);
void init(const char *url, curl_slist *headersList, Common::HashMap<Common::String, Common::String> formFields, Common::HashMap<Common::String, Common::String> formFiles);
+ /**
+ * Fills the passed buffer with _sendingContentsBuffer contents.
+ * It works similarly to read(), expect it's not for reading
+ * Stream's contents, but for sending our own data to the server.
+ *
+ * @returns how many bytes were actually read (filled in)
+ */
+ uint32 fillWithSendingContents(char *bufferToFill, uint32 maxSize);
+
+ /**
+ * Remembers headers returned to CURL in server's response.
+ *
+ * @returns how many bytes were actually read
+ */
+ uint32 addResponseHeaders(char *buffer, uint32 bufferSize);
+
+ /** Used in curl progress callback to pass current downloaded/total values. */
+ void setProgress(uint64 downloaded, uint64 total);
+
+ static size_t curlDataCallback(char *d, size_t n, size_t l, void *p);
+ static size_t curlReadDataCallback(char *d, size_t n, size_t l, void *p);
+ static size_t curlHeadersCallback(char *d, size_t n, size_t l, void *p);
+ static int curlProgressCallback(void *p, long dltotal, long dlnow, long ultotal, long ulnow);
+ static int curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
public:
/** Send <postFields>, using POST by default. */
NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields, bool uploading = false, bool usingPatch = false);
@@ -115,27 +140,8 @@ public:
*/
Common::String responseHeaders() const;
- /**
- * Fills the passed buffer with _sendingContentsBuffer contents.
- * It works similarly to read(), expect it's not for reading
- * Stream's contents, but for sending our own data to the server.
- *
- * @returns how many bytes were actually read (filled in)
- */
- uint32 fillWithSendingContents(char *bufferToFill, uint32 maxSize);
-
- /**
- * Remembers headers returned to CURL in server's response.
- *
- * @returns how many bytes were actually read
- */
- uint32 addResponseHeaders(char *buffer, uint32 bufferSize);
-
/** Returns a number in range [0, 1], where 1 is "complete". */
double getProgress() const;
-
- /** Used in curl progress callback to pass current downloaded/total values. */
- void setProgress(uint64 downloaded, uint64 total);
};
} // End of namespace Networking
diff --git a/common/memstream.h b/common/memstream.h
index 0338d35378..f6bf990208 100644
--- a/common/memstream.h
+++ b/common/memstream.h
@@ -184,7 +184,7 @@ protected:
_size = new_len;
}
public:
- MemoryWriteStreamDynamic(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {}
+ explicit MemoryWriteStreamDynamic(DisposeAfterUse::Flag disposeMemory) : _capacity(0), _size(0), _ptr(0), _data(0), _pos(0), _disposeMemory(disposeMemory) {}
~MemoryWriteStreamDynamic() {
if (_disposeMemory)
@@ -247,7 +247,7 @@ private:
}
}
public:
- MemoryReadWriteStream(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : _capacity(0), _size(0), _data(0), _writePos(0), _readPos(0), _pos(0), _length(0), _disposeMemory(disposeMemory), _eos(false) {}
+ explicit MemoryReadWriteStream(DisposeAfterUse::Flag disposeMemory) : _capacity(0), _size(0), _data(0), _writePos(0), _readPos(0), _pos(0), _length(0), _disposeMemory(disposeMemory), _eos(false) {}
~MemoryReadWriteStream() {
if (_disposeMemory)
diff --git a/engines/agi/sound_midi.cpp b/engines/agi/sound_midi.cpp
index 6998df6862..97dcc0d98b 100644
--- a/engines/agi/sound_midi.cpp
+++ b/engines/agi/sound_midi.cpp
@@ -169,7 +169,7 @@ static uint32 convertSND2MIDI(byte *snddata, byte **data) {
int n;
double ll;
- Common::MemoryWriteStreamDynamic st;
+ Common::MemoryWriteStreamDynamic st(DisposeAfterUse::NO);
ll = log10(pow(2.0, 1.0 / 12.0));
diff --git a/engines/dm/eventman.cpp b/engines/dm/eventman.cpp
index 622a7d5e1f..3859fc90b2 100644
--- a/engines/dm/eventman.cpp
+++ b/engines/dm/eventman.cpp
@@ -782,7 +782,7 @@ void EventManager::processCommandQueue() {
delete _vm->_saveThumbnail;
_vm->_saveThumbnail = nullptr;
} else if (!_vm->_saveThumbnail) {
- _vm->_saveThumbnail = new Common::MemoryWriteStreamDynamic();
+ _vm->_saveThumbnail = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES);
Graphics::saveThumbnail(*_vm->_saveThumbnail);
}
diff --git a/engines/fullpipe/statesaver.cpp b/engines/fullpipe/statesaver.cpp
index 7fb56f0479..5eb08fe213 100644
--- a/engines/fullpipe/statesaver.cpp
+++ b/engines/fullpipe/statesaver.cpp
@@ -55,7 +55,7 @@ bool GameLoader::writeSavegame(Scene *sc, const char *fname) {
header.updateCounter = _updateCounter;
header.unkField = 1;
- Common::MemoryWriteStreamDynamic stream;
+ Common::MemoryWriteStreamDynamic stream(DisposeAfterUse::YES);
MfcArchive *archive = new MfcArchive(&stream);
diff --git a/engines/gnap/menu.cpp b/engines/gnap/menu.cpp
index 2bfe7300df..9606273b4c 100644
--- a/engines/gnap/menu.cpp
+++ b/engines/gnap/menu.cpp
@@ -211,7 +211,7 @@ void GnapEngine::runMenu() {
_menuDone = false;
delete _tempThumbnail;
- _tempThumbnail = new Common::MemoryWriteStreamDynamic;
+ _tempThumbnail = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES);
Graphics::saveThumbnail(*_tempThumbnail);
createMenuSprite();
diff --git a/engines/pegasus/ai/ai_area.cpp b/engines/pegasus/ai/ai_area.cpp
index c078d5e80e..58698e6c77 100644
--- a/engines/pegasus/ai/ai_area.cpp
+++ b/engines/pegasus/ai/ai_area.cpp
@@ -78,7 +78,7 @@ void AIArea::saveAIState() {
delete vm->_aiSaveStream;
- Common::MemoryWriteStreamDynamic out;
+ Common::MemoryWriteStreamDynamic out(DisposeAfterUse::NO);
writeAIRules(&out);
vm->_aiSaveStream = new Common::MemoryReadStream(out.getData(), out.size(), DisposeAfterUse::YES);
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index 0ab36d1a96..06d564648b 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -228,7 +228,7 @@ void ScummEngine_v4::prepareSavegame() {
_savePreparedSavegame = NULL;
// store headerless savegame in a compressed memory stream
- memStream = new Common::MemoryWriteStreamDynamic();
+ memStream = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::NO);
writeStream = Common::wrapCompressedWriteStream(memStream);
if (saveState(writeStream, false)) {
// we have to finalize the compression-stream first, otherwise the internal
diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp
index fbc3f6af4a..0c53430ba3 100644
--- a/engines/sword1/control.cpp
+++ b/engines/sword1/control.cpp
@@ -303,7 +303,7 @@ static int volToBalance(int volL, int volR) {
uint8 Control::runPanel() {
// Make a thumbnail of the screen before displaying the menu in case we want to save
// the game from the menu.
- _tempThumbnail = new Common::MemoryWriteStreamDynamic;
+ _tempThumbnail = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES);
Graphics::saveThumbnail(*_tempThumbnail);
_panelShown = true;
diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp
index eeaece97f2..c86a2fe1d5 100644
--- a/engines/sword25/gfx/screenshot.cpp
+++ b/engines/sword25/gfx/screenshot.cpp
@@ -113,11 +113,11 @@ Common::SeekableReadStream *Screenshot::createThumbnail(Graphics::Surface *data)
}
// Create a PNG representation of the thumbnail data
- Common::MemoryWriteStreamDynamic *stream = new Common::MemoryWriteStreamDynamic();
- saveToFile(&thumbnail, stream);
+ Common::MemoryWriteStreamDynamic stream(DisposeAfterUse::NO);
+ saveToFile(&thumbnail, &stream);
// Output a MemoryReadStream that encompasses the written data
- Common::SeekableReadStream *result = new Common::MemoryReadStream(stream->getData(), stream->size(),
+ Common::SeekableReadStream *result = new Common::MemoryReadStream(stream.getData(), stream.size(),
DisposeAfterUse::YES);
return result;
}
diff --git a/engines/sword25/script/luascript.cpp b/engines/sword25/script/luascript.cpp
index 3aca6676ac..1a83fc9c82 100644
--- a/engines/sword25/script/luascript.cpp
+++ b/engines/sword25/script/luascript.cpp
@@ -395,7 +395,7 @@ bool LuaScriptEngine::persist(OutputPersistenceBlock &writer) {
lua_getglobal(_state, "_G");
// Lua persists and stores the data in a WriteStream
- Common::MemoryWriteStreamDynamic writeStream;
+ Common::MemoryWriteStreamDynamic writeStream(DisposeAfterUse::YES);
Lua::persistLua(_state, &writeStream);
// Persistenzdaten in den Writer schreiben.
diff --git a/engines/xeen/saves.cpp b/engines/xeen/saves.cpp
index 4df4b3727c..f9a26b1d6b 100644
--- a/engines/xeen/saves.cpp
+++ b/engines/xeen/saves.cpp
@@ -30,17 +30,27 @@
namespace Xeen {
OutFile::OutFile(XeenEngine *vm, const Common::String filename) :
- _vm(vm), _filename(filename) {
+ _vm(vm),
+ _filename(filename),
+ _backingStream(DisposeAfterUse::YES) {
+}
+
+uint32 OutFile::write(const void *dataPtr, uint32 dataSize) {
+ return _backingStream.write(dataPtr, dataSize);
+}
+
+int32 OutFile::pos() const {
+ return _backingStream.pos();
}
void OutFile::finalize() {
uint16 id = BaseCCArchive::convertNameToId(_filename);
if (!_vm->_saves->_newData.contains(id))
- _vm->_saves->_newData[id] = Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES);
+ _vm->_saves->_newData[id] = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES);
- Common::MemoryWriteStreamDynamic &out = _vm->_saves->_newData[id];
- out.write(getData(), size());
+ Common::MemoryWriteStreamDynamic *out = _vm->_saves->_newData[id];
+ out->write(_backingStream.getData(), _backingStream.size());
}
/*------------------------------------------------------------------------*/
@@ -54,6 +64,9 @@ SavesManager::SavesManager(XeenEngine *vm, Party &party) :
}
SavesManager::~SavesManager() {
+ for (Common::HashMap<uint16, Common::MemoryWriteStreamDynamic *>::iterator it = _newData.begin(); it != _newData.end(); it++) {
+ delete (*it)._value;
+ }
delete[] _data;
}
@@ -86,8 +99,8 @@ Common::SeekableReadStream *SavesManager::createReadStreamForMember(const Common
// save manager, then return that new resource
uint16 id = BaseCCArchive::convertNameToId(name);
if (_newData.contains(id)) {
- Common::MemoryWriteStreamDynamic stream = _newData[id];
- return new Common::MemoryReadStream(stream.getData(), stream.size());
+ Common::MemoryWriteStreamDynamic *stream = _newData[id];
+ return new Common::MemoryReadStream(stream->getData(), stream->size());
}
// Retrieve the resource from the loaded savefile
diff --git a/engines/xeen/saves.h b/engines/xeen/saves.h
index 2571c46600..9c161c838c 100644
--- a/engines/xeen/saves.h
+++ b/engines/xeen/saves.h
@@ -44,14 +44,19 @@ struct XeenSavegameHeader {
class XeenEngine;
class SavesManager;
-class OutFile : public Common::MemoryWriteStreamDynamic {
+class OutFile : public Common::WriteStream {
private:
XeenEngine *_vm;
Common::String _filename;
+ Common::MemoryWriteStreamDynamic _backingStream;
public:
OutFile(XeenEngine *vm, const Common::String filename);
void finalize();
+
+ uint32 write(const void *dataPtr, uint32 dataSize) override;
+
+ int32 pos() const override;
};
class SavesManager: public BaseCCArchive {
@@ -60,7 +65,7 @@ private:
XeenEngine *_vm;
Party &_party;
byte *_data;
- Common::HashMap<uint16, Common::MemoryWriteStreamDynamic > _newData;
+ Common::HashMap<uint16, Common::MemoryWriteStreamDynamic *> _newData;
void load(Common::SeekableReadStream *stream);
public:
diff --git a/engines/zvision/file/save_manager.cpp b/engines/zvision/file/save_manager.cpp
index 8a78e988b3..4259937a3b 100644
--- a/engines/zvision/file/save_manager.cpp
+++ b/engines/zvision/file/save_manager.cpp
@@ -273,11 +273,11 @@ Common::SeekableReadStream *SaveManager::getSlotFile(uint slot) {
void SaveManager::prepareSaveBuffer() {
delete _tempThumbnail;
- _tempThumbnail = new Common::MemoryWriteStreamDynamic;
+ _tempThumbnail = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES);
Graphics::saveThumbnail(*_tempThumbnail);
delete _tempSave;
- _tempSave = new Common::MemoryWriteStreamDynamic;
+ _tempSave = new Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES);
_engine->getScriptManager()->serialize(_tempSave);
}