Commit 614501e1 authored by Mickael Savinaud's avatar Mickael Savinaud
Browse files

WIP

No related merge requests found
Showing with 242 additions and 42 deletions
+242 -42
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "otbWrapperCommandLineLauncher.h" #include "otbWrapperCommandLineLauncher.h"
#include "otbTinyXML.h" #include "otbTinyXML.h"
#include <vector>
const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key); const std::string GetChildNodeTextOf(TiXmlElement *parentElement, std::string key);
std::string PrepareExpressionFromXML(std::string filename); std::string PrepareExpressionFromXML(std::string filename);
...@@ -153,6 +154,8 @@ int main(int argc, char* argv[]) ...@@ -153,6 +154,8 @@ int main(int argc, char* argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
std::vector<std::string> vexp;
std::string exp; std::string exp;
if (strcmp(argv[1], "-inxml") == 0) if (strcmp(argv[1], "-inxml") == 0)
{ {
...@@ -163,7 +166,7 @@ int main(int argc, char* argv[]) ...@@ -163,7 +166,7 @@ int main(int argc, char* argv[])
// Construct the string expression // Construct the string expression
for (int i = 1; i < argc; i++) for (int i = 1; i < argc; i++)
{ {
if (i != argc - 1) /*if (i != argc - 1)
{ {
exp.append(argv[i]); exp.append(argv[i]);
exp.append(" "); exp.append(" ");
...@@ -171,16 +174,19 @@ int main(int argc, char* argv[]) ...@@ -171,16 +174,19 @@ int main(int argc, char* argv[])
else else
{ {
exp.append(argv[i]); exp.append(argv[i]);
} }*/
std::string strarg (argv[i]);
std::cout << strarg << std::endl;
vexp.push_back(strarg);
} }
} }
// std::cerr << exp << ":\n"; // std::cerr << exp << ":\n";
typedef otb::Wrapper::CommandLineLauncher LauncherType; typedef otb::Wrapper::CommandLineLauncher LauncherType;
LauncherType::Pointer launcher = LauncherType::New(); LauncherType::Pointer launcher = LauncherType::New();
if (launcher->Load(exp) == true) //if (launcher->Load(exp) == true)
if (launcher->Load(vexp) == true)
{ {
if (launcher->ExecuteAndWriteOutput() == false) if (launcher->ExecuteAndWriteOutput() == false)
{ {
......
...@@ -58,7 +58,7 @@ namespace Wrapper ...@@ -58,7 +58,7 @@ namespace Wrapper
{ {
CommandLineLauncher::CommandLineLauncher() : CommandLineLauncher::CommandLineLauncher() :
m_Expression(""), m_WatcherList(), m_ReportProgress(true), m_MaxKeySize(0) /*m_Expression(""),*/ m_WatcherList(), m_ReportProgress(true), m_MaxKeySize(0),m_VExpression()
{ {
m_Application = NULL; m_Application = NULL;
m_Parser = CommandLineParser::New(); m_Parser = CommandLineParser::New();
...@@ -70,8 +70,8 @@ CommandLineLauncher::CommandLineLauncher() : ...@@ -70,8 +70,8 @@ CommandLineLauncher::CommandLineLauncher() :
m_AddProcessCommand->SetCallbackFunction(this, &CommandLineLauncher::LinkWatchers); m_AddProcessCommand->SetCallbackFunction(this, &CommandLineLauncher::LinkWatchers);
} }
CommandLineLauncher::CommandLineLauncher(const char * exp) : CommandLineLauncher::CommandLineLauncher(const char * exp) /*:
m_Expression(exp) m_Expression(exp)*/
{ {
m_Application = NULL; m_Application = NULL;
m_Parser = CommandLineParser::New(); m_Parser = CommandLineParser::New();
...@@ -94,15 +94,23 @@ void CommandLineLauncher::DeleteWatcherList() ...@@ -94,15 +94,23 @@ void CommandLineLauncher::DeleteWatcherList()
bool CommandLineLauncher::Load(const std::string & exp) bool CommandLineLauncher::Load(const std::string & exp)
{ {
m_Expression = exp; /*m_Expression = exp;
return this->Load();*/
return false;
}
bool CommandLineLauncher::Load(std::vector<std::string> vexp)
{
m_VExpression = vexp;
return this->Load(); return this->Load();
} }
bool CommandLineLauncher::Load() bool CommandLineLauncher::Load()
{ {
// Add a space to clarify output logs // Add a space to clarify output logs
std::cerr << std::endl; std::cerr << std::endl;
if (m_Expression == "") if (m_VExpression.empty())
{ {
itkExceptionMacro("No expression specified..."); itkExceptionMacro("No expression specified...");
} }
...@@ -121,9 +129,9 @@ bool CommandLineLauncher::Load() ...@@ -121,9 +129,9 @@ bool CommandLineLauncher::Load()
if (this->LoadPath() == false) if (this->LoadPath() == false)
{ {
if (m_Parser->GetPathsAsString(m_Expression).size() != 0) if (m_Parser->GetPathsAsString(m_VExpression).size() != 0)
{ {
std::cerr << "ERROR: At least one specified path within \"" << m_Parser->GetPathsAsString(m_Expression) std::cerr << "ERROR: At least one specified path within \"" << m_Parser->GetPathsAsString(m_VExpression)
<< "\" is invalid or doesn't exist..." << std::endl; << "\" is invalid or doesn't exist..." << std::endl;
return false; return false;
} }
...@@ -193,7 +201,7 @@ bool CommandLineLauncher::BeforeExecute() ...@@ -193,7 +201,7 @@ bool CommandLineLauncher::BeforeExecute()
// Check if there's keys in the expression if the application takes // Check if there's keys in the expression if the application takes
// at least 1 mandatory parameter // at least 1 mandatory parameter
const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true); const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
std::vector<std::string> keyList = m_Parser->GetKeyList( m_Expression ); std::vector<std::string> keyList = m_Parser->GetKeyList( m_VExpression );
if( appKeyList.size()!=0 && keyList.size()==0 ) if( appKeyList.size()!=0 && keyList.size()==0 )
{ {
...@@ -203,21 +211,21 @@ bool CommandLineLauncher::BeforeExecute() ...@@ -203,21 +211,21 @@ bool CommandLineLauncher::BeforeExecute()
} }
// if help is asked... // if help is asked...
if (m_Parser->IsAttributExists("-help", m_Expression) == true) if (m_Parser->IsAttributExists("-help", m_VExpression) == true)
{ {
this->DisplayHelp(); this->DisplayHelp();
return false; return false;
} }
//display OTB version //display OTB version
if (m_Parser->IsAttributExists("-version", m_Expression) == true) if (m_Parser->IsAttributExists("-version", m_VExpression) == true)
{ {
std::cerr << "This is the "<<m_Application->GetName() << " application, version " << OTB_VERSION_STRING <<std::endl; std::cerr << "This is the "<<m_Application->GetName() << " application, version " << OTB_VERSION_STRING <<std::endl;
return false; return false;
} }
// if we want to load test environnement // if we want to load test environnement
if (m_Parser->IsAttributExists("-testenv", m_Expression) == true) if (m_Parser->IsAttributExists("-testenv", m_VExpression) == true)
{ {
this->LoadTestEnv(); this->LoadTestEnv();
} }
...@@ -256,10 +264,10 @@ bool CommandLineLauncher::BeforeExecute() ...@@ -256,10 +264,10 @@ bool CommandLineLauncher::BeforeExecute()
} }
// Check for the progress report // Check for the progress report
if (m_Parser->IsAttributExists("-progress", m_Expression) == true) if (m_Parser->IsAttributExists("-progress", m_VExpression) == true)
{ {
std::vector<std::string> val; std::vector<std::string> val;
val = m_Parser->GetAttribut("-progress", m_Expression); val = m_Parser->GetAttribut("-progress", m_VExpression);
if (val.size() != 1) if (val.size() != 1)
{ {
std::cerr << "ERROR: Invalid progress argument, must be unique value..." << std::endl; std::cerr << "ERROR: Invalid progress argument, must be unique value..." << std::endl;
...@@ -292,7 +300,8 @@ bool CommandLineLauncher::LoadPath() ...@@ -292,7 +300,8 @@ bool CommandLineLauncher::LoadPath()
{ {
std::vector<std::string> pathList; std::vector<std::string> pathList;
// If users has set path... // If users has set path...
if (m_Parser->GetPaths(pathList, m_Expression) == CommandLineParser::OK) //if (m_Parser->GetPaths(pathList, m_Expression) == CommandLineParser::OK)
if (m_Parser->GetPaths(pathList, m_VExpression) == CommandLineParser::OK)
{ {
for (unsigned i = 0; i < pathList.size(); i++) for (unsigned i = 0; i < pathList.size(); i++)
{ {
...@@ -311,7 +320,8 @@ void CommandLineLauncher::LoadApplication() ...@@ -311,7 +320,8 @@ void CommandLineLauncher::LoadApplication()
{ {
// Look for the module name // Look for the module name
std::string moduleName; std::string moduleName;
if (m_Parser->GetModuleName(moduleName, m_Expression) != CommandLineParser::OK) //if (m_Parser->GetModuleName(moduleName, m_Expression) != CommandLineParser::OK)
if (m_Parser->GetModuleName(moduleName, m_VExpression) != CommandLineParser::OK)
{ {
std::cerr << "ERROR: LoadApplication, no module found..." << std::endl; std::cerr << "ERROR: LoadApplication, no module found..." << std::endl;
return; return;
...@@ -365,11 +375,11 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() ...@@ -365,11 +375,11 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
*/ */
const char *inXMLKey = "inxml"; const char *inXMLKey = "inxml";
const char *attrib = "-inxml"; const char *attrib = "-inxml";
const bool paramInXMLExists(m_Parser->IsAttributExists(attrib, m_Expression)); const bool paramInXMLExists(m_Parser->IsAttributExists(attrib, m_VExpression));
if(paramInXMLExists) if(paramInXMLExists)
{ {
std::vector<std::string> inXMLValues; std::vector<std::string> inXMLValues;
inXMLValues = m_Parser->GetAttribut(attrib, m_Expression); inXMLValues = m_Parser->GetAttribut(attrib, m_VExpression);
m_Application->SetParameterString(inXMLKey, inXMLValues[0]); m_Application->SetParameterString(inXMLKey, inXMLValues[0]);
m_Application->UpdateParameters(); m_Application->UpdateParameters();
} }
...@@ -384,13 +394,13 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() ...@@ -384,13 +394,13 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
Parameter::Pointer param = m_Application->GetParameterByKey(paramKey); Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
ParameterType type = m_Application->GetParameterType(paramKey); ParameterType type = m_Application->GetParameterType(paramKey);
const bool paramExists(m_Parser->IsAttributExists(std::string("-").append(paramKey), m_Expression)); const bool paramExists(m_Parser->IsAttributExists(std::string("-").append(paramKey), m_VExpression));
// if param is a Group, dont do anything, ParamGroup dont have values // if param is a Group, dont do anything, ParamGroup dont have values
if (type != ParameterType_Group) if (type != ParameterType_Group)
{ {
// Get the attribute relative to this key as vector // Get the attribute relative to this key as vector
values = m_Parser->GetAttribut(std::string("-").append(paramKey), m_Expression); values = m_Parser->GetAttribut(std::string("-").append(paramKey), m_VExpression);
// If the param does not exists in the cli, dont try to set a // If the param does not exists in the cli, dont try to set a
// value on it, an exception will be thrown later in this function // value on it, an exception will be thrown later in this function
...@@ -430,7 +440,7 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() ...@@ -430,7 +440,7 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
if (type == ParameterType_String) if (type == ParameterType_String)
{ {
dynamic_cast<StringParameter *> (param.GetPointer())->SetValue( dynamic_cast<StringParameter *> (param.GetPointer())->SetValue(
m_Parser->GetAttributAsString(std::string("-").append(paramKey), m_Expression) ); m_Parser->GetAttributAsString(std::string("-").append(paramKey), m_VExpression) );
} }
else else
if (type == ParameterType_OutputImage) if (type == ParameterType_OutputImage)
...@@ -586,7 +596,7 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() ...@@ -586,7 +596,7 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
} }
else else
{ {
values = m_Parser->GetAttribut(std::string("-").append(paramKey), m_Expression); values = m_Parser->GetAttribut(std::string("-").append(paramKey), m_VExpression);
if (values.size() == 0 && !m_Application->HasValue(paramKey)) if (values.size() == 0 && !m_Application->HasValue(paramKey))
{ {
std::cerr << "ERROR: Missing mandatory parameter: " << paramKey << std::endl; std::cerr << "ERROR: Missing mandatory parameter: " << paramKey << std::endl;
...@@ -599,7 +609,7 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() ...@@ -599,7 +609,7 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
{ {
if( paramExists ) if( paramExists )
{ {
values = m_Parser->GetAttribut(std::string("-").append(paramKey), m_Expression); values = m_Parser->GetAttribut(std::string("-").append(paramKey), m_VExpression);
if (values.size() == 0) if (values.size() == 0)
{ {
std::cerr << "ERROR: Missing non-mandatory parameter: " << paramKey << std::endl; std::cerr << "ERROR: Missing non-mandatory parameter: " << paramKey << std::endl;
...@@ -708,7 +718,7 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer & ...@@ -708,7 +718,7 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer &
// - The param is not root and belonging to a Mandatory Group // - The param is not root and belonging to a Mandatory Group
// wich is activated // wich is activated
bool isMissing = false; bool isMissing = false;
if (!m_Parser->IsAttributExists(std::string("-").append(paramKey), m_Expression)) if (!m_Parser->IsAttributExists(std::string("-").append(paramKey), m_VExpression))
{ {
if (!m_Application->HasValue(paramKey)) if (!m_Application->HasValue(paramKey))
{ {
...@@ -847,7 +857,8 @@ bool CommandLineLauncher::CheckUnicity() ...@@ -847,7 +857,8 @@ bool CommandLineLauncher::CheckUnicity()
{ {
bool res = true; bool res = true;
// Extract expression keys // Extract expression keys
std::vector<std::string> keyList = m_Parser->GetKeyList(m_Expression); //std::vector<std::string> keyList = m_Parser->GetKeyList(m_Expression);
std::vector<std::string> keyList = m_Parser->GetKeyList(m_VExpression);
// Check Unicity // Check Unicity
for (unsigned int i = 0; i < keyList.size(); i++) for (unsigned int i = 0; i < keyList.size(); i++)
...@@ -872,21 +883,22 @@ bool CommandLineLauncher::CheckUnicity() ...@@ -872,21 +883,22 @@ bool CommandLineLauncher::CheckUnicity()
bool CommandLineLauncher::CheckParametersPrefix() bool CommandLineLauncher::CheckParametersPrefix()
{ {
bool res = true; // Check if the chain " --" appears in the args, could be a common mistake
// Check if the chain " --" appears in the expression, could be a common mistake for (std::vector<std::string>::iterator it = m_VExpression.begin() ; it != m_VExpression.end(); ++it)
if (m_Expression.find(" --") != std::string::npos )
{ {
res = false; if (it->find("--") != std::string::npos )
{
return false;
}
} }
return true;
return res;
} }
bool CommandLineLauncher::CheckKeyValidity(std::string& refKey) bool CommandLineLauncher::CheckKeyValidity(std::string& refKey)
{ {
bool res = true; bool res = true;
// Extract expression keys // Extract expression keys
std::vector<std::string> expKeyList = m_Parser->GetKeyList(m_Expression); std::vector<std::string> expKeyList = m_Parser->GetKeyList(m_VExpression);
// Extract application keys // Extract application keys
std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true); std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
...@@ -895,13 +907,18 @@ bool CommandLineLauncher::CheckKeyValidity(std::string& refKey) ...@@ -895,13 +907,18 @@ bool CommandLineLauncher::CheckKeyValidity(std::string& refKey)
appKeyList.push_back("testenv"); appKeyList.push_back("testenv");
appKeyList.push_back("version"); appKeyList.push_back("version");
std::cout<< "toto" << std::endl;
// Check if each key in the expression exists in the application // Check if each key in the expression exists in the application
for (unsigned int i = 0; i < expKeyList.size(); i++) for (unsigned int i = 0; i < expKeyList.size(); i++)
{ {
refKey = expKeyList[i]; //remove first character
std::cout<< "expKey= " << expKeyList[i] << std::endl;
refKey = expKeyList[i].substr(1,expKeyList[i].length()-1);
bool keyExist = false; bool keyExist = false;
for (unsigned int j = 0; j < appKeyList.size(); j++) for (unsigned int j = 0; j < appKeyList.size(); j++)
{ {
std::cout<< "appKey= " << appKeyList[j] << std::endl;
if (refKey == appKeyList[j]) if (refKey == appKeyList[j])
{ {
keyExist = true; keyExist = true;
...@@ -935,9 +952,9 @@ void CommandLineLauncher::DisplayOutputParameters() ...@@ -935,9 +952,9 @@ void CommandLineLauncher::DisplayOutputParameters()
} }
if ( m_Parser->IsAttributExists("-testenv", m_Expression) ) if ( m_Parser->IsAttributExists("-testenv", m_VExpression) )
{ {
std::vector<std::string> val = m_Parser->GetAttribut("-testenv", m_Expression); std::vector<std::string> val = m_Parser->GetAttribut("-testenv", m_VExpression);
if( val.size() == 1 ) if( val.size() == 1 )
{ {
std::ofstream ofs(val[0].c_str()); std::ofstream ofs(val[0].c_str());
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "itkCommand.h" #include "itkCommand.h"
#include <vector>
namespace otb namespace otb
{ {
namespace Wrapper namespace Wrapper
...@@ -84,6 +86,9 @@ public: ...@@ -84,6 +86,9 @@ public:
/** same as Load method but set the expression before. */ /** same as Load method but set the expression before. */
bool Load( const std::string & exp ); bool Load( const std::string & exp );
/** same as Load method but set the expression before. */
bool Load( std::vector<std::string> vexp);
/** Launch the process, using the Execute application method /** Launch the process, using the Execute application method
* The method will check if the user asked for help (looking at * The method will check if the user asked for help (looking at
...@@ -168,7 +173,8 @@ private: ...@@ -168,7 +173,8 @@ private:
std::string m_Path; std::string m_Path;
Application::Pointer m_Application; Application::Pointer m_Application;
std::string m_Expression; //std::string m_Expression;
std::vector<std::string> m_VExpression;
CommandLineParser::Pointer m_Parser; CommandLineParser::Pointer m_Parser;
WatcherListType m_WatcherList; WatcherListType m_WatcherList;
......
...@@ -39,6 +39,24 @@ CommandLineParser::~CommandLineParser() ...@@ -39,6 +39,24 @@ CommandLineParser::~CommandLineParser()
{ {
} }
std::string
CommandLineParser::GetPathsAsString(std::vector<std::string> & vexp )
{
std::string res;
// The first element must be the module name, non " -" allowed.
// The module path list element are the strings between the first
// element and the first key (ie. " -" string).
std::vector<std::string>::iterator it = vexp.begin();
++it; // first element is module name
while (it->find("-") != std::string::npos)
{
++it;
}
return res;
}
std::string std::string
CommandLineParser::GetPathsAsString( const std::string & exp ) CommandLineParser::GetPathsAsString( const std::string & exp )
{ {
...@@ -68,6 +86,34 @@ CommandLineParser::GetPathsAsString( const std::string & exp ) ...@@ -68,6 +86,34 @@ CommandLineParser::GetPathsAsString( const std::string & exp )
return res; return res;
} }
CommandLineParser::ParseResultType
CommandLineParser::GetPaths( std::vector<std::string> & paths, std::vector<std::string> & exp )
{
// The first element must be the module name, non " -" allowed.
// The module path list elements are the strings between the first
// element and the first key (ie. string which begins with "-").
std::vector<std::string>::iterator it = exp.begin();
++it; // first element is module name
std::vector<itksys::String> pathlist;
while (it->find("-") == std::string::npos)
{
std::string fullPath = itksys::SystemTools::CollapseFullPath((*it).c_str());
if( !itksys::SystemTools::FileIsDirectory(fullPath.c_str()) )
{
std::cerr<<"Invalid module path: "<<fullPath<<std::endl;
return INVALIDMODULEPATH;
}
paths.push_back(fullPath);
++it;
}
return OK;
}
CommandLineParser::ParseResultType CommandLineParser::ParseResultType
CommandLineParser::GetPaths( std::vector<std::string> & paths, const std::string & exp ) CommandLineParser::GetPaths( std::vector<std::string> & paths, const std::string & exp )
{ {
...@@ -118,6 +164,29 @@ CommandLineParser::GetPaths( std::vector<std::string> & paths, const std::string ...@@ -118,6 +164,29 @@ CommandLineParser::GetPaths( std::vector<std::string> & paths, const std::string
return OK; return OK;
} }
CommandLineParser::ParseResultType
CommandLineParser::GetModuleName( std::string & modName, std::vector<std::string> & exp )
{
itksys::RegularExpression reg;
reg.compile("([^0-9a-zA-Z])");
// The first element must be the module path, non " -" allowed.
if( exp[0].find(" -") != std::string::npos)
{
return NOMODULENAME;
}
// It must contain only alphanumerical character
if(reg.find(exp[0]))
{
return INVALIDMODULENAME;
}
else
{
modName = exp[0];
}
return OK;
}
CommandLineParser::ParseResultType CommandLineParser::ParseResultType
CommandLineParser::GetModuleName( std::string & modName, const std::string & exp ) CommandLineParser::GetModuleName( std::string & modName, const std::string & exp )
...@@ -162,6 +231,45 @@ CommandLineParser::GetModuleName( std::string & modName, const std::string & exp ...@@ -162,6 +231,45 @@ CommandLineParser::GetModuleName( std::string & modName, const std::string & exp
return OK; return OK;
} }
std::vector<std::string>
CommandLineParser::GetAttribut( const std::string & key, std::vector<std::string> & exp )
{
std::cout << "here1" << std::endl;
std::vector<std::string> res;
if (!this->IsAttributExists(key,exp))
return res;
std::cout << "here2: " << exp.size()<< std::endl;
bool foundKey=false;
std::vector<std::string>::iterator it = exp.begin();
while(it!=exp.end() )
{
std::cout << key << "//" << *it<< std::endl;
if (foundKey)
{
if (it->find("-") == 0)
{
std::cout << res.size() << std::endl;
return res;
}
else
res.push_back(*it);
}
if (it->find(key) != std::string::npos)
{ foundKey=true;
std::cout << "foundkey true" << std::endl;
}
else
{
std::cout << "foundkey false" << std::endl;
}
++it;
}
return res;
}
std::vector<std::string> std::vector<std::string>
CommandLineParser::GetAttribut( const std::string & key, const std::string & exp ) CommandLineParser::GetAttribut( const std::string & key, const std::string & exp )
...@@ -253,6 +361,36 @@ CommandLineParser::GetAttribut( const std::string & key, const std::string & exp ...@@ -253,6 +361,36 @@ CommandLineParser::GetAttribut( const std::string & key, const std::string & exp
return res; return res;
} }
std::string
CommandLineParser::GetAttributAsString( const std::string & key, std::vector<std::string> & exp )
{
std::string res("");
std::vector<std::string> values = this->GetAttribut( key, exp );
if( values.size() == 0 )
{
return "";
}
else if( values.size() == 1 && values[0] == " " )
{
return "";
}
for( unsigned int i=0; i<values.size(); i++)
{
if( i<values.size()-1 )
{
res.append(values[i]);
res.append(" ");
}
else
{
res.append(values[i]);
}
}
return res;
}
std::string std::string
CommandLineParser::GetAttributAsString( const std::string & key, const std::string & exp ) CommandLineParser::GetAttributAsString( const std::string & key, const std::string & exp )
{ {
...@@ -296,6 +434,31 @@ CommandLineParser::IsAttributExists( const std::string key, const std::string & ...@@ -296,6 +434,31 @@ CommandLineParser::IsAttributExists( const std::string key, const std::string &
return (found != std::string::npos); return (found != std::string::npos);
} }
bool
CommandLineParser::IsAttributExists( const std::string key, std::vector<std::string> & exp )
{
for (std::vector<std::string>::iterator it = exp.begin() ; it != exp.end(); ++it)
{
if (it->find(key) != std::string::npos)
return true;
}
return false;
}
std::vector<std::string>
CommandLineParser::GetKeyList( std::vector<std::string> & exp )
{
std::vector<std::string> keyList;
for (std::vector<std::string>::iterator it = exp.begin() ; it != exp.end(); ++it)
{
if (it->find("-") == 0 && this->IsAValidKey(*it))
{
keyList.push_back(*it);
}
}
return keyList;
}
std::vector<std::string> std::vector<std::string>
CommandLineParser::GetKeyList( const std::string & exp ) CommandLineParser::GetKeyList( const std::string & exp )
......
...@@ -57,22 +57,30 @@ public: ...@@ -57,22 +57,30 @@ public:
/** Get the attribut associatd to a key (list of element after the key and before the next "--") as a vector of string. */ /** Get the attribut associatd to a key (list of element after the key and before the next "--") as a vector of string. */
std::vector<std::string> GetAttribut( const std::string & key, const std::string & exp ); std::vector<std::string> GetAttribut( const std::string & key, const std::string & exp );
std::vector<std::string> GetAttribut( const std::string & key, std::vector<std::string> & exp );
/** Get the attribut associatd to a key (list of element after the key and before the next "--") as a string separated by spaces. */ /** Get the attribut associatd to a key (list of element after the key and before the next "--") as a string separated by spaces. */
std::string GetAttributAsString( const std::string & key, const std::string & exp ); std::string GetAttributAsString( const std::string & key, const std::string & exp );
std::string GetAttributAsString( const std::string & key, std::vector<std::string> & exp );
/** Look if a given key is in an expression. */ /** Look if a given key is in an expression. */
bool IsAttributExists(const std::string key, const std::string & exp ); bool IsAttributExists(const std::string key, const std::string & exp );
bool IsAttributExists(const std::string key, std::vector<std::string> & exp);
/** Get the paths executables in an expression. Store the list in a vector of string. */ /** Get the paths executables in an expression. Store the list in a vector of string. */
CommandLineParser::ParseResultType GetPaths( std::vector<std::string> & paths, const std::string & exp ); CommandLineParser::ParseResultType GetPaths( std::vector<std::string> & paths, const std::string & exp );
CommandLineParser::ParseResultType GetPaths( std::vector<std::string> & paths, std::vector<std::string> & exp );
/** Get the paths executables in an expression. Store the list in a vector of string. */ /** Get the paths executables in an expression. Store the list in a vector of string. */
std::string GetPathsAsString( const std::string & exp ); std::string GetPathsAsString( const std::string & exp );
std::string GetPathsAsString( std::vector<std::string> & vexp );
/** Get the module name in an expression. It can be the first element of the expression (if the expression doesn't start with a "--" or the attribut associated to the key m_ModuleNameKey). */ /** Get the module name in an expression. It can be the first element of the expression (if the expression doesn't start with a "--" or the attribut associated to the key m_ModuleNameKey). */
CommandLineParser::ParseResultType GetModuleName( std::string & modName, const std::string & exp ); CommandLineParser::ParseResultType GetModuleName( std::string & modName, const std::string & exp );
CommandLineParser::ParseResultType GetModuleName( std::string & modName, std::vector<std::string> & exp );
/** Get the list of keys in an expression. That is to say each word starting by "--". */ /** Get the list of keys in an expression. That is to say each word starting by "--". */
std::vector<std::string> GetKeyList( const std::string & exp ); std::vector<std::string> GetKeyList( const std::string & exp );
std::vector<std::string> GetKeyList( std::vector<std::string> & exp);
protected: protected:
/** Constructor */ /** Constructor */
......
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