comparison OrthancStone/Sources/Toolbox/OrthancDatasets/IOrthancConnection.cpp @ 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 3889ae96d2e9
comparison
equal deleted inserted replaced
1739:9ac2a65d4172 1740:84d1402c98fe
23 #include "IOrthancConnection.h" 23 #include "IOrthancConnection.h"
24 24
25 #include <OrthancException.h> 25 #include <OrthancException.h>
26 #include <Toolbox.h> 26 #include <Toolbox.h>
27 27
28 #if !defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE)
29 # error You are using a version of the Orthanc framework that is too old
30 #endif
31
32 #if !ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
33 # include <json/reader.h>
34 #endif
35
36
28 namespace OrthancStone 37 namespace OrthancStone
29 { 38 {
30 void IOrthancConnection::ParseJson(Json::Value& result, 39 void IOrthancConnection::ParseJson(Json::Value& result,
31 const std::string& content) 40 const std::string& content)
32 { 41 {
33 if (!Orthanc::Toolbox::ReadJson(result, content)) 42 bool ok;
43
44 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
45 ok = Orthanc::Toolbox::ReadJson(result, content);
46 #else
47 // Backward compatibility (for use in orthanc-wsi 1.0)
48 Json::Reader reader;
49 ok = reader.parse(content, result);
50 #endif
51
52 if (!ok)
34 { 53 {
35 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); 54 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
36 } 55 }
37 } 56 }
38 57
39 58
40 void IOrthancConnection::ParseJson(Json::Value& result, 59 void IOrthancConnection::ParseJson(Json::Value& result,
41 const void* content, 60 const void* content,
42 size_t size) 61 size_t size)
43 { 62 {
44 if (!Orthanc::Toolbox::ReadJson(result, content, size)) 63 bool ok;
64
65 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
66 ok = Orthanc::Toolbox::ReadJson(result, content, size);
67 #else
68 // Backward compatibility (for use in orthanc-wsi 1.0)
69 Json::Reader reader;
70 ok = reader.parse(reinterpret_cast<const char*>(content),
71 reinterpret_cast<const char*>(content) + size, result);
72 #endif
73
74 if (!ok)
45 { 75 {
46 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); 76 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
47 } 77 }
48 } 78 }
49 79