From fa9cbeec307f5e26ccc63b80d7d2e5e083f33356 Mon Sep 17 00:00:00 2001 From: zahar-kohut-ucu Date: Sun, 12 May 2024 20:45:04 +0300 Subject: [PATCH] devops commit --- CMakeLists.txt | 36 ++++++++++++++++-------- compile.sh | 4 +-- include/errcode_exception.h | 23 ++++++++++++++++ include/time_measure.h | 26 +++++++++++++++++ options_parser/options_parser.cpp | 46 ------------------------------- options_parser/options_parser.h | 42 ---------------------------- src/errcode_exception.cpp | 13 +++++++++ main.cpp => src/main.cpp | 7 +++-- 8 files changed, 92 insertions(+), 105 deletions(-) create mode 100644 include/errcode_exception.h create mode 100644 include/time_measure.h delete mode 100644 options_parser/options_parser.cpp delete mode 100644 options_parser/options_parser.h create mode 100644 src/errcode_exception.cpp rename main.cpp => src/main.cpp (56%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81cdc53..b70943b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,8 @@ cmake_minimum_required(VERSION 3.15) #! CHANGE YOUR PROJECT NAME # It is used as your project's main executable name. -set(PROJECT_NAME template) -project(${PROJECT_NAME} C CXX) # project(${PROJECT_NAME} C CXX ASM) +set(PROJECT_NAME exam_acs_2024) +project(${PROJECT_NAME} C CXX) set(CMAKE_CXX_STANDARD 20) @@ -53,30 +53,42 @@ include(cmake/CompilerWarnings.cmake) ########################################################## # Project files, packages, libraries and so on ########################################################## - +set(EXE_NAME run_exam) #! Project main executable source compilation -add_executable(${PROJECT_NAME} main.cpp - options_parser/options_parser.cpp options_parser/options_parser.h) +add_executable(${EXE_NAME} src/main.cpp +) + +target_include_directories(${EXE_NAME} PRIVATE include) -#! Put path to your project headers -target_include_directories(${PROJECT_NAME} PRIVATE options_parser) +# TBB +find_package(TBB REQUIRED) +target_link_libraries(${EXE_NAME} TBB::tbb) #! Add external packages # options_parser requires boost::program_options library -find_package(Boost 1.71.0 COMPONENTS program_options system REQUIRED) -target_include_directories(${PROJECT_NAME} PRIVATE ${Boost_INCLUDE_DIR}) -target_link_libraries(${PROJECT_NAME} Boost::program_options Boost::system) +find_package(Boost 1.71.0 COMPONENTS locale program_options system REQUIRED) +target_include_directories(${EXE_NAME} PRIVATE ${Boost_INCLUDE_DIR}) +target_link_libraries(${EXE_NAME} Boost::program_options Boost::system Boost::locale) + +# Add Libarchive +#set(LibArchive_INCLUDE_DIR "/opt/homebrew/opt/libarchive/include") +find_package(LibArchive REQUIRED) +target_link_libraries(${EXE_NAME} LibArchive::LibArchive) + +# Add Threads +find_package(Threads REQUIRED) +target_link_libraries(${EXE_NAME} Threads::Threads) ########################################################## # Fixed CMakeLists.txt part ########################################################## INSTALL(PROGRAMS - $ # ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} + $ # ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} DESTINATION bin) # Define ALL_TARGETS variable to use in PVS and Sanitizers -set(ALL_TARGETS ${PROJECT_NAME}) +set(ALL_TARGETS ${EXE_NAME}) # Include CMake setup include(cmake/main-config.cmake) diff --git a/compile.sh b/compile.sh index 0c76784..4434e2c 100755 --- a/compile.sh +++ b/compile.sh @@ -8,8 +8,8 @@ set -o errexit set -o nounset set -o pipefail -debug_build=true -optimize_build=false +debug_build=false +optimize_build=true remove_dirs=false install_prefix=".." diff --git a/include/errcode_exception.h b/include/errcode_exception.h new file mode 100644 index 0000000..8f51513 --- /dev/null +++ b/include/errcode_exception.h @@ -0,0 +1,23 @@ +// +// Created by mykola on 22.04.24. +// + +#ifndef COUNTWORDS_PAR_PROFTOOLS_ERRCODE_EXCEPTION_H +#define COUNTWORDS_PAR_PROFTOOLS_ERRCODE_EXCEPTION_H + +#include +#include + +class errcode_exception: public std::exception { +private: + int m_err_code; + std::string m_message; + +public: + errcode_exception(int err_code, std::string_view msg): m_message(msg), m_err_code(err_code) {} + + [[nodiscard]] const char* what() const noexcept override; + [[nodiscard]] int err_code() const noexcept; +}; + +#endif //COUNTWORDS_PAR_PROFTOOLS_ERRCODE_EXCEPTION_H diff --git a/include/time_measure.h b/include/time_measure.h new file mode 100644 index 0000000..ddc5076 --- /dev/null +++ b/include/time_measure.h @@ -0,0 +1,26 @@ +// +// Created by mykola on 22.04.24. +// + +#ifndef COUNTWORDS_PAR_PROFTOOLS_TIME_MEASURE_H +#define COUNTWORDS_PAR_PROFTOOLS_TIME_MEASURE_H + +#include +#include + +inline std::chrono::high_resolution_clock::time_point +get_current_time_fenced() +{ + std::atomic_thread_fence(std::memory_order_seq_cst); + auto res_time = std::chrono::high_resolution_clock::now(); + std::atomic_thread_fence(std::memory_order_seq_cst); + return res_time; +} + +template +inline long long to_ms(const D& d) +{ + return std::chrono::duration_cast(d).count(); +} + +#endif //COUNTWORDS_PAR_PROFTOOLS_TIME_MEASURE_H diff --git a/options_parser/options_parser.cpp b/options_parser/options_parser.cpp deleted file mode 100644 index 75eb678..0000000 --- a/options_parser/options_parser.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// This is a personal academic project. Dear PVS-Studio, please check it. -// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com - -#include -#include -#include "options_parser.h" - -namespace po = boost::program_options; - -command_line_options_t::command_line_options_t() { - opt_conf.add_options() - ("help,h", - "Show help message") - ("A_flag,A", - "All invisible characters, except for whitespaces, " - "should be displayed as their hexadecimal codes") - ; -} - -command_line_options_t::command_line_options_t(int ac, char **av): - command_line_options_t() // Delegate constructor -{ - parse(ac, av); -} - -void command_line_options_t::parse(int ac, char **av) { - try { - po::parsed_options parsed = po::command_line_parser(ac, av).options(opt_conf).allow_unregistered().run(); - po::store(parsed, var_map); - filenames = po::collect_unrecognized(parsed.options, po::include_positional); - if (var_map.count("help")) { - std::cout << opt_conf << "\n"; - exit(EXIT_SUCCESS); - } - A_flag = var_map.count("A_flag"); - po::notify(var_map); - } catch (std::exception &ex) { - throw OptionsParseException(ex.what()); // Convert to our error type - } -} - -void assert_file_exist(const std::string &f_name) { - if (!std::filesystem::exists(f_name)) { - throw std::invalid_argument("File " + f_name + " not found!"); - } -} \ No newline at end of file diff --git a/options_parser/options_parser.h b/options_parser/options_parser.h deleted file mode 100644 index d62c4e0..0000000 --- a/options_parser/options_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef MYCAT_CONFIG_FILE_H -#define MYCAT_CONFIG_FILE_H - -#include -#include -#include -#include - -class OptionsParseException : public std::runtime_error { -public: - using runtime_error::runtime_error; -}; - -void assert_file_exist(const std::string &f_name); - -class command_line_options_t { -public: - command_line_options_t(); - command_line_options_t(int ac, char **av); - - //! Explicit is better than implicit: - command_line_options_t(const command_line_options_t&) = default; - command_line_options_t& operator=(const command_line_options_t&) = delete; - command_line_options_t(command_line_options_t&&) = default; - command_line_options_t& operator=(command_line_options_t&&) = delete; - ~command_line_options_t() = default; - - [[nodiscard]] std::vector get_filenames() const { return filenames; }; - [[nodiscard]] bool get_A_flag() const { return A_flag; }; - - void parse(int ac, char **av); -private: - bool A_flag = false; - std::vector filenames; - - boost::program_options::variables_map var_map{}; - boost::program_options::options_description opt_conf{ - "Config File Options:\n\tmycat [-h|--help] [-A_flag] ... \n"}; -}; - -#endif //MYCAT_CONFIG_FILE_H - diff --git a/src/errcode_exception.cpp b/src/errcode_exception.cpp new file mode 100644 index 0000000..7d3b53f --- /dev/null +++ b/src/errcode_exception.cpp @@ -0,0 +1,13 @@ +// +// Created by mykola on 22.04.24. +// + +#include "errcode_exception.h" + +const char* errcode_exception::what() const noexcept { + return m_message.c_str(); +} + +int errcode_exception::err_code() const noexcept { + return m_err_code; +} diff --git a/main.cpp b/src/main.cpp similarity index 56% rename from main.cpp rename to src/main.cpp index 3806a2b..982a4b3 100644 --- a/main.cpp +++ b/src/main.cpp @@ -2,10 +2,11 @@ // PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com #include -#include "options_parser.h" +#include "time_measure.h" +#include "errcode_exception.h" +#include "oneapi/tbb.h" + int main(int argc, char* argv[]) { - command_line_options_t command_line_options{argc, argv}; - std::cout << "A flag value: " << command_line_options.get_A_flag() << std::endl; return 0; }