mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-18 15:57:13 +02:00
Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer
This commit is contained in:
@ -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,16 +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);
|
||||
auto cmd = proxy.Call(parser.command(), parser.arguments(),
|
||||
parser.detector_id(), action);
|
||||
// TODO! move this check into CmdProxy
|
||||
if (!cmd.empty()) {
|
||||
std::cout << cmd
|
||||
<< " Unknown command, use list to list all commands\n";
|
||||
}
|
||||
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
|
||||
|
@ -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;
|
@ -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);
|
@ -25,7 +25,7 @@ std::ostream &operator<<(std::ostream &os,
|
||||
return os;
|
||||
}
|
||||
|
||||
std::string CmdProxy::Call(const std::string &command,
|
||||
void CmdProxy::Call(const std::string &command,
|
||||
const std::vector<std::string> &arguments,
|
||||
int detector_id, int action, std::ostream &os) {
|
||||
cmd = command;
|
||||
@ -37,9 +37,8 @@ std::string CmdProxy::Call(const std::string &command,
|
||||
auto it = functions.find(cmd);
|
||||
if (it != functions.end()) {
|
||||
os << ((*this).*(it->second))(action);
|
||||
return {};
|
||||
} else {
|
||||
return cmd;
|
||||
throw sls::RuntimeError(cmd + " Unknown command, use list to list all commands");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,7 +416,7 @@ class CmdProxy {
|
||||
public:
|
||||
explicit CmdProxy(Detector *ptr) : det(ptr) {}
|
||||
|
||||
std::string Call(const std::string &command,
|
||||
void Call(const std::string &command,
|
||||
const std::vector<std::string> &arguments, int detector_id = -1,
|
||||
int action = -1, std::ostream &os = std::cout);
|
||||
|
||||
|
@ -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()) {
|
||||
|
Reference in New Issue
Block a user