Skip to content
Snippets Groups Projects
Commit a37b3e74 authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

ENH: Execute method returns a boolean

parent 4ff66139
Branches
Tags
No related merge requests found
......@@ -108,48 +108,56 @@ void Application::UpdateParameters()
this->DoUpdateParameters();
}
void Application::Execute()
bool Application::Execute()
{
bool ret = true;
try
{
this->DoExecute();
}
catch(std::exception& err)
{
ret = false;
otbAppLogFATAL(<<err.what());
}
catch(...)
{
ret = false;
otbAppLogFATAL(<<"Unknown exception thrown.");
}
return ret;
}
void Application::ExecuteAndWriteOutput()
{
this->Execute();
std::vector<std::string> paramList = GetParametersKeys(true);
for (std::vector<std::string>::const_iterator it = paramList.begin();
it != paramList.end();
++it)
if (this->Execute())
{
std::string key = *it;
if (GetParameterType(key) == ParameterType_OutputImage
&& IsParameterEnabled(key) && HasValue(key) )
std::vector<std::string> paramList = GetParametersKeys(true);
for (std::vector<std::string>::const_iterator it = paramList.begin();
it != paramList.end();
++it)
{
Parameter* param = GetParameterByKey(key);
OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param);
outputParam->InitializeWriters();
AddProcess(outputParam->GetWriter(),"Writer");
outputParam->Write();
}
else if (GetParameterType(key) == ParameterType_OutputVectorData
&& IsParameterEnabled(key) && HasValue(key) )
{
Parameter* param = GetParameterByKey(key);
OutputVectorDataParameter* outputParam = dynamic_cast<OutputVectorDataParameter*>(param);
outputParam->InitializeWriters();
AddProcess(outputParam->GetWriter(),"Writer");
outputParam->Write();
std::string key = *it;
if (GetParameterType(key) == ParameterType_OutputImage
&& IsParameterEnabled(key) && HasValue(key) )
{
Parameter* param = GetParameterByKey(key);
OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param);
outputParam->InitializeWriters();
AddProcess(outputParam->GetWriter(),"Writer");
outputParam->Write();
}
else if (GetParameterType(key) == ParameterType_OutputVectorData
&& IsParameterEnabled(key) && HasValue(key) )
{
Parameter* param = GetParameterByKey(key);
OutputVectorDataParameter* outputParam = dynamic_cast<OutputVectorDataParameter*>(param);
outputParam->InitializeWriters();
AddProcess(outputParam->GetWriter(),"Writer");
outputParam->Write();
}
}
}
}
......
......@@ -82,7 +82,7 @@ public:
*
* In other cases, the application must handle
* the I/O (intermediary results for example) */
void Execute();
bool Execute();
/** Run the application, then writes all the output to disk
* if they have an associated filename.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment