From 4470d241084fb5679cf53e4fc7cea54a1bc6da71 Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Tue, 8 Nov 2011 18:43:18 +0100
Subject: [PATCH] ENH: add methods to get the RAM value set by default in the
 Configuration file

---
 Code/Common/otbConfigurationFile.cxx | 27 +++++++++++++++++++++++++++
 Code/Common/otbConfigurationFile.h   | 10 ++++++++++
 2 files changed, 37 insertions(+)

diff --git a/Code/Common/otbConfigurationFile.cxx b/Code/Common/otbConfigurationFile.cxx
index 349972e92a..5a21bde044 100644
--- a/Code/Common/otbConfigurationFile.cxx
+++ b/Code/Common/otbConfigurationFile.cxx
@@ -139,6 +139,33 @@ ConfigurationFile
   return ret;
 }
 
+itk::uint64_t
+ConfigurationFile
+::GetAvailableRAMInBytes() const
+{
+  itk::uint64_t availableRAMInBytes = 0;
+
+  otbMsgDevMacro(<< "Retrieving available RAM size from configuration");
+  // Retrieve it from the configuration
+  try
+    {
+    typedef otb::ConfigurationFile ConfigurationType;
+    ConfigurationType::Pointer conf = ConfigurationType::GetInstance();
+    
+    availableRAMInBytes = conf->GetParameter< itk::uint64_t >(
+      "OTB_STREAM_MAX_SIZE_BUFFER_FOR_STREAMING");
+    }
+  catch(...)
+    {
+    // We should never have to go here if the configuration file is
+    // correct and found.
+    // In case it is not, fallback on the cmake
+    // defined constants.
+    return OTB_STREAM_MAX_SIZE_BUFFER_FOR_STREAMING;
+    }
+  return availableRAMInBytes;
+}
+
 ConfigurationFile::Pointer
 ConfigurationFile
 ::GetInstance()
diff --git a/Code/Common/otbConfigurationFile.h b/Code/Common/otbConfigurationFile.h
index 35363f2af9..b2a5f1a661 100644
--- a/Code/Common/otbConfigurationFile.h
+++ b/Code/Common/otbConfigurationFile.h
@@ -23,6 +23,7 @@
 #include "itkObject.h"
 #include "itkObjectFactory.h"
 #include "ConfigFile.h"
+#include "itkIntTypes.h"
 
 namespace otb
 {
@@ -79,6 +80,15 @@ public:
   /** Returns the Geoid entry in the config file, or an empty string if not found */
   std::string GetGeoidFile() const;
 
+  /** Returns the available RAM in bytes  */
+  itk::uint64_t GetAvailableRAMInBytes() const;
+
+  /** Returns the available RAM in MBytes*/
+  itk::uint64_t GetAvailableRAMInMBytes() const
+  {
+    return static_cast< itk::uint64_t >(GetAvailableRAMInBytes() / 1024 / 1024);
+  }
+
 protected:
   /** This is protected for the singleton. Use GetInstance() instead. */
   itkNewMacro(Self);
-- 
GitLab