From 6e4769f95b508b0c923970ed82077906417ab71c Mon Sep 17 00:00:00 2001
From: Stephane ALBERT <stephane.albert@c-s.fr>
Date: Thu, 6 Oct 2016 17:31:44 +0200
Subject: [PATCH] REFAC: Cleaned otb::Wrapper::InputProcessXMLParameter code.

---
 .../otbWrapperInputProcessXMLParameter.cxx    | 42 +++++++++++++------
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx
index fc569c8a8d..448e744727 100644
--- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx
+++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperInputProcessXMLParameter.cxx
@@ -263,12 +263,17 @@ InputProcessXMLParameter::Read(Application::Pointer this_)
     ParameterType type = paramGroup->GetParameterTypeFromString(typeAsString);
 
     Parameter* param = this_->GetParameterByKey(key);
-    bool updateFromXML = true;
 
-    if(param->HasUserValue())
-      updateFromXML = false;
+    // std::cout
+    //   << "'" << paramName << "'\t"
+    //   << key << "\t"
+    //   << typeAsString << "\t"
+    //   << type << "\t"
+    //   << ParameterType_OutputImage << "\t"
+    //   << param->HasUserValue() << "\t"
+    //   << value << std::endl;
 
-    if(updateFromXML)
+    if( !param->HasUserValue() )
       {
       param->SetUserValue(true);
       param->SetActive(true);
@@ -289,16 +294,27 @@ InputProcessXMLParameter::Read(Application::Pointer this_)
         {
         this_->SetParameterString(key, value);
         }
-      else if (type == ParameterType_OutputImage)
+      else if( type == ParameterType_OutputImage )
         {
-        OutputImageParameter *paramDown = dynamic_cast<OutputImageParameter*>(param);
-        if(paramDown!=ITK_NULLPTR)
-          {
-          paramDown->SetFileName(value);
-          std::string pixTypeAsString  = GetChildNodeTextOf(n_Parameter, "pixtype");
-          ImagePixelType outPixType = GetPixelTypeFromString(pixTypeAsString);
-          paramDown->SetPixelType(outPixType);
-          }
+	assert( dynamic_cast< OutputImageParameter * >( param )==param );
+
+        OutputImageParameter * outImageParam =
+	  dynamic_cast< OutputImageParameter * >( param );
+
+	assert( outImageParam!=ITK_NULLPTR );
+
+	outImageParam->SetFileName( value );
+
+	std::string pixelType(
+	  GetChildNodeTextOf(n_Parameter, "pixtype" )
+	);
+
+	if( pixelType.empty() )
+	  std::runtime_error( "Invalid pixel type (empty string)." );
+
+	outImageParam->SetPixelType(
+	  GetPixelTypeFromString( pixelType )
+	);
         }
       else if (type == ParameterType_ComplexOutputImage)
         {
-- 
GitLab