From 57ac5c0dab6f40f90cf081e35520967864d26754 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 23 Aug 2019 10:42:35 +0200 Subject: [PATCH] moved CmdLineParser to sls:: --- .../include/multiSlsDetectorClient.h | 2 +- slsSupportLib/include/CmdLineParser.h | 9 ++++++--- slsSupportLib/src/CmdLineParser.cpp | 18 +++++++++++------- slsSupportLib/tests/test-CmdLineParser.cpp | 1 + 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/slsDetectorSoftware/include/multiSlsDetectorClient.h b/slsDetectorSoftware/include/multiSlsDetectorClient.h index 55d1939d8..d08df34f0 100755 --- a/slsDetectorSoftware/include/multiSlsDetectorClient.h +++ b/slsDetectorSoftware/include/multiSlsDetectorClient.h @@ -15,7 +15,7 @@ class multiSlsDetectorClient { private: int action_; - CmdLineParser parser; + sls::CmdLineParser parser; multiSlsDetector *detPtr = nullptr; std::ostream &os; diff --git a/slsSupportLib/include/CmdLineParser.h b/slsSupportLib/include/CmdLineParser.h index 44a2200ad..3eed2fa8c 100755 --- a/slsSupportLib/include/CmdLineParser.h +++ b/slsSupportLib/include/CmdLineParser.h @@ -4,9 +4,11 @@ #include #include +namespace sls { + class CmdLineParser { public: - void Parse(int argc, const char * const argv[]); + void Parse(int argc, const char *const argv[]); void Parse(const std::string &s); void Print(); @@ -14,8 +16,8 @@ class CmdLineParser { int detector_id() const { return detector_id_; }; int n_arguments() const { return arguments_.size(); } const std::string &command() const { return command_; } - bool isHelp() const{return help_;} - void setCommand(std::string cmd){command_ = cmd;} + bool isHelp() const { return help_; } + void setCommand(std::string cmd) { command_ = cmd; } const std::string &executable() const { return executable_; } const std::vector &arguments() const { return arguments_; }; std::vector argv() const; @@ -30,4 +32,5 @@ class CmdLineParser { std::vector arguments_; }; +} // namespace sls #endif // CMD_LINE_PARSER_H \ No newline at end of file diff --git a/slsSupportLib/src/CmdLineParser.cpp b/slsSupportLib/src/CmdLineParser.cpp index 17394296b..0fd939bf7 100755 --- a/slsSupportLib/src/CmdLineParser.cpp +++ b/slsSupportLib/src/CmdLineParser.cpp @@ -7,6 +7,8 @@ #include #include +namespace sls { + void CmdLineParser::Print() { std::cout << "\nCmdLineParser::Print()\n"; std::cout << "\tmulti_id: " << multi_id_ @@ -40,15 +42,15 @@ void CmdLineParser::Parse(const std::string &s) { std::vector(it, std::istream_iterator()); auto old_size = arguments_.size(); arguments_.erase(std::remove_if(begin(arguments_), end(arguments_), - [](const std::string &item) { - if (item == "-h" || item == "--help") - return true; - return false; - }), - end(arguments_)); + [](const std::string &item) { + if (item == "-h" || item == "--help") + return true; + return false; + }), + end(arguments_)); if (old_size - arguments_.size() > 0) help_ = true; - if(!arguments_.empty()){ + if (!arguments_.empty()) { command_ = arguments_[0]; arguments_.erase(begin(arguments_)); } @@ -97,3 +99,5 @@ std::vector CmdLineParser::argv() const { } return vec; } + +} // namespace sls \ No newline at end of file diff --git a/slsSupportLib/tests/test-CmdLineParser.cpp b/slsSupportLib/tests/test-CmdLineParser.cpp index 144938c96..bd10cf365 100755 --- a/slsSupportLib/tests/test-CmdLineParser.cpp +++ b/slsSupportLib/tests/test-CmdLineParser.cpp @@ -9,6 +9,7 @@ // command for all depreciated commands using vs = std::vector; +using sls::CmdLineParser; SCENARIO("Construction", "[support]") { GIVEN("A default constructed CmdLineParser") {