From a961eead24e1cdd8f17dece4f2c767b2c2271013 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 15 Sep 2021 08:49:57 +0200 Subject: [PATCH] format and removed unused headers --- slsDetectorSoftware/src/CmdParser.cpp | 59 +++++++++++++-------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/slsDetectorSoftware/src/CmdParser.cpp b/slsDetectorSoftware/src/CmdParser.cpp index 84dbeffef..90b548275 100644 --- a/slsDetectorSoftware/src/CmdParser.cpp +++ b/slsDetectorSoftware/src/CmdParser.cpp @@ -1,10 +1,8 @@ #include "CmdParser.h" -#include "sls/sls_detector_defs.h" #include "sls/string_utils.h" -#include -#include -#include + +#include #include #include @@ -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(iss); - command_ = *it++; //First arg is the comand to run + command_ = *it++; // First arg is the comand to run arguments_ = std::vector(it, std::istream_iterator()); - //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() {