diff --git a/python/scripts/generate_enums.py b/python/scripts/generate_enums.py index 94971ca0b..1dbcdc2b5 100644 --- a/python/scripts/generate_enums.py +++ b/python/scripts/generate_enums.py @@ -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']) \ No newline at end of file diff --git a/slsDetectorSoftware/CMakeLists.txt b/slsDetectorSoftware/CMakeLists.txt index 9a7e32b76..e60cdab02 100755 --- a/slsDetectorSoftware/CMakeLists.txt +++ b/slsDetectorSoftware/CMakeLists.txt @@ -6,6 +6,7 @@ set(SOURCES src/slsDetector.cpp src/Detector.cpp src/CmdProxy.cpp + src/CmdLineParser.cpp ) set(HEADERS diff --git a/slsSupportLib/src/CmdLineParser.cpp b/slsDetectorSoftware/src/CmdLineParser.cpp similarity index 100% rename from slsSupportLib/src/CmdLineParser.cpp rename to slsDetectorSoftware/src/CmdLineParser.cpp diff --git a/slsDetectorSoftware/src/CmdLineParser.h b/slsDetectorSoftware/src/CmdLineParser.h new file mode 100755 index 000000000..14540bb30 --- /dev/null +++ b/slsDetectorSoftware/src/CmdLineParser.h @@ -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 +#include + +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 &arguments() const noexcept{ return arguments_; }; + std::vector 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 arguments_; +}; + +} // namespace sls +#endif // CMD_LINE_PARSER_H \ No newline at end of file diff --git a/slsDetectorSoftware/include/multiSlsDetectorClient.h b/slsDetectorSoftware/src/multiSlsDetectorClient.h similarity index 100% rename from slsDetectorSoftware/include/multiSlsDetectorClient.h rename to slsDetectorSoftware/src/multiSlsDetectorClient.h diff --git a/slsDetectorSoftware/tests/CMakeLists.txt b/slsDetectorSoftware/tests/CMakeLists.txt index 70d6ff999..e0d3a59cc 100755 --- a/slsDetectorSoftware/tests/CMakeLists.txt +++ b/slsDetectorSoftware/tests/CMakeLists.txt @@ -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 -) \ No newline at end of file + ${CMAKE_CURRENT_SOURCE_DIR}/test-CmdLineParser.cpp +) + +target_include_directories(tests PUBLIC "$") \ No newline at end of file diff --git a/slsSupportLib/tests/test-CmdLineParser.cpp b/slsDetectorSoftware/tests/test-CmdLineParser.cpp similarity index 100% rename from slsSupportLib/tests/test-CmdLineParser.cpp rename to slsDetectorSoftware/tests/test-CmdLineParser.cpp diff --git a/slsSupportLib/CMakeLists.txt b/slsSupportLib/CMakeLists.txt index 20380e13c..a4d08690e 100755 --- a/slsSupportLib/CMakeLists.txt +++ b/slsSupportLib/CMakeLists.txt @@ -1,5 +1,4 @@ set(SOURCES - src/CmdLineParser.cpp src/string_utils.cpp src/file_utils.cpp src/ClientSocket.cpp diff --git a/slsSupportLib/include/CmdLineParser.h b/slsSupportLib/include/CmdLineParser.h deleted file mode 100755 index fd4451108..000000000 --- a/slsSupportLib/include/CmdLineParser.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef CMD_LINE_PARSER_H -#define CMD_LINE_PARSER_H -#include -#include - -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 &arguments() const { return arguments_; }; - std::vector 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 arguments_; -}; - -} // namespace sls -#endif // CMD_LINE_PARSER_H \ No newline at end of file diff --git a/slsSupportLib/tests/CMakeLists.txt b/slsSupportLib/tests/CMakeLists.txt index 2d131a537..6a7315042 100755 --- a/slsSupportLib/tests/CMakeLists.txt +++ b/slsSupportLib/tests/CMakeLists.txt @@ -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