mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 07:20:01 +02:00
format and removed unused headers
This commit is contained in:
parent
ca35613b66
commit
a961eead24
@ -1,10 +1,8 @@
|
|||||||
|
|
||||||
#include "CmdParser.h"
|
#include "CmdParser.h"
|
||||||
#include "sls/sls_detector_defs.h"
|
|
||||||
#include "sls/string_utils.h"
|
#include "sls/string_utils.h"
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
#include <algorithm>
|
||||||
#include <iostream>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -24,74 +22,73 @@ void CmdParser::Parse(int argc, const char *const argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CmdParser::Parse(std::string s) {
|
void CmdParser::Parse(std::string s) {
|
||||||
//taking s by value we can modify it.
|
// taking s by value we can modify it.
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
//Are we looking at -h --help?
|
// Are we looking at -h --help?
|
||||||
bool h = replace_first(&s, "--help", " ");
|
bool h = replace_first(&s, "--help", " ");
|
||||||
h = h || replace_first(&s, "-h", " ");
|
h = h || replace_first(&s, "-h", " ");
|
||||||
help_ = h;
|
help_ = h;
|
||||||
|
|
||||||
// Extract the position indicies
|
// Extract the position indicies
|
||||||
auto pos = s.find_first_not_of("0123456789:- ");
|
auto pos = s.find_first_not_of("0123456789:- ");
|
||||||
if (pos!=0){
|
if (pos != 0) {
|
||||||
auto pre = s.substr(0, pos);
|
auto pre = s.substr(0, pos);
|
||||||
pre.erase(std::remove(pre.begin(), pre.end(), ' '), pre.end());
|
pre.erase(std::remove(pre.begin(), pre.end(), ' '), pre.end());
|
||||||
s.erase(0, pos);
|
s.erase(0, pos);
|
||||||
DecodeIdAndPosition(pre.c_str());
|
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);
|
std::istringstream iss(s);
|
||||||
auto it = std::istream_iterator<std::string>(iss);
|
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_ =
|
arguments_ =
|
||||||
std::vector<std::string>(it, std::istream_iterator<std::string>());
|
std::vector<std::string>(it, std::istream_iterator<std::string>());
|
||||||
|
|
||||||
//allow comma sep
|
// allow comma sep
|
||||||
for (auto& arg : arguments_){
|
for (auto &arg : arguments_) {
|
||||||
if (arg.back() == ',')
|
if (arg.back() == ',')
|
||||||
arg.pop_back();
|
arg.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmdParser::DecodeIdAndPosition(std::string pre){
|
void CmdParser::DecodeIdAndPosition(std::string pre) {
|
||||||
if(pre.empty())
|
if (pre.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Get the detector id
|
// Get the detector id
|
||||||
auto pos = pre.find_first_of("-");
|
auto pos = pre.find_first_of("-");
|
||||||
if (pos != std::string::npos){
|
if (pos != std::string::npos) {
|
||||||
multi_id_ = std::stoi(pre);
|
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 there is nothing left to parse we need to return
|
||||||
if(pre.empty()){
|
if (pre.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//now lets see if there is a :
|
// now lets see if there is a :
|
||||||
pos = pre.find_first_of(":");
|
pos = pre.find_first_of(":");
|
||||||
if (pos == std::string::npos){
|
if (pos == std::string::npos) {
|
||||||
//no : we only have the multi id
|
// no : we only have the multi id
|
||||||
detector_id_ = std::stoi(pre);
|
detector_id_ = std::stoi(pre);
|
||||||
|
|
||||||
}else if(pos == 0){
|
} else if (pos == 0) {
|
||||||
//do nothing, there is no multi id specified
|
// do nothing, there is no multi id specified
|
||||||
pre.erase(0,1);
|
pre.erase(0, 1);
|
||||||
}else{
|
} else {
|
||||||
// the : is somewhere in the middle
|
// the : is somewhere in the middle
|
||||||
detector_id_ = std::stoi(pre);
|
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
|
// now if the string is not empty we also have a receiver id
|
||||||
if(!pre.empty()){
|
if (!pre.empty()) {
|
||||||
receiver_id_ = std::stoi(pre);
|
receiver_id_ = std::stoi(pre);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmdParser::Reset() {
|
void CmdParser::Reset() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user