# HG changeset patch # User Sebastien Jodogne # Date 1618332201 -7200 # Node ID 02cd7254c94967baf7edcbb693d286fa5c45e165 # Parent f5dc59c56e657feea7e1ab80c10a2e3f9dfcf798 separating class InputFileValue from FileValue diff -r f5dc59c56e65 -r 02cd7254c949 Framework/Common/BinaryStringValue.cpp --- 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; diff -r f5dc59c56e65 -r 02cd7254c949 Framework/Common/DatabasesEnumerations.h --- 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 diff -r f5dc59c56e65 -r 02cd7254c949 Framework/Common/Dictionary.cpp --- 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)); } diff -r f5dc59c56e65 -r 02cd7254c949 Framework/Common/FileValue.h --- 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(buffer), size); - } - std::string& GetContent() { return content_; diff -r f5dc59c56e65 -r 02cd7254c949 Framework/Common/InputFileValue.cpp --- /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 . + **/ + + +#include "InputFileValue.h" + +#include "BinaryStringValue.h" +#include "NullValue.h" + +#include + +#include + +namespace OrthancDatabases +{ + IValue* InputFileValue::Convert(ValueType target) const + { + switch (target) + { + case ValueType_BinaryString: + return new BinaryStringValue(content_); + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType); + } + } +} diff -r f5dc59c56e65 -r 02cd7254c949 Framework/Common/InputFileValue.h --- /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 . + **/ + + +#pragma once + +#include "IValue.h" + +#include + +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(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; + }; +} diff -r f5dc59c56e65 -r 02cd7254c949 Framework/Common/Integer64Value.cpp --- 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); diff -r f5dc59c56e65 -r 02cd7254c949 Framework/Common/Utf8StringValue.cpp --- 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 { diff -r f5dc59c56e65 -r 02cd7254c949 Framework/MySQL/MySQLStatement.cpp --- 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(value).GetContent(); + const std::string& content = dynamic_cast(value).GetContent(); inputs[i].buffer = const_cast(content.c_str()); inputs[i].buffer_length = content.size(); inputs[i].buffer_type = MYSQL_TYPE_BLOB; diff -r f5dc59c56e65 -r 02cd7254c949 Framework/Plugins/StorageBackend.cpp --- 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; diff -r f5dc59c56e65 -r 02cd7254c949 Framework/PostgreSQL/PostgreSQLStatement.cpp --- 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(parameters.GetValue(name)); + const InputFileValue& blob = + dynamic_cast(parameters.GetValue(name)); PostgreSQLLargeObject largeObject(database_, blob.GetContent()); BindLargeObject(i, largeObject); diff -r f5dc59c56e65 -r 02cd7254c949 Resources/CMake/DatabasesFrameworkConfiguration.cmake --- 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