changeset 3320:0f721f015b85

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Mar 2019 13:37:21 +0100
parents df90c2a56acd
children e54ca78059bd
files Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h
diffstat 2 files changed, 27 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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<uint32_t>(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<uint32_t>(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<uint32_t>(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<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(),
-         0, NULL, NULL, NULL, 0, timeout_);
+      (GetGlobalContext(), *answer, NULL, &status, peers_,
+       static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(),
+       0, NULL, NULL, NULL, 0, timeout_);
 
     if (code == OrthancPluginErrorCode_Success)
     {
-      OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &answer);
       return (status == 200);
     }
     else
--- 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