diff Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 2803:579acc5e5412

OrthancConfiguration::GetDictionary
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 28 Aug 2018 15:14:33 +0200
parents 4df3c64402ba
children 473bf302d629
line wrap: on
line diff
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Thu Aug 23 18:52:14 2018 +0200
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Tue Aug 28 15:14:33 2018 +0200
@@ -779,6 +779,53 @@
   }
 
 
+  void OrthancConfiguration::GetDictionary(std::map<std::string, std::string>& target,
+                                           const std::string& key) const
+  {
+    assert(configuration_.type() == Json::objectValue);
+
+    target.clear();
+
+    if (!configuration_.isMember(key))
+    {
+      return;
+    }
+
+    if (configuration_[key].type() != Json::objectValue)
+    {
+      if (context_ != NULL)
+      {
+        std::string s = "The configuration option \"" + GetPath(key) + "\" is not a string as expected";
+        OrthancPluginLogError(context_, s.c_str());
+      }
+
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
+    }
+
+    Json::Value::Members members = configuration_[key].getMemberNames();
+
+    for (size_t i = 0; i < members.size(); i++)
+    {
+      const Json::Value& value = configuration_[key][members[i]];
+
+      if (value.type() == Json::stringValue)
+      {
+        target[members[i]] = value.asString();
+      }
+      else
+      {
+        if (context_ != NULL)
+        {
+          std::string s = "The configuration option \"" + GetPath(key) + "\" is not a dictionary mapping strings to strings";
+          OrthancPluginLogError(context_, s.c_str());
+        }
+
+        ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
+      }
+    }
+  }
+
+
   void OrthancImage::Clear()
   {
     if (image_ != NULL)