changeset 554:1a74fc1bea2d find-refactoring

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Sep 2024 15:54:14 +0200
parents 7f45f23b10d0
children 44e6b65f1630
files Framework/Plugins/DatabaseConstraint.cpp Framework/Plugins/DatabaseConstraint.h Framework/Plugins/ISqlLookupFormatter.cpp Framework/Plugins/IndexBackend.cpp Framework/Plugins/MessagesToolbox.cpp Framework/Plugins/MessagesToolbox.h
diffstat 6 files changed, 149 insertions(+), 133 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseConstraint.cpp	Mon Sep 09 15:27:52 2024 +0200
+++ b/Framework/Plugins/DatabaseConstraint.cpp	Mon Sep 09 15:54:14 2024 +0200
@@ -38,106 +38,6 @@
 
 namespace OrthancDatabases
 {
-  namespace Plugins
-  {
-    OrthancPluginResourceType Convert(Orthanc::ResourceType type)
-    {
-      switch (type)
-      {
-        case Orthanc::ResourceType_Patient:
-          return OrthancPluginResourceType_Patient;
-
-        case Orthanc::ResourceType_Study:
-          return OrthancPluginResourceType_Study;
-
-        case Orthanc::ResourceType_Series:
-          return OrthancPluginResourceType_Series;
-
-        case Orthanc::ResourceType_Instance:
-          return OrthancPluginResourceType_Instance;
-
-        default:
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-      }
-    }
-
-
-    Orthanc::ResourceType Convert(OrthancPluginResourceType type)
-    {
-      switch (type)
-      {
-        case OrthancPluginResourceType_Patient:
-          return Orthanc::ResourceType_Patient;
-
-        case OrthancPluginResourceType_Study:
-          return Orthanc::ResourceType_Study;
-
-        case OrthancPluginResourceType_Series:
-          return Orthanc::ResourceType_Series;
-
-        case OrthancPluginResourceType_Instance:
-          return Orthanc::ResourceType_Instance;
-
-        default:
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-      }
-    }
-
-
-#if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
-    OrthancPluginConstraintType Convert(ConstraintType constraint)
-    {
-      switch (constraint)
-      {
-        case ConstraintType_Equal:
-          return OrthancPluginConstraintType_Equal;
-
-        case ConstraintType_GreaterOrEqual:
-          return OrthancPluginConstraintType_GreaterOrEqual;
-
-        case ConstraintType_SmallerOrEqual:
-          return OrthancPluginConstraintType_SmallerOrEqual;
-
-        case ConstraintType_Wildcard:
-          return OrthancPluginConstraintType_Wildcard;
-
-        case ConstraintType_List:
-          return OrthancPluginConstraintType_List;
-
-        default:
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-      }
-    }
-#endif
-
-
-#if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
-    ConstraintType Convert(OrthancPluginConstraintType constraint)
-    {
-      switch (constraint)
-      {
-        case OrthancPluginConstraintType_Equal:
-          return ConstraintType_Equal;
-
-        case OrthancPluginConstraintType_GreaterOrEqual:
-          return ConstraintType_GreaterOrEqual;
-
-        case OrthancPluginConstraintType_SmallerOrEqual:
-          return ConstraintType_SmallerOrEqual;
-
-        case OrthancPluginConstraintType_Wildcard:
-          return ConstraintType_Wildcard;
-
-        case OrthancPluginConstraintType_List:
-          return ConstraintType_List;
-
-        default:
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
-      }
-    }
-#endif
-  }
-
   DatabaseConstraint::DatabaseConstraint(Orthanc::ResourceType level,
                                          const Orthanc::DicomTag& tag,
                                          bool isIdentifier,
@@ -163,10 +63,10 @@
 
 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
   DatabaseConstraint::DatabaseConstraint(const OrthancPluginDatabaseConstraint& constraint) :
-    level_(Plugins::Convert(constraint.level)),
+    level_(MessagesToolbox::Convert(constraint.level)),
     tag_(constraint.tagGroup, constraint.tagElement),
     isIdentifier_(constraint.isIdentifierTag),
-    constraintType_(Plugins::Convert(constraint.type)),
+    constraintType_(MessagesToolbox::Convert(constraint.type)),
     caseSensitive_(constraint.isCaseSensitive),
     mandatory_(constraint.isMandatory)
   {
@@ -189,7 +89,7 @@
 
 #if ORTHANC_PLUGINS_HAS_INTEGRATED_FIND == 1
   DatabaseConstraint::DatabaseConstraint(const Orthanc::DatabasePluginMessages::DatabaseConstraint& constraint) :
-    level_(OrthancDatabases::MessagesToolbox::Convert(constraint.level())),
+    level_(MessagesToolbox::Convert(constraint.level())),
     tag_(constraint.tag_group(), constraint.tag_element()),
     isIdentifier_(constraint.is_identifier_tag()),
     caseSensitive_(constraint.is_case_sensitive()),
@@ -276,13 +176,13 @@
       tmpValues[i] = values_[i].c_str();
     }
 
-    constraint.level = Plugins::Convert(level_);
+    constraint.level = MessagesToolbox::ConvertToPlainC(level_);
     constraint.tagGroup = tag_.GetGroup();
     constraint.tagElement = tag_.GetElement();
     constraint.isIdentifierTag = isIdentifier_;
     constraint.isCaseSensitive = caseSensitive_;
     constraint.isMandatory = mandatory_;
-    constraint.type = Plugins::Convert(constraintType_);
+    constraint.type = MessagesToolbox::ConvertToPlainC(constraintType_);
     constraint.valuesCount = values_.size();
     constraint.values = (tmpValues.empty() ? NULL : &tmpValues[0]);
   }
--- a/Framework/Plugins/DatabaseConstraint.h	Mon Sep 09 15:27:52 2024 +0200
+++ b/Framework/Plugins/DatabaseConstraint.h	Mon Sep 09 15:54:14 2024 +0200
@@ -38,31 +38,6 @@
 
 namespace OrthancDatabases
 {
-  enum ConstraintType
-  {
-    ConstraintType_Equal,
-    ConstraintType_SmallerOrEqual,
-    ConstraintType_GreaterOrEqual,
-    ConstraintType_Wildcard,
-    ConstraintType_List
-  };
-
-  namespace Plugins
-  {
-    OrthancPluginResourceType Convert(Orthanc::ResourceType type);
-
-    Orthanc::ResourceType Convert(OrthancPluginResourceType type);
-
-#if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
-    OrthancPluginConstraintType Convert(ConstraintType constraint);
-#endif
-
-#if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
-    ConstraintType Convert(OrthancPluginConstraintType constraint);
-#endif
-  }
-
-
   class DatabaseConstraint : public boost::noncopyable
   {
   private:
--- a/Framework/Plugins/ISqlLookupFormatter.cpp	Mon Sep 09 15:27:52 2024 +0200
+++ b/Framework/Plugins/ISqlLookupFormatter.cpp	Mon Sep 09 15:54:14 2024 +0200
@@ -648,7 +648,7 @@
                                   const Orthanc::DatabasePluginMessages::Find_Request& request)
   {
     const bool escapeBrackets = formatter.IsEscapeBrackets();
-    Orthanc::ResourceType queryLevel = OrthancDatabases::MessagesToolbox::Convert(request.level());
+    Orthanc::ResourceType queryLevel = MessagesToolbox::Convert(request.level());
     const std::string& strQueryLevel = FormatLevel(queryLevel);
 
     DatabaseConstraints constraints;
--- a/Framework/Plugins/IndexBackend.cpp	Mon Sep 09 15:27:52 2024 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Mon Sep 09 15:54:14 2024 +0200
@@ -2158,7 +2158,7 @@
 
     virtual std::string FormatResourceType(Orthanc::ResourceType level)
     {
-      return boost::lexical_cast<std::string>(Plugins::Convert(level));
+      return boost::lexical_cast<std::string>(MessagesToolbox::ConvertToPlainC(level));
     }
 
     virtual std::string FormatWildcardEscape()
@@ -2252,7 +2252,7 @@
                                      bool requestSomeInstance)
   {
     LookupFormatter formatter(manager.GetDialect());
-    Orthanc::ResourceType queryLevel = Plugins::Convert(queryLevel_);
+    Orthanc::ResourceType queryLevel = MessagesToolbox::Convert(queryLevel_);
     Orthanc::ResourceType lowerLevel, upperLevel;
     ISqlLookupFormatter::GetLookupLevels(lowerLevel, upperLevel,  queryLevel, lookup);
 
--- a/Framework/Plugins/MessagesToolbox.cpp	Mon Sep 09 15:27:52 2024 +0200
+++ b/Framework/Plugins/MessagesToolbox.cpp	Mon Sep 09 15:54:14 2024 +0200
@@ -48,5 +48,125 @@
           throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
       }
     }
+
+
+    OrthancPluginResourceType ConvertToPlainC(Orthanc::ResourceType type)
+    {
+      switch (type)
+      {
+        case Orthanc::ResourceType_Patient:
+          return OrthancPluginResourceType_Patient;
+
+        case Orthanc::ResourceType_Study:
+          return OrthancPluginResourceType_Study;
+
+        case Orthanc::ResourceType_Series:
+          return OrthancPluginResourceType_Series;
+
+        case Orthanc::ResourceType_Instance:
+          return OrthancPluginResourceType_Instance;
+
+        default:
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+      }
+    }
+
+
+    Orthanc::ResourceType Convert(OrthancPluginResourceType type)
+    {
+      switch (type)
+      {
+        case OrthancPluginResourceType_Patient:
+          return Orthanc::ResourceType_Patient;
+
+        case OrthancPluginResourceType_Study:
+          return Orthanc::ResourceType_Study;
+
+        case OrthancPluginResourceType_Series:
+          return Orthanc::ResourceType_Series;
+
+        case OrthancPluginResourceType_Instance:
+          return Orthanc::ResourceType_Instance;
+
+        default:
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+      }
+    }
+
+
+#if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
+    OrthancPluginConstraintType ConvertToPlainC(ConstraintType constraint)
+    {
+      switch (constraint)
+      {
+        case ConstraintType_Equal:
+          return OrthancPluginConstraintType_Equal;
+
+        case ConstraintType_GreaterOrEqual:
+          return OrthancPluginConstraintType_GreaterOrEqual;
+
+        case ConstraintType_SmallerOrEqual:
+          return OrthancPluginConstraintType_SmallerOrEqual;
+
+        case ConstraintType_Wildcard:
+          return OrthancPluginConstraintType_Wildcard;
+
+        case ConstraintType_List:
+          return OrthancPluginConstraintType_List;
+
+        default:
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+      }
+    }
+#endif
+
+
+#if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
+    ConstraintType Convert(OrthancPluginConstraintType constraint)
+    {
+      switch (constraint)
+      {
+        case OrthancPluginConstraintType_Equal:
+          return ConstraintType_Equal;
+
+        case OrthancPluginConstraintType_GreaterOrEqual:
+          return ConstraintType_GreaterOrEqual;
+
+        case OrthancPluginConstraintType_SmallerOrEqual:
+          return ConstraintType_SmallerOrEqual;
+
+        case OrthancPluginConstraintType_Wildcard:
+          return ConstraintType_Wildcard;
+
+        case OrthancPluginConstraintType_List:
+          return ConstraintType_List;
+
+        default:
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+      }
+    }
+#endif
+
+
+    Orthanc::DatabasePluginMessages::ResourceType ConvertToProtobuf(OrthancPluginResourceType resourceType)
+    {
+      switch (resourceType)
+      {
+        case OrthancPluginResourceType_Patient:
+          return Orthanc::DatabasePluginMessages::RESOURCE_PATIENT;
+
+        case OrthancPluginResourceType_Study:
+          return Orthanc::DatabasePluginMessages::RESOURCE_STUDY;
+
+        case OrthancPluginResourceType_Series:
+          return Orthanc::DatabasePluginMessages::RESOURCE_SERIES;
+
+        case OrthancPluginResourceType_Instance:
+          return Orthanc::DatabasePluginMessages::RESOURCE_INSTANCE;
+
+        default:
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+      }
+    }
   }
 }
--- a/Framework/Plugins/MessagesToolbox.h	Mon Sep 09 15:27:52 2024 +0200
+++ b/Framework/Plugins/MessagesToolbox.h	Mon Sep 09 15:54:14 2024 +0200
@@ -60,8 +60,29 @@
 
 namespace OrthancDatabases
 {
+  enum ConstraintType
+  {
+    ConstraintType_Equal,
+    ConstraintType_SmallerOrEqual,
+    ConstraintType_GreaterOrEqual,
+    ConstraintType_Wildcard,
+    ConstraintType_List
+  };
+
   namespace MessagesToolbox
   {
     Orthanc::ResourceType Convert(Orthanc::DatabasePluginMessages::ResourceType resourceType);
+
+    OrthancPluginResourceType ConvertToPlainC(Orthanc::ResourceType type);
+
+    Orthanc::ResourceType Convert(OrthancPluginResourceType type);
+
+#if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
+    OrthancPluginConstraintType ConvertToPlainC(ConstraintType constraint);
+#endif
+
+#if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
+    ConstraintType Convert(OrthancPluginConstraintType constraint);
+#endif
   }
 }