changeset 1275:4287285709d1

new functions for initialization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 21 Jan 2015 17:47:27 +0100
parents b9e2ed59cae4
children 6164f7200c43
files OrthancServer/OrthancInitialization.cpp
diffstat 1 files changed, 46 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/OrthancInitialization.cpp	Wed Jan 21 17:32:53 2015 +0100
+++ b/OrthancServer/OrthancInitialization.cpp	Wed Jan 21 17:47:27 2015 +0100
@@ -186,6 +186,52 @@
   }
 
 
+  static std::string GetStringValue(const Json::Value& configuration,
+                                    const std::string& key,
+                                    const std::string& defaultValue)
+  {
+    if (configuration.type() != Json::objectValue)
+    {
+      throw OrthancException(ErrorCode_BadFileFormat);
+    }
+
+    if (!configuration.isMember(key))
+    {
+      return defaultValue;
+    }
+
+    if (configuration[key].type() != Json::stringValue)
+    {
+      throw OrthancException(ErrorCode_BadFileFormat);
+    }
+
+    return configuration[key].asString();
+  }
+
+
+  static int GetIntegerValue(const Json::Value& configuration,
+                             const std::string& key,
+                             int defaultValue)
+  {
+    if (configuration.type() != Json::objectValue)
+    {
+      throw OrthancException(ErrorCode_BadFileFormat);
+    }
+
+    if (!configuration.isMember(key))
+    {
+      return defaultValue;
+    }
+
+    if (configuration[key].type() != Json::intValue)
+    {
+      throw OrthancException(ErrorCode_BadFileFormat);
+    }
+
+    return configuration[key].asInt();
+  }
+
+
   void OrthancInitialize(const char* configurationFile)
   {
     boost::mutex::scoped_lock lock(globalMutex_);