Commit 5dcce21b authored by Julien Michel's avatar Julien Michel
Browse files

STY: Replace class member m_MaxKeySize with const method GetMaxKeySize()

No related merge requests found
Showing with 31 additions and 26 deletions
+31 -26
...@@ -164,6 +164,8 @@ protected: ...@@ -164,6 +164,8 @@ protected:
/** Clear watcher list, deleting its pointers. */ /** Clear watcher list, deleting its pointers. */
void DeleteWatcherList(); void DeleteWatcherList();
/** Returns the width of the longest key (in number of chars) */
unsigned int GetMaxKeySize() const;
private: private:
...@@ -184,7 +186,6 @@ private: ...@@ -184,7 +186,6 @@ private:
AddProcessCommandType::Pointer m_AddProcessCommand; AddProcessCommandType::Pointer m_AddProcessCommand;
bool m_ReportProgress; bool m_ReportProgress;
unsigned int m_MaxKeySize;
}; //end class }; //end class
} // end namespace Wrapper } // end namespace Wrapper
......
...@@ -55,7 +55,7 @@ namespace Wrapper ...@@ -55,7 +55,7 @@ namespace Wrapper
{ {
CommandLineLauncher::CommandLineLauncher() : 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_Application = ITK_NULLPTR;
m_Parser = CommandLineParser::New(); m_Parser = CommandLineParser::New();
...@@ -206,17 +206,7 @@ bool CommandLineLauncher::BeforeExecute() ...@@ -206,17 +206,7 @@ bool CommandLineLauncher::BeforeExecute()
} }
else 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) for(std::vector<std::string>::const_iterator it = val.begin(); it!=val.end();++it)
{ {
...@@ -752,24 +742,16 @@ void CommandLineLauncher::DisplayHelp(bool longHelp) ...@@ -752,24 +742,16 @@ void CommandLineLauncher::DisplayHelp(bool longHelp)
const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true); const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
const unsigned int nbOfParam = appKeyList.size(); const unsigned int nbOfParam = appKeyList.size();
m_MaxKeySize = std::string("progress").size(); unsigned int maxKeySize = GetMaxKeySize();
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();
}
}
//// progress report parameter //// progress report parameter
std::string bigKey = "progress"; 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(" "); bigKey.append(" ");
std::cerr << " -"<<bigKey<<" <boolean> Report progress " << std::endl; std::cerr << " -"<<bigKey<<" <boolean> Report progress " << std::endl;
bigKey = "help"; 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(" "); bigKey.append(" ");
std::cerr << " -"<<bigKey<<" <string list> Display long help (empty list), or help for given parameters keys" << std::endl; 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 & ...@@ -886,7 +868,10 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer &
} }
std::string bigKey = paramKey; 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(" "); bigKey.append(" ");
oss<< "-" << bigKey << " "; oss<< "-" << bigKey << " ";
...@@ -996,7 +981,7 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer & ...@@ -996,7 +981,7 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer &
if(longHelp) if(longHelp)
{ {
oss << " "; oss << " ";
for(unsigned int i=0; i<m_MaxKeySize;++i) for(unsigned int i=0; i<maxKeySize;++i)
oss<<" "; oss<<" ";
oss<<" "; oss<<" ";
oss<<m_Application->GetParameterDescription(paramKey)<<std::endl; oss<<m_Application->GetParameterDescription(paramKey)<<std::endl;
...@@ -1120,5 +1105,24 @@ void CommandLineLauncher::DisplayOutputParameters() ...@@ -1120,5 +1105,24 @@ void CommandLineLauncher::DisplayOutputParameters()
std::cout << oss.str() << std::endl; 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;
}
} }
} }
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