# HG changeset patch # User Sebastien Jodogne # Date 1486564040 -3600 # Node ID b9775db0fd9b1f26ee76aeb6786620e32db2f7ce # Parent 6d425452247edca39ba18c8eb1a44d83840fdb18 OrthancPlugins::OrthancConfiguration::LookupListOfStrings diff -r 6d425452247e -r b9775db0fd9b Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- 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& 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 diff -r 6d425452247e -r b9775db0fd9b Plugins/Samples/Common/OrthancPluginCppWrapper.h --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Fri Feb 03 09:41:05 2017 +0000 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Wed Feb 08 15:27:20 2017 +0100 @@ -39,6 +39,7 @@ #include #include #include +#include #if (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER >= 2 || \ @@ -232,6 +233,9 @@ bool LookupFloatValue(float& target, const std::string& key) const; + bool LookupListOfStrings(std::list& target, + const std::string& key) const; + std::string GetStringValue(const std::string& key, const std::string& defaultValue) const;