changeset 244:02cd7254c949

separating class InputFileValue from FileValue
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 13 Apr 2021 18:43:21 +0200
parents f5dc59c56e65
children 9d00e5e073e8
files Framework/Common/BinaryStringValue.cpp Framework/Common/DatabasesEnumerations.h Framework/Common/Dictionary.cpp Framework/Common/FileValue.h Framework/Common/InputFileValue.cpp Framework/Common/InputFileValue.h Framework/Common/Integer64Value.cpp Framework/Common/Utf8StringValue.cpp Framework/MySQL/MySQLStatement.cpp Framework/Plugins/StorageBackend.cpp Framework/PostgreSQL/PostgreSQLStatement.cpp Resources/CMake/DatabasesFrameworkConfiguration.cmake
diffstat 12 files changed, 127 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Common/BinaryStringValue.cpp	Tue Apr 13 17:53:53 2021 +0200
+++ b/Framework/Common/BinaryStringValue.cpp	Tue Apr 13 18:43:21 2021 +0200
@@ -34,9 +34,6 @@
   {
     switch (target)
     {
-      case ValueType_File:
-        return new FileValue(content_);
-
       case ValueType_Null:
         return new NullValue;
 
--- a/Framework/Common/DatabasesEnumerations.h	Tue Apr 13 17:53:53 2021 +0200
+++ b/Framework/Common/DatabasesEnumerations.h	Tue Apr 13 18:43:21 2021 +0200
@@ -28,6 +28,7 @@
   {
     ValueType_BinaryString,
     ValueType_File,
+    ValueType_InputFile,
     ValueType_Integer64,
     ValueType_Null,
     ValueType_Utf8String
--- a/Framework/Common/Dictionary.cpp	Tue Apr 13 17:53:53 2021 +0200
+++ b/Framework/Common/Dictionary.cpp	Tue Apr 13 18:43:21 2021 +0200
@@ -22,7 +22,7 @@
 #include "Dictionary.h"
 
 #include "BinaryStringValue.h"
-#include "FileValue.h"
+#include "InputFileValue.h"
 #include "Integer64Value.h"
 #include "NullValue.h"
 #include "Utf8StringValue.h"
@@ -104,7 +104,7 @@
   void Dictionary::SetFileValue(const std::string& key,
                                 const std::string& file)
   {
-    SetValue(key, new FileValue(file));
+    SetValue(key, new InputFileValue(file));
   }
 
   
@@ -112,7 +112,7 @@
                                 const void* content,
                                 size_t size)
   {
-    SetValue(key, new FileValue(content, size));
+    SetValue(key, new InputFileValue(content, size));
   }
 
   
--- a/Framework/Common/FileValue.h	Tue Apr 13 17:53:53 2021 +0200
+++ b/Framework/Common/FileValue.h	Tue Apr 13 18:43:21 2021 +0200
@@ -37,17 +37,6 @@
     {
     }
 
-    explicit FileValue(const std::string& content) :
-      content_(content)
-    {
-    }
-
-    FileValue(const void* buffer,
-              size_t size)
-    {
-      content_.assign(reinterpret_cast<const char*>(buffer), size);
-    }
-    
     std::string& GetContent()
     {
       return content_;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Common/InputFileValue.cpp	Tue Apr 13 18:43:21 2021 +0200
@@ -0,0 +1,44 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2021 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "InputFileValue.h"
+
+#include "BinaryStringValue.h"
+#include "NullValue.h"
+
+#include <OrthancException.h>
+
+#include <boost/lexical_cast.hpp>
+
+namespace OrthancDatabases
+{
+  IValue* InputFileValue::Convert(ValueType target) const
+  {
+    switch (target)
+    {
+      case ValueType_BinaryString:
+        return new BinaryStringValue(content_);
+
+      default:
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Common/InputFileValue.h	Tue Apr 13 18:43:21 2021 +0200
@@ -0,0 +1,69 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2021 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#include "IValue.h"
+
+#include <Compatibility.h>
+
+namespace OrthancDatabases
+{
+  class InputFileValue : public IValue
+  {
+  private:
+    std::string  content_;
+
+  public:
+    explicit InputFileValue(const std::string& content) :
+      content_(content)
+    {
+    }
+
+    InputFileValue(const void* buffer,
+                   size_t size)
+    {
+      content_.assign(reinterpret_cast<const char*>(buffer), size);
+    }
+    
+    const std::string& GetContent() const
+    {
+      return content_;
+    }
+
+    const void* GetBuffer() const
+    {
+      return (content_.empty() ? NULL : content_.c_str());
+    }
+
+    size_t GetSize() const
+    {
+      return content_.size();
+    }
+
+    virtual ValueType GetType() const ORTHANC_OVERRIDE
+    {
+      return ValueType_InputFile;
+    }
+    
+    virtual IValue* Convert(ValueType target) const ORTHANC_OVERRIDE;
+  };
+}
--- a/Framework/Common/Integer64Value.cpp	Tue Apr 13 17:53:53 2021 +0200
+++ b/Framework/Common/Integer64Value.cpp	Tue Apr 13 18:43:21 2021 +0200
@@ -44,9 +44,6 @@
       case ValueType_BinaryString:
         return new BinaryStringValue(s);
 
-      case ValueType_File:
-        return new FileValue(s);
-
       case ValueType_Utf8String:
         return new Utf8StringValue(s);
 
--- a/Framework/Common/Utf8StringValue.cpp	Tue Apr 13 17:53:53 2021 +0200
+++ b/Framework/Common/Utf8StringValue.cpp	Tue Apr 13 18:43:21 2021 +0200
@@ -42,9 +42,6 @@
       case ValueType_BinaryString:
         return new BinaryStringValue(utf8_);
 
-      case ValueType_File:
-        return new FileValue(utf8_);
-
       case ValueType_Integer64:
         try
         {
--- a/Framework/MySQL/MySQLStatement.cpp	Tue Apr 13 17:53:53 2021 +0200
+++ b/Framework/MySQL/MySQLStatement.cpp	Tue Apr 13 18:43:21 2021 +0200
@@ -22,7 +22,7 @@
 #include "MySQLStatement.h"
 
 #include "../Common/BinaryStringValue.h"
-#include "../Common/FileValue.h"
+#include "../Common/InputFileValue.h"
 #include "../Common/Integer64Value.h"
 #include "../Common/NullValue.h"
 #include "../Common/Utf8StringValue.h"
@@ -500,9 +500,9 @@
           break;
         }
 
-        case ValueType_File:
+        case ValueType_InputFile:
         {
-          const std::string& content = dynamic_cast<const FileValue&>(value).GetContent();
+          const std::string& content = dynamic_cast<const InputFileValue&>(value).GetContent();
           inputs[i].buffer = const_cast<char*>(content.c_str());
           inputs[i].buffer_length = content.size();
           inputs[i].buffer_type = MYSQL_TYPE_BLOB;
--- a/Framework/Plugins/StorageBackend.cpp	Tue Apr 13 17:53:53 2021 +0200
+++ b/Framework/Plugins/StorageBackend.cpp	Tue Apr 13 18:43:21 2021 +0200
@@ -98,7 +98,7 @@
         "INSERT INTO StorageArea VALUES (${uuid}, ${content}, ${type})");
      
       statement.SetParameterType("uuid", ValueType_Utf8String);
-      statement.SetParameterType("content", ValueType_File);
+      statement.SetParameterType("content", ValueType_InputFile);
       statement.SetParameterType("type", ValueType_Integer64);
 
       Dictionary args;
--- a/Framework/PostgreSQL/PostgreSQLStatement.cpp	Tue Apr 13 17:53:53 2021 +0200
+++ b/Framework/PostgreSQL/PostgreSQLStatement.cpp	Tue Apr 13 18:43:21 2021 +0200
@@ -23,7 +23,7 @@
 #include "PostgreSQLStatement.h"
 
 #include "../Common/BinaryStringValue.h"
-#include "../Common/FileValue.h"
+#include "../Common/InputFileValue.h"
 #include "../Common/Integer64Value.h"
 #include "../Common/NullValue.h"
 #include "../Common/ResultBase.h"
@@ -336,7 +336,7 @@
           DeclareInputBinary(i);
           break;
 
-        case ValueType_File:
+        case ValueType_InputFile:
           DeclareInputLargeObject(i);
           break;
 
@@ -533,10 +533,10 @@
                      (parameters.GetValue(name)).GetContent());
           break;
 
-        case ValueType_File:
+        case ValueType_InputFile:
         {
-          const FileValue& blob =
-            dynamic_cast<const FileValue&>(parameters.GetValue(name));
+          const InputFileValue& blob =
+            dynamic_cast<const InputFileValue&>(parameters.GetValue(name));
 
           PostgreSQLLargeObject largeObject(database_, blob.GetContent());
           BindLargeObject(i, largeObject);
--- a/Resources/CMake/DatabasesFrameworkConfiguration.cmake	Tue Apr 13 17:53:53 2021 +0200
+++ b/Resources/CMake/DatabasesFrameworkConfiguration.cmake	Tue Apr 13 18:43:21 2021 +0200
@@ -91,6 +91,7 @@
   ${ORTHANC_DATABASES_ROOT}/Framework/Common/FileValue.cpp
   ${ORTHANC_DATABASES_ROOT}/Framework/Common/GenericFormatter.cpp
   ${ORTHANC_DATABASES_ROOT}/Framework/Common/ImplicitTransaction.cpp
+  ${ORTHANC_DATABASES_ROOT}/Framework/Common/InputFileValue.cpp
   ${ORTHANC_DATABASES_ROOT}/Framework/Common/Integer64Value.cpp
   ${ORTHANC_DATABASES_ROOT}/Framework/Common/NullValue.cpp
   ${ORTHANC_DATABASES_ROOT}/Framework/Common/Query.cpp