format and removed unused headers

This commit is contained in:
Erik Frojdh 2021-09-15 08:49:57 +02:00
parent ca35613b66
commit a961eead24

View File

@ -1,10 +1,8 @@
#include "CmdParser.h"
#include "sls/sls_detector_defs.h"
#include "sls/string_utils.h"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <sstream>
@ -24,74 +22,73 @@ void CmdParser::Parse(int argc, const char *const argv[]) {
}
void CmdParser::Parse(std::string s) {
//taking s by value we can modify it.
// taking s by value we can modify it.
Reset();
//Are we looking at -h --help?
// Are we looking at -h --help?
bool h = replace_first(&s, "--help", " ");
h = h || replace_first(&s, "-h", " ");
help_ = h;
// Extract the position indicies
auto pos = s.find_first_not_of("0123456789:- ");
if (pos!=0){
if (pos != 0) {
auto pre = s.substr(0, pos);
pre.erase(std::remove(pre.begin(), pre.end(), ' '), pre.end());
s.erase(0, pos);
DecodeIdAndPosition(pre.c_str());
}
//Command and args should now be all that's left in the string
// Command and args should now be all that's left in the string
std::istringstream iss(s);
auto it = std::istream_iterator<std::string>(iss);
command_ = *it++; //First arg is the comand to run
command_ = *it++; // First arg is the comand to run
arguments_ =
std::vector<std::string>(it, std::istream_iterator<std::string>());
//allow comma sep
for (auto& arg : arguments_){
// allow comma sep
for (auto &arg : arguments_) {
if (arg.back() == ',')
arg.pop_back();
}
}
void CmdParser::DecodeIdAndPosition(std::string pre){
if(pre.empty())
void CmdParser::DecodeIdAndPosition(std::string pre) {
if (pre.empty())
return;
//Get the detector id
// Get the detector id
auto pos = pre.find_first_of("-");
if (pos != std::string::npos){
if (pos != std::string::npos) {
multi_id_ = std::stoi(pre);
pre.erase(0,pos+1);
pre.erase(0, pos + 1);
}
//if there is nothing left to parse we need to return
if(pre.empty()){
// if there is nothing left to parse we need to return
if (pre.empty()) {
return;
}
//now lets see if there is a :
// now lets see if there is a :
pos = pre.find_first_of(":");
if (pos == std::string::npos){
//no : we only have the multi id
if (pos == std::string::npos) {
// no : we only have the multi id
detector_id_ = std::stoi(pre);
}else if(pos == 0){
//do nothing, there is no multi id specified
pre.erase(0,1);
}else{
} else if (pos == 0) {
// do nothing, there is no multi id specified
pre.erase(0, 1);
} else {
// the : is somewhere in the middle
detector_id_ = std::stoi(pre);
pre.erase(0,pos+1);
pre.erase(0, pos + 1);
}
//now if the string is not empty we also have a receiver id
if(!pre.empty()){
// now if the string is not empty we also have a receiver id
if (!pre.empty()) {
receiver_id_ = std::stoi(pre);
}
}
void CmdParser::Reset() {