comparison Plugins/Samples/Common/SimplifiedOrthancDataset.cpp @ 2180:71b8bec8ca91

improvements
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 Nov 2016 17:00:39 +0100
parents de32f3b4ff09
children 403d92d8df83
comparison
equal deleted inserted replaced
2179:de32f3b4ff09 2180:71b8bec8ca91
32 32
33 #include "SimplifiedOrthancDataset.h" 33 #include "SimplifiedOrthancDataset.h"
34 34
35 #include "OrthancPluginCppWrapper.h" 35 #include "OrthancPluginCppWrapper.h"
36 36
37 #include <json/reader.h>
38
39 namespace OrthancPlugins 37 namespace OrthancPlugins
40 { 38 {
41 void SimplifiedOrthancDataset::Parse(const std::string& source)
42 {
43 Json::Reader reader;
44
45 if (!reader.parse(source, root_) ||
46 root_.type() != Json::objectValue)
47 {
48 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
49 }
50 }
51
52
53 const Json::Value* SimplifiedOrthancDataset::LookupPath(const DicomPath& path) const 39 const Json::Value* SimplifiedOrthancDataset::LookupPath(const DicomPath& path) const
54 { 40 {
55 const Json::Value* content = &root_; 41 const Json::Value* content = &root_;
56 42
57 for (unsigned int depth = 0; depth < path.GetPrefixLength(); depth++) 43 for (unsigned int depth = 0; depth < path.GetPrefixLength(); depth++)
99 return &((*content) [name]); 85 return &((*content) [name]);
100 } 86 }
101 } 87 }
102 88
103 89
90 void SimplifiedOrthancDataset::CheckRoot() const
91 {
92 if (root_.type() != Json::objectValue)
93 {
94 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
95 }
96 }
97
98
104 SimplifiedOrthancDataset::SimplifiedOrthancDataset(IOrthancConnection& orthanc, 99 SimplifiedOrthancDataset::SimplifiedOrthancDataset(IOrthancConnection& orthanc,
105 const std::string& uri) 100 const std::string& uri)
106 { 101 {
107 std::string content; 102 IOrthancConnection::RestApiGet(root_, orthanc, uri);
108 orthanc.RestApiGet(content, uri); 103 CheckRoot();
109 Parse(content); 104 }
105
106
107 SimplifiedOrthancDataset::SimplifiedOrthancDataset(const std::string& content)
108 {
109 IOrthancConnection::ParseJson(root_, content);
110 CheckRoot();
110 } 111 }
111 112
112 113
113 bool SimplifiedOrthancDataset::GetStringValue(std::string& result, 114 bool SimplifiedOrthancDataset::GetStringValue(std::string& result,
114 const DicomPath& path) const 115 const DicomPath& path) const