Commit d8bf6cae authored by Julien Michel's avatar Julien Michel
Browse files

ENH: Adressing comments from @poughov, with a bit of C++11 seasoning

No related merge requests found
Showing with 52 additions and 24 deletions
+52 -24
...@@ -168,7 +168,16 @@ protected: ...@@ -168,7 +168,16 @@ protected:
unsigned int GetMaxKeySize() const; unsigned int GetMaxKeySize() const;
private: private:
/** \return false if paramKey is a missing mandatory parameter */
bool CheckMissingMandatoryParameter(const std::string & paramKey) const;
/** Prints a warning to std::cerr if paramKey is an unused parameter */
void CheckUnusedParameter(const std::string & paramKey) const;
/** \return false if paramKey is an OutputFilename parameter
pointing to a path that does not exist */
bool CheckOutputPathsValidity(const std::string & paramKey) const;
CommandLineLauncher(const CommandLineLauncher &) = delete; CommandLineLauncher(const CommandLineLauncher &) = delete;
void operator =(const CommandLineLauncher&) = delete; void operator =(const CommandLineLauncher&) = delete;
......
...@@ -511,18 +511,54 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() ...@@ -511,18 +511,54 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
} }
} }
// SECOND PASS : check mandatory parameters // SECOND PASS : checks
for (unsigned int i = 0; i < appKeyList.size(); i++) for (const auto & paramKey : appKeyList)
{ {
const std::string paramKey(appKeyList[i]); // Check for missing mandatory parameters
ParameterType type = m_Application->GetParameterType(paramKey); if(!CheckMissingMandatoryParameter(paramKey))
return MISSINGMANDATORYPARAMETER;
// Check and warn unused parameters
CheckUnusedParameter(paramKey);
// Check output paths are valid
if(!CheckOutputPathsValidity(paramKey))
return WRONGPARAMETERVALUE;
}
return OKPARAM;
}
bool CommandLineLauncher::CheckOutputPathsValidity(const std::string & paramKey) const
{
ParameterType type = m_Application->GetParameterType(paramKey);
if (m_Application->HasValue(paramKey) &&
type == ParameterType_OutputFilename)
{
std::string filename = m_Application->GetParameterString(paramKey);
itksys::String path = itksys::SystemTools::GetFilenamePath(filename);
if (path!="" && !itksys::SystemTools::FileIsDirectory(path.c_str()))
{
std::cerr <<"ERROR: Directory doesn't exist : "<< path.c_str() << std::endl;
return false;
}
}
return true;
}
bool CommandLineLauncher::CheckMissingMandatoryParameter(const std::string & paramKey) const
{
if (m_Application->IsParameterMissing(paramKey)) if (m_Application->IsParameterMissing(paramKey))
{ {
std::cerr << "ERROR: Missing mandatory parameter -" << paramKey << "." << std::endl; std::cerr << "ERROR: Missing mandatory parameter -" << paramKey << "." << std::endl;
return MISSINGMANDATORYPARAMETER; return true;
} }
return false;
}
// Check for ignored parameters void CommandLineLauncher::CheckUnusedParameter(const std::string & paramKey) const
{
// Check for ignored parameters
if(m_Application->HasUserValue(paramKey)) if(m_Application->HasUserValue(paramKey))
{ {
...@@ -551,30 +587,13 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() ...@@ -551,30 +587,13 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
// Check that this choice is active // Check that this choice is active
if(paramKey.find(value) == std::string::npos) if(paramKey.find(value) == std::string::npos)
{ {
const std::string & missingMode = paramKey.substr(start,end-start); std::cerr<<"WARNING: Parameter -"<<paramKey<<" will be ignored because -"<<key<<" is "<<value<<"."<<std::endl;
std::cerr<<"WARNING: Parameter -"<<paramKey<<" will be ignored because -"<<key<<" is "<<value<<". Consider adding -"<<key<<" "<<missingMode<<" to application parameters."<<std::endl;
break; break;
} }
} }
} }
} }
// Check output paths validity
if (m_Application->HasValue(paramKey) &&
type == ParameterType_OutputFilename)
{
std::string filename = m_Application->GetParameterString(paramKey);
itksys::String path = itksys::SystemTools::GetFilenamePath(filename);
if (path!="" && !itksys::SystemTools::FileIsDirectory(path.c_str()))
{
std::cerr <<"ERROR: Directory doesn't exist : "<< path.c_str() << std::endl;
return WRONGPARAMETERVALUE;
}
}
}
return OKPARAM;
} }
void CommandLineLauncher::LinkWatchers(itk::Object * itkNotUsed(caller), const itk::EventObject & event) void CommandLineLauncher::LinkWatchers(itk::Object * itkNotUsed(caller), const itk::EventObject & event)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment