diff --git a/Modules/Wrappers/CommandLine/include/otbWrapperCommandLineLauncher.h b/Modules/Wrappers/CommandLine/include/otbWrapperCommandLineLauncher.h index 50c39f6cd5baf4c254b32f1ca9a585750893c2c3..a7869e4842741e315d4adac5eb8d0e24972bf07e 100644 --- a/Modules/Wrappers/CommandLine/include/otbWrapperCommandLineLauncher.h +++ b/Modules/Wrappers/CommandLine/include/otbWrapperCommandLineLauncher.h @@ -164,6 +164,8 @@ protected: /** Clear watcher list, deleting its pointers. */ void DeleteWatcherList(); + /** Returns the width of the longest key (in number of chars) */ + unsigned int GetMaxKeySize() const; private: @@ -184,7 +186,6 @@ private: AddProcessCommandType::Pointer m_AddProcessCommand; bool m_ReportProgress; - unsigned int m_MaxKeySize; }; //end class } // end namespace Wrapper diff --git a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx index 876c2e008769439b22274584b2cce742df86ea31..4be16ba228f5c27a3ad114f77609d011038a72e2 100644 --- a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx +++ b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx @@ -55,7 +55,7 @@ namespace Wrapper { CommandLineLauncher::CommandLineLauncher() : - /*m_Expression(""),*/m_VExpression(), m_WatcherList(), m_ReportProgress(true), m_MaxKeySize(0) + /*m_Expression(""),*/m_VExpression(), m_WatcherList(), m_ReportProgress(true) { m_Application = ITK_NULLPTR; m_Parser = CommandLineParser::New(); @@ -206,17 +206,7 @@ bool CommandLineLauncher::BeforeExecute() } else { - const unsigned int nbOfParam = appKeyList.size(); - - m_MaxKeySize = std::string("progress").size(); - for (unsigned int i = 0; i < nbOfParam; i++) - { - if (m_Application->GetParameterRole(appKeyList[i]) != Role_Output) - { - if( m_MaxKeySize < appKeyList[i].size() ) - m_MaxKeySize = appKeyList[i].size(); - } - } + for(std::vector<std::string>::const_iterator it = val.begin(); it!=val.end();++it) { @@ -752,24 +742,16 @@ void CommandLineLauncher::DisplayHelp(bool longHelp) const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true); const unsigned int nbOfParam = appKeyList.size(); - m_MaxKeySize = std::string("progress").size(); - for (unsigned int i = 0; i < nbOfParam; i++) - { - if (m_Application->GetParameterRole(appKeyList[i]) != Role_Output) - { - if( m_MaxKeySize < appKeyList[i].size() ) - m_MaxKeySize = appKeyList[i].size(); - } - } + unsigned int maxKeySize = GetMaxKeySize(); //// progress report parameter std::string bigKey = "progress"; - for(unsigned int i=0; i<m_MaxKeySize-std::string("progress").size(); i++) + for(unsigned int i=0; i<maxKeySize-std::string("progress").size(); i++) bigKey.append(" "); std::cerr << " -"<<bigKey<<" <boolean> Report progress " << std::endl; bigKey = "help"; - for(unsigned int i=0; i<m_MaxKeySize-std::string("help").size(); i++) + for(unsigned int i=0; i<maxKeySize-std::string("help").size(); i++) bigKey.append(" "); std::cerr << " -"<<bigKey<<" <string list> Display long help (empty list), or help for given parameters keys" << std::endl; @@ -886,7 +868,10 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer & } std::string bigKey = paramKey; - for(unsigned int i=0; i<m_MaxKeySize-paramKey.size(); i++) + + unsigned int maxKeySize = GetMaxKeySize(); + + for(unsigned int i=0; i<maxKeySize-paramKey.size(); i++) bigKey.append(" "); oss<< "-" << bigKey << " "; @@ -996,7 +981,7 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer & if(longHelp) { oss << " "; - for(unsigned int i=0; i<m_MaxKeySize;++i) + for(unsigned int i=0; i<maxKeySize;++i) oss<<" "; oss<<" "; oss<<m_Application->GetParameterDescription(paramKey)<<std::endl; @@ -1120,5 +1105,24 @@ void CommandLineLauncher::DisplayOutputParameters() std::cout << oss.str() << std::endl; } +unsigned int CommandLineLauncher::GetMaxKeySize() const +{ + const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true); + const unsigned int nbOfParam = appKeyList.size(); + + unsigned int maxKeySize = std::string("progress").size(); + + for (unsigned int i = 0; i < nbOfParam; i++) + { + if (m_Application->GetParameterRole(appKeyList[i]) != Role_Output) + { + if( maxKeySize < appKeyList[i].size() ) + maxKeySize = appKeyList[i].size(); + } + } + + return maxKeySize; +} + } }