diff OrthancFramework/Sources/FileStorage/FilesystemStorage.cpp @ 4484:64f06e7d5fc7

new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 28 Jan 2021 19:03:19 +0100
parents d9473bd5ed43
children fa2311f94d9f
line wrap: on
line diff
--- a/OrthancFramework/Sources/FileStorage/FilesystemStorage.cpp	Thu Jan 28 16:59:40 2021 +0100
+++ b/OrthancFramework/Sources/FileStorage/FilesystemStorage.cpp	Thu Jan 28 19:03:19 2021 +0100
@@ -28,8 +28,9 @@
 
 #include "../Logging.h"
 #include "../OrthancException.h"
+#include "../StringMemoryBuffer.h"
+#include "../SystemToolbox.h"
 #include "../Toolbox.h"
-#include "../SystemToolbox.h"
 
 #include <boost/filesystem/fstream.hpp>
 
@@ -150,15 +151,16 @@
   }
 
 
-  void FilesystemStorage::Read(std::string& content,
-                               const std::string& uuid,
-                               FileContentType type)
+  IMemoryBuffer* FilesystemStorage::Read(const std::string& uuid,
+                                         FileContentType type)
   {
     LOG(INFO) << "Reading attachment \"" << uuid << "\" of \"" << GetDescriptionInternal(type) 
               << "\" content type";
 
-    content.clear();
+    std::string content;
     SystemToolbox::ReadFile(content, GetPath(uuid).string());
+
+    return StringMemoryBuffer::CreateFromSwap(content);
   }
 
 
@@ -282,4 +284,15 @@
     Setup(root);
   }
 #endif
+
+
+#if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1
+  void FilesystemStorage::Read(std::string& content,
+                               const std::string& uuid,
+                               FileContentType type)
+  {
+    std::unique_ptr<IMemoryBuffer> buffer(Read(uuid, type));
+    buffer->MoveToString(content);
+  }
+#endif
 }