Mercurial > hg > orthanc
changeset 2803:579acc5e5412
OrthancConfiguration::GetDictionary
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 28 Aug 2018 15:14:33 +0200 |
parents | c48ddc902e3e |
children | d88970f1ffbf |
files | Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h |
diffstat | 2 files changed, 51 insertions(+), 0 deletions(-) [+] |
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)
--- 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 <json/value.h> #include <list> #include <set> +#include <map> @@ -285,6 +286,9 @@ float GetFloatValue(const std::string& key, float defaultValue) const; + + void GetDictionary(std::map<std::string, std::string>& target, + const std::string& key) const; }; class OrthancImage : public boost::noncopyable