changeset 2263:b9775db0fd9b

OrthancPlugins::OrthancConfiguration::LookupListOfStrings
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 Feb 2017 15:27:20 +0100
parents 6d425452247e
children 8e5e0de75839
files Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h
diffstat 2 files changed, 55 insertions(+), 0 deletions(-) [+]
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
--- 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 <boost/noncopyable.hpp>
 #include <boost/lexical_cast.hpp>
 #include <json/value.h>
+#include <list>
 
 
 #if (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER >= 2 ||   \
@@ -232,6 +233,9 @@
     bool LookupFloatValue(float& target,
                           const std::string& key) const;
 
+    bool LookupListOfStrings(std::list<std::string>& target,
+                             const std::string& key) const;
+
     std::string GetStringValue(const std::string& key,
                                const std::string& defaultValue) const;