Moved CmdLineProxy

This commit is contained in:
Erik Frojdh 2019-11-05 11:07:07 +01:00
parent b3587bcee5
commit 2f2e4da628
10 changed files with 68 additions and 42 deletions

View File

@ -1,7 +1,16 @@
"""
Code generator for enum bindings in the Python extension.
Reads the sls_detector_defs.h and enums_in.cpp then outputs
enums.cpp
"""
import re
import subprocess
def comment_remover(text):
def remove_comments(text):
def replacer(match):
s = match.group(0)
if s.startswith('/'):
@ -49,7 +58,7 @@ def generate_enum_string(enums):
with open('../../slsSupportLib/include/sls_detector_defs.h') as f:
data = f.read()
data = comment_remover(data)
data = remove_comments(data)
data = data.splitlines()
enums = extract_enums(data)
s = generate_enum_string(enums)
@ -64,5 +73,5 @@ with open('../src/enums.cpp', 'w') as f:
f.write(text)
# clang-format ../src/enums.cpp -i
# run clang format on the output
subprocess.run(['clang-format', '../src/enums.cpp', '-i'])

View File

@ -6,6 +6,7 @@ set(SOURCES
src/slsDetector.cpp
src/Detector.cpp
src/CmdProxy.cpp
src/CmdLineParser.cpp
)
set(HEADERS

View File

@ -0,0 +1,51 @@
/*
This class parses command line input or string input to extract the
multi_id, detector_id, command and arguments. It's used in the command
line binaries (sls_detector_get/put) to parse commands and in the
slsDetectorShared library to parse input from config files.
This class is fully internal to the project and NO guarantees are given
on the stability of the interface or implementation. This is also the
reason that the header file is not exposed.
*/
#ifndef CMD_LINE_PARSER_H
#define CMD_LINE_PARSER_H
#include <string>
#include <vector>
namespace sls {
class CmdLineParser {
public:
void Parse(int argc, const char *const argv[]);
void Parse(const std::string &s);
void Print();
int multi_id() const noexcept { return multi_id_; };
int detector_id() const noexcept { return detector_id_; };
int n_arguments() const noexcept { return arguments_.size(); }
const std::string &command() const noexcept{ return command_; }
void setCommand(std::string cmd) { command_ = cmd; }
bool isHelp() const noexcept { return help_; }
const std::string &executable() const noexcept{ return executable_; }
const std::vector<std::string> &arguments() const noexcept{ return arguments_; };
std::vector<const char *> argv() const;
std::string cli_line() const;
private:
void DecodeIdAndPosition(const char *c);
int multi_id_ = 0;
int detector_id_ = -1;
bool help_{false};
std::string command_;
std::string executable_;
std::vector<std::string> arguments_;
};
} // namespace sls
#endif // CMD_LINE_PARSER_H

View File

@ -4,4 +4,7 @@ target_sources(tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/test-multiSlsDetector.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-multiSlsDetectorClient.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-Result.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-CmdLineParser.cpp
)
target_include_directories(tests PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src>")

View File

@ -1,5 +1,4 @@
set(SOURCES
src/CmdLineParser.cpp
src/string_utils.cpp
src/file_utils.cpp
src/ClientSocket.cpp

View File

@ -1,36 +0,0 @@
#ifndef CMD_LINE_PARSER_H
#define CMD_LINE_PARSER_H
#include <string>
#include <vector>
namespace sls {
class CmdLineParser {
public:
void Parse(int argc, const char *const argv[]);
void Parse(const std::string &s);
void Print();
int multi_id() const { return multi_id_; };
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; }
const std::string &executable() const { return executable_; }
const std::vector<std::string> &arguments() const { return arguments_; };
std::vector<const char *> argv() const;
std::string cli_line() const;
private:
void DecodeIdAndPosition(const char *c);
int multi_id_ = 0;
int detector_id_ = -1;
bool help_{false};
std::string command_;
std::string executable_;
std::vector<std::string> arguments_;
};
} // namespace sls
#endif // CMD_LINE_PARSER_H

View File

@ -1,5 +1,4 @@
target_sources(tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/test-CmdLineParser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-container_utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-network_utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-string_utils.cpp