# HG changeset patch # User Sebastien Jodogne # Date 1551703041 -3600 # Node ID 0f721f015b8563ccc925e83888af1ddfc23b020a # Parent df90c2a56acdfadfb4c95b1f8a37d7c31d8591c5 fix diff -r df90c2a56acd -r 0f721f015b85 Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Mon Mar 04 13:10:46 2019 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Mon Mar 04 13:37:21 2019 +0100 @@ -145,6 +145,13 @@ } + void MemoryBuffer::Swap(MemoryBuffer& other) + { + std::swap(buffer_.data, other.buffer_.data); + std::swap(buffer_.size, other.buffer_.size); + } + + OrthancPluginMemoryBuffer MemoryBuffer::Release() { OrthancPluginMemoryBuffer result = buffer_; @@ -1024,11 +1031,11 @@ { CheckImageAvailable(); - OrthancPluginMemoryBuffer tmp; - OrthancPluginCompressPngImage(GetGlobalContext(), &tmp, GetPixelFormat(), + OrthancPlugins::MemoryBuffer answer; + OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(), GetWidth(), GetHeight(), GetPitch(), GetBuffer()); - target.Assign(tmp); + target.Swap(answer); } @@ -1037,11 +1044,11 @@ { CheckImageAvailable(); - OrthancPluginMemoryBuffer tmp; - OrthancPluginCompressJpegImage(GetGlobalContext(), &tmp, GetPixelFormat(), + OrthancPlugins::MemoryBuffer answer; + OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(), GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); - target.Assign(tmp); + target.Swap(answer); } @@ -1580,16 +1587,16 @@ ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); } - OrthancPluginMemoryBuffer answer; + OrthancPlugins::MemoryBuffer answer; uint16_t status; OrthancPluginErrorCode code = OrthancPluginCallPeerApi - (GetGlobalContext(), &answer, NULL, &status, peers_, + (GetGlobalContext(), *answer, NULL, &status, peers_, static_cast(index), OrthancPluginHttpMethod_Get, uri.c_str(), 0, NULL, NULL, NULL, 0, timeout_); if (code == OrthancPluginErrorCode_Success) { - target.Assign(answer); + target.Swap(answer); return (status == 200); } else @@ -1704,16 +1711,16 @@ ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); } - OrthancPluginMemoryBuffer answer; + OrthancPlugins::MemoryBuffer answer; uint16_t status; OrthancPluginErrorCode code = OrthancPluginCallPeerApi - (GetGlobalContext(), &answer, NULL, &status, peers_, + (GetGlobalContext(), *answer, NULL, &status, peers_, static_cast(index), OrthancPluginHttpMethod_Post, uri.c_str(), 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); if (code == OrthancPluginErrorCode_Success) { - target.Assign(answer); + target.Swap(answer); return (status == 200); } else @@ -1732,16 +1739,15 @@ ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); } - OrthancPluginMemoryBuffer answer; + OrthancPlugins::MemoryBuffer answer; uint16_t status; OrthancPluginErrorCode code = OrthancPluginCallPeerApi - (GetGlobalContext(), &answer, NULL, &status, peers_, + (GetGlobalContext(), *answer, NULL, &status, peers_, static_cast(index), OrthancPluginHttpMethod_Put, uri.c_str(), 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); if (code == OrthancPluginErrorCode_Success) { - OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &answer); return (status == 200); } else @@ -1769,16 +1775,15 @@ ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); } - OrthancPluginMemoryBuffer answer; + OrthancPlugins::MemoryBuffer answer; uint16_t status; OrthancPluginErrorCode code = OrthancPluginCallPeerApi - (GetGlobalContext(), &answer, NULL, &status, peers_, - static_cast(index), OrthancPluginHttpMethod_Delete, uri.c_str(), - 0, NULL, NULL, NULL, 0, timeout_); + (GetGlobalContext(), *answer, NULL, &status, peers_, + static_cast(index), OrthancPluginHttpMethod_Delete, uri.c_str(), + 0, NULL, NULL, NULL, 0, timeout_); if (code == OrthancPluginErrorCode_Success) { - OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &answer); return (status == 200); } else diff -r df90c2a56acd -r 0f721f015b85 Plugins/Samples/Common/OrthancPluginCppWrapper.h --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Mon Mar 04 13:10:46 2019 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Mon Mar 04 13:37:21 2019 +0100 @@ -129,6 +129,8 @@ // This transfers ownership from "other" to "this" void Assign(OrthancPluginMemoryBuffer& other); + void Swap(MemoryBuffer& other); + OrthancPluginMemoryBuffer Release(); const char* GetData() const