changeset 507:46fff4855a64

compatibility with older versions of the Orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 31 Aug 2021 15:07:25 +0200
parents 770c28870925
children f5b64f680bfb 9154d738f5bf
files Plugin/WadoRsRetrieveRendered.cpp
diffstat 1 files changed, 62 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Plugin/WadoRsRetrieveRendered.cpp	Tue Aug 31 14:52:41 2021 +0200
+++ b/Plugin/WadoRsRetrieveRendered.cpp	Tue Aug 31 15:07:25 2021 +0200
@@ -26,13 +26,70 @@
 #include <Images/ImageProcessing.h>
 #include <Images/ImageTraits.h>
 #include <Logging.h>
-#include <SerializationToolbox.h>
 #include <Toolbox.h>
 
+#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 7)
+#  include <SerializationToolbox.h>
+#else
+#  include <boost/lexical_cast.hpp>
+#endif
+
 #include <boost/algorithm/string/predicate.hpp>
 #include <boost/math/special_functions/round.hpp>
 
 
+static bool ParseFloat(float& target,
+                       const std::string& source)
+{
+#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 7)
+  return Orthanc::SerializationToolbox::ParseFloat(target, source);
+
+#else
+  // Emulation for older versions of the Orthanc framework
+  std::string s = Orthanc::Toolbox::StripSpaces(source);
+  
+  if (s.empty())
+  {
+    return false;
+  }
+  else
+  {
+    try
+    {
+      target = boost::lexical_cast<float>(s);
+      return true;
+    }
+    catch (boost::bad_lexical_cast&)
+    {
+      return false;
+    }
+  }
+#endif
+}
+
+
+static bool ParseFirstFloat(float& target,
+                            const std::string& source)
+{
+#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 7)
+  return Orthanc::SerializationToolbox::ParseFirstFloat(target, source);
+
+#else
+  // Emulation for older versions of the Orthanc framework
+  std::vector<std::string> tokens;
+  Orthanc::Toolbox::TokenizeString(tokens, source, '\\');
+  if (tokens.empty())
+  {
+    return false;
+  }
+  else
+  {
+    return ParseFloat(target, tokens[0]);
+  }
+#endif
+}
+
+
 namespace
 {
   enum WindowingMode
@@ -722,8 +779,8 @@
   {
     float s, i;
 
-    if (Orthanc::SerializationToolbox::ParseFloat(s, tags[RESCALE_SLOPE].asString()) &&
-        Orthanc::SerializationToolbox::ParseFloat(i, tags[RESCALE_INTERCEPT].asString()))
+    if (ParseFloat(s, tags[RESCALE_SLOPE].asString()) &&
+        ParseFloat(i, tags[RESCALE_INTERCEPT].asString()))
     {
       parameters.SetRescaleSlope(s);
       parameters.SetRescaleIntercept(i);
@@ -749,8 +806,8 @@
   {
     float wc, ww;
 
-    if (Orthanc::SerializationToolbox::ParseFirstFloat(wc, tags[WINDOW_CENTER].asString()) &&
-        Orthanc::SerializationToolbox::ParseFirstFloat(ww, tags[WINDOW_WIDTH].asString()))
+    if (ParseFirstFloat(wc, tags[WINDOW_CENTER].asString()) &&
+        ParseFirstFloat(ww, tags[WINDOW_WIDTH].asString()))
     {
       parameters.SetWindow(wc, ww);
       return true;