# HG changeset patch # User Sebastien Jodogne # Date 1535462073 -7200 # Node ID 579acc5e5412cb5de740eea796276188e512c595 # Parent c48ddc902e3e73abd145f2401b6565c92df31ea7 OrthancConfiguration::GetDictionary diff -r c48ddc902e3e -r 579acc5e5412 Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- 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& 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) diff -r c48ddc902e3e -r 579acc5e5412 Plugins/Samples/Common/OrthancPluginCppWrapper.h --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Thu Aug 23 18:52:14 2018 +0200 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Tue Aug 28 15:14:33 2018 +0200 @@ -41,6 +41,7 @@ #include #include #include +#include @@ -285,6 +286,9 @@ float GetFloatValue(const std::string& key, float defaultValue) const; + + void GetDictionary(std::map& target, + const std::string& key) const; }; class OrthancImage : public boost::noncopyable