Mercurial > hg > orthanc
diff Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 2263:b9775db0fd9b
OrthancPlugins::OrthancConfiguration::LookupListOfStrings
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 08 Feb 2017 15:27:20 +0100 |
parents | a3a65de1840f |
children | 8e5e0de75839 |
line wrap: on
line diff
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Fri Feb 03 09:41:05 2017 +0000 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Wed Feb 08 15:27:20 2017 +0100 @@ -557,6 +557,57 @@ } } + + bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target, + const std::string& key) const + { + assert(configuration_.type() == Json::objectValue); + + target.clear(); + + if (!configuration_.isMember(key)) + { + return false; + } + + bool ok = true; + + if (configuration_[key].type() != Json::arrayValue) + { + ok = false; + } + else + { + for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) + { + if (configuration_[key][i].type() == Json::stringValue) + { + target.push_back(configuration_[key][i].asString()); + } + else + { + ok = false; + } + } + } + + if (ok) + { + return true; + } + else + { + if (context_ != NULL) + { + std::string s = ("The configuration option \"" + GetPath(key) + + "\" is not a list of strings as expected"); + OrthancPluginLogError(context_, s.c_str()); + } + + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + } + std::string OrthancConfiguration::GetStringValue(const std::string& key, const std::string& defaultValue) const