using new CmdLineParser

This commit is contained in:
Erik Frojdh
2019-01-16 18:46:34 +01:00
parent db0807bf7b
commit 76da6a07aa
5 changed files with 77 additions and 89 deletions

View File

@ -10,7 +10,9 @@ void CmdLineParser::Print()
{
std::cout << "\nCmdLineParser::Print()\n";
std::cout << "\tmulti_id: " << multi_id_ << ", detector_id: " << detector_id_ << std::endl;
std::cout << "\tcommand: " << command_ << std::endl;
std::cout << "\texecutable: " << executable_ << '\n';
std::cout << "\tcommand: " << command_ << '\n';
std::cout << "\tn_arguments: " << n_arguments() << '\n';
std::cout << "\targuments: ";
for (size_t i = 0; i < arguments_.size(); ++i) {
std::cout << arguments_[i] << " ";
@ -22,12 +24,13 @@ void CmdLineParser::Parse(int argc, char* argv[])
{
//first element of argv is the command used to call the executable ->skipping
//and if this is the only command skip all
executable_ = argv[0];
if (argc > 1) {
//second element is cmd string that needs to be decoded
DecodeIdAndPosition(argv[1]);
//The rest of the arguments goes into a vector for later processing
for (int i = 2; i < argc; ++i)
arguments_.push_back(std::string(argv[i]));
arguments_.emplace_back(std::string(argv[i]));
}
};
@ -65,3 +68,11 @@ void CmdLineParser::DecodeIdAndPosition(const char* c)
command_ = c;
}
}
std::vector<char*> CmdLineParser::argv(){
std::vector<char*> vec;
vec.push_back(&command_.front());
for (auto& arg: arguments_)
vec.push_back(&arg.front());
return vec;
}