renamed CmdLineParser to CmdParser

This commit is contained in:
Erik Frojdh
2019-11-27 13:56:14 +01:00
parent e996068328
commit a28fa66e54
7 changed files with 44 additions and 38 deletions

View File

@ -1,5 +1,11 @@
#include "CmdLineParser.h"
/*
This file is used to generate the command line binaries
(sls_detector_get/put/acquire/help). By defines in CMake
we get the different files.
*/
#include "CmdParser.h"
#include "CmdProxy.h"
#include "Detector.h"
#include "sls_detector_defs.h"
@ -35,7 +41,7 @@ int main(int argc, char *argv[]) {
}
}
sls::CmdLineParser parser;
sls::CmdParser parser;
parser.Parse(argc, argv);
// If we called sls_detector_acquire, add the acquire command
@ -57,11 +63,11 @@ int main(int argc, char *argv[]) {
}
try {
//How big should this try block be?
// How big should this try block be?
sls::Detector det(parser.multi_id());
sls::CmdProxy proxy(&det);
proxy.Call(parser.command(), parser.arguments(),
parser.detector_id(), action);
proxy.Call(parser.command(), parser.arguments(), parser.detector_id(),
action);
} catch (const sls::RuntimeError &e) {
// OK to catch and do nothing since this will print the error message
// and command line app will anyway exit

View File

@ -1,5 +1,5 @@
#include "CmdLineParser.h"
#include "CmdParser.h"
#include "sls_detector_defs.h"
#include <cstdio>
#include <cstring>
@ -9,8 +9,8 @@
namespace sls {
void CmdLineParser::Print() {
std::cout << "\nCmdLineParser::Print()\n";
void CmdParser::Print() {
std::cout << "\nCmdParser::Print()\n";
std::cout << "\tmulti_id: " << multi_id_
<< ", detector_id: " << detector_id_ << std::endl;
std::cout << "\texecutable: " << executable_ << '\n';
@ -23,7 +23,7 @@ void CmdLineParser::Print() {
std::cout << "\n\n";
};
void CmdLineParser::Parse(int argc, const char *const argv[]) {
void CmdParser::Parse(int argc, const char *const argv[]) {
Reset();
executable_ = argv[0]; // first arg is calling binary
if (argc > 1) {
@ -36,7 +36,7 @@ void CmdLineParser::Parse(int argc, const char *const argv[]) {
}
}
void CmdLineParser::Parse(const std::string &s) {
void CmdParser::Parse(const std::string &s) {
Reset();
std::istringstream iss(s);
auto it = std::istream_iterator<std::string>(iss);
@ -59,7 +59,7 @@ void CmdLineParser::Parse(const std::string &s) {
DecodeIdAndPosition(command_.c_str());
}
void CmdLineParser::DecodeIdAndPosition(const char *c) {
void CmdParser::DecodeIdAndPosition(const char *c) {
bool contains_id = std::strchr(c, '-') != nullptr;
bool contains_pos = std::strchr(c, ':') != nullptr;
char tmp[100];
@ -91,7 +91,7 @@ void CmdLineParser::DecodeIdAndPosition(const char *c) {
}
}
std::vector<const char *> CmdLineParser::argv() const {
std::vector<const char *> CmdParser::argv() const {
std::vector<const char *> vec;
if (command_.empty() != true) {
vec.push_back(&command_.front());
@ -103,7 +103,7 @@ std::vector<const char *> CmdLineParser::argv() const {
}
std::string CmdLineParser::cli_line() const{
std::string CmdParser::cli_line() const{
std::ostringstream os;
os << command_;
for (const auto & arg : arguments_)
@ -111,7 +111,7 @@ std::string CmdLineParser::cli_line() const{
return os.str();
}
void CmdLineParser::Reset(){
void CmdParser::Reset(){
multi_id_ = 0;
detector_id_ = -1;
help_ = false;

View File

@ -19,7 +19,7 @@ reason that the header file is not exposed.
namespace sls {
class CmdLineParser {
class CmdParser {
public:
void Parse(int argc, const char *const argv[]);
void Parse(const std::string &s);

View File

@ -1,5 +1,5 @@
#include "Detector.h"
#include "CmdLineParser.h"
#include "CmdParser.h"
#include "CmdProxy.h"
#include "container_utils.h"
#include "detectorData.h"
@ -58,7 +58,7 @@ void Detector::loadConfig(const std::string &fname) {
void Detector::loadParameters(const std::string &fname) {
CmdProxy proxy(this);
CmdLineParser parser;
CmdParser parser;
std::ifstream input_file;
input_file.open(fname.c_str(), std::ios_base::in);
if (!input_file.is_open()) {