# HG changeset patch # User Sebastien Jodogne # Date 1487084359 -3600 # Node ID e46b0ee6c19de2e2633798ec41ff7dd02287e849 # Parent 8e5e0de758394a92bfac84d57f902b2579b9351d allowSingleString in OrthancConfiguration::LookupListOfStrings diff -r 8e5e0de75839 -r e46b0ee6c19d Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Mon Feb 13 10:39:14 2017 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Tue Feb 14 15:59:19 2017 +0100 @@ -598,7 +598,8 @@ bool OrthancConfiguration::LookupListOfStrings(std::list& target, - const std::string& key) const + const std::string& key, + bool allowSingleString) const { assert(configuration_.type() == Json::objectValue); @@ -609,42 +610,53 @@ return false; } - bool ok = true; - - if (configuration_[key].type() != Json::arrayValue) + switch (configuration_[key].type()) { - ok = false; - } - else - { - for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) + case Json::arrayValue: { - if (configuration_[key][i].type() == Json::stringValue) + bool ok = true; + + for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) { - target.push_back(configuration_[key][i].asString()); + if (configuration_[key][i].type() == Json::stringValue) + { + target.push_back(configuration_[key][i].asString()); + } + else + { + ok = false; + } } - else + + if (ok) { - ok = false; + return true; } + + break; } + + case Json::stringValue: + if (allowSingleString) + { + target.push_back(configuration_[key].asString()); + return true; + } + + break; + + default: + break; } - if (ok) - { - return true; - } - else + if (context_ != NULL) { - if (context_ != NULL) - { - std::string s = ("The configuration option \"" + GetPath(key) + - "\" is not a list of strings as expected"); - OrthancPluginLogError(context_, s.c_str()); - } + 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); - } + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); } diff -r 8e5e0de75839 -r e46b0ee6c19d Plugins/Samples/Common/OrthancPluginCppWrapper.h --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Mon Feb 13 10:39:14 2017 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Tue Feb 14 15:59:19 2017 +0100 @@ -250,7 +250,8 @@ const std::string& key) const; bool LookupListOfStrings(std::list& target, - const std::string& key) const; + const std::string& key, + bool allowSingleString) const; std::string GetStringValue(const std::string& key, const std::string& defaultValue) const;