changeset 1740:84d1402c98fe

backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 13 Jan 2021 09:07:57 +0100
parents 9ac2a65d4172
children 62377949e739
files OrthancStone/Sources/Toolbox/OrthancDatasets/IOrthancConnection.cpp
diffstat 1 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Sources/Toolbox/OrthancDatasets/IOrthancConnection.cpp	Wed Jan 06 17:50:00 2021 +0100
+++ b/OrthancStone/Sources/Toolbox/OrthancDatasets/IOrthancConnection.cpp	Wed Jan 13 09:07:57 2021 +0100
@@ -25,12 +25,31 @@
 #include <OrthancException.h>
 #include <Toolbox.h>
 
+#if !defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE)
+#  error You are using a version of the Orthanc framework that is too old
+#endif
+
+#if !ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
+#  include <json/reader.h>
+#endif
+
+
 namespace OrthancStone
 {
   void IOrthancConnection::ParseJson(Json::Value& result,
                                      const std::string& content)
   {
-    if (!Orthanc::Toolbox::ReadJson(result, content))
+    bool ok;
+    
+#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
+    ok = Orthanc::Toolbox::ReadJson(result, content);
+#else
+    // Backward compatibility (for use in orthanc-wsi 1.0)
+    Json::Reader reader;
+    ok = reader.parse(content, result);
+#endif
+
+    if (!ok)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
     }
@@ -41,7 +60,18 @@
                                      const void* content,
                                      size_t size)
   {
-    if (!Orthanc::Toolbox::ReadJson(result, content, size))
+    bool ok;
+
+#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
+    ok = Orthanc::Toolbox::ReadJson(result, content, size);
+#else
+    // Backward compatibility (for use in orthanc-wsi 1.0)
+    Json::Reader reader;
+    ok = reader.parse(reinterpret_cast<const char*>(content),
+                      reinterpret_cast<const char*>(content) + size, result);
+#endif
+    
+    if (!ok)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
     }