changeset 2265:e46b0ee6c19d

allowSingleString in OrthancConfiguration::LookupListOfStrings
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 14 Feb 2017 15:59:19 +0100
parents 8e5e0de75839
children a344e47e9c9a
files Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h
diffstat 2 files changed, 40 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- 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<std::string>& 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);
   }
 
   
--- 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<std::string>& 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;