From 204156d81bc78abeafd25a80f6726c02c71d843a Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Tue, 20 Dec 2022 21:22:04 +0100 Subject: [PATCH] Applied clang-tidy fixes in util --- src/util/thread_pool_executor.cc | 4 ++-- src/util/thread_pool_executor.h | 9 +++++++-- src/util/util.cc | 30 +++++++++++++++--------------- src/util/util.h | 30 +++++++++++++++--------------- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/util/thread_pool_executor.cc b/src/util/thread_pool_executor.cc index b72c60c9..04277d18 100644 --- a/src/util/thread_pool_executor.cc +++ b/src/util/thread_pool_executor.cc @@ -31,7 +31,7 @@ thread_pool_executor::thread_pool_executor(unsigned int pool_size) pool_size = std::thread::hardware_concurrency(); for (auto i = 0U; i < pool_size; i++) { - threads_.push_back(std::thread{&thread_pool_executor::worker, this}); + threads_.emplace_back(&thread_pool_executor::worker, this); } } @@ -90,4 +90,4 @@ std::packaged_task thread_pool_executor::get() return res; } -} +} // namespace clanguml::util diff --git a/src/util/thread_pool_executor.h b/src/util/thread_pool_executor.h index 52e19fdf..cc2c9a61 100644 --- a/src/util/thread_pool_executor.h +++ b/src/util/thread_pool_executor.h @@ -27,7 +27,12 @@ class thread_pool_executor { public: thread_pool_executor(); - thread_pool_executor(unsigned int pool_size); + thread_pool_executor(const thread_pool_executor &) = delete; + thread_pool_executor(thread_pool_executor &&) = delete; + thread_pool_executor &operator=(const thread_pool_executor &) = delete; + thread_pool_executor &operator=(thread_pool_executor &&) = delete; + + explicit thread_pool_executor(unsigned int pool_size); ~thread_pool_executor(); @@ -48,4 +53,4 @@ private: std::vector threads_; }; -} \ No newline at end of file +} // namespace clanguml::util \ No newline at end of file diff --git a/src/util/util.cc b/src/util/util.cc index bda4497b..ace86166 100644 --- a/src/util/util.cc +++ b/src/util/util.cc @@ -21,10 +21,9 @@ #include -namespace clanguml { -namespace util { +namespace clanguml::util { -const std::string WHITESPACE = " \n\r\t\f\v"; +static const auto WHITESPACE = " \n\r\t\f\v"; void setup_logging(int verbose) { @@ -49,7 +48,9 @@ void setup_logging(int verbose) std::string get_process_output(const std::string &command) { - std::array buffer; + constexpr size_t kBufferSize{1024}; + + std::array buffer{}; std::string result; std::unique_ptr pipe( popen(command.c_str(), "r"), pclose); @@ -67,7 +68,7 @@ std::string get_process_output(const std::string &command) std::string get_env(const std::string &name) { - const char *value = std::getenv(name.c_str()); + const char *value = std::getenv(name.c_str()); // NOLINT if (value == nullptr) return {}; @@ -93,7 +94,7 @@ bool is_git_repository() std::string get_git_branch() { - const auto env = get_env("CLANGUML_GIT_BRANCH"); + auto env = get_env("CLANGUML_GIT_BRANCH"); if (!env.empty()) return env; @@ -103,7 +104,7 @@ std::string get_git_branch() std::string get_git_revision() { - const auto env = get_env("CLANGUML_GIT_REVISION"); + auto env = get_env("CLANGUML_GIT_REVISION"); if (!env.empty()) return env; @@ -113,7 +114,7 @@ std::string get_git_revision() std::string get_git_commit() { - const auto env = get_env("CLANGUML_GIT_COMMIT"); + auto env = get_env("CLANGUML_GIT_COMMIT"); if (!env.empty()) return env; @@ -123,7 +124,7 @@ std::string get_git_commit() std::string get_git_toplevel_dir() { - const auto env = get_env("CLANGUML_GIT_TOPLEVEL_DIR"); + auto env = get_env("CLANGUML_GIT_TOPLEVEL_DIR"); if (!env.empty()) return env; @@ -153,7 +154,7 @@ std::vector split( if (!contains(str, delimiter)) result.push_back(str); else - while (str.size()) { + while (static_cast(!str.empty()) != 0U) { auto index = str.find(delimiter); if (index != std::string::npos) { auto tok = str.substr(0, index); @@ -210,7 +211,7 @@ std::string abbreviate(const std::string &s, const unsigned int max_length) bool find_element_alias( const std::string &input, std::tuple &result) { - std::regex alias_regex("(@A\\([^\\).]+\\))"); + std::regex alias_regex(R"((@A\([^\).]+\)))"); auto alias_it = std::sregex_iterator(input.begin(), input.end(), alias_regex); @@ -229,8 +230,8 @@ bool find_element_alias( return true; } -bool replace_all( - std::string &input, std::string pattern, std::string replace_with) +bool replace_all(std::string &input, const std::string &pattern, + const std::string &replace_with) { bool replaced{false}; @@ -280,5 +281,4 @@ template <> bool ends_with(const std::string &value, const std::string &suffix) return std::equal(suffix.rbegin(), suffix.rend(), value.rbegin()); } -} -} +} // namespace clanguml::util diff --git a/src/util/util.h b/src/util/util.h index a5b5b696..ad10816f 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -21,8 +21,8 @@ #include #include +#include #include -#include #include #include #include @@ -34,28 +34,28 @@ std::string ltrim(const std::string &s); std::string rtrim(const std::string &s); std::string trim(const std::string &s); -#define __FILENAME__ \ +#define FILENAME_ \ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) #define LOG_ERROR(fmt__, ...) \ - spdlog::get("console")->error(std::string("[{}:{}] ") + fmt__, \ - __FILENAME__, __LINE__, ##__VA_ARGS__) + spdlog::get("console")->error( \ + std::string("[{}:{}] ") + fmt__, FILENAME_, __LINE__, ##__VA_ARGS__) #define LOG_WARN(fmt__, ...) \ - spdlog::get("console")->warn(std::string("[{}:{}] ") + fmt__, \ - __FILENAME__, __LINE__, ##__VA_ARGS__) + spdlog::get("console")->warn( \ + std::string("[{}:{}] ") + fmt__, FILENAME_, __LINE__, ##__VA_ARGS__) #define LOG_INFO(fmt__, ...) \ - spdlog::get("console")->info(std::string("[{}:{}] ") + fmt__, \ - __FILENAME__, __LINE__, ##__VA_ARGS__) + spdlog::get("console")->info( \ + std::string("[{}:{}] ") + fmt__, FILENAME_, __LINE__, ##__VA_ARGS__) #define LOG_DBG(fmt__, ...) \ - spdlog::get("console")->debug(std::string("[{}:{}] ") + fmt__, \ - __FILENAME__, __LINE__, ##__VA_ARGS__) + spdlog::get("console")->debug( \ + std::string("[{}:{}] ") + fmt__, FILENAME_, __LINE__, ##__VA_ARGS__) #define LOG_TRACE(fmt__, ...) \ - spdlog::get("console")->trace(std::string("[{}:{}] ") + fmt__, \ - __FILENAME__, __LINE__, ##__VA_ARGS__) + spdlog::get("console")->trace( \ + std::string("[{}:{}] ") + fmt__, FILENAME_, __LINE__, ##__VA_ARGS__) /** * @brief Setup spdlog logger. @@ -114,7 +114,7 @@ std::string unqualify(const std::string &s); * @param max_length Maximum length * @return Abbreviated string */ -std::string abbreviate(const std::string &s, const unsigned int max_length); +std::string abbreviate(const std::string &s, unsigned int max_length); /** * @brief Find element alias in Puml note @@ -136,8 +136,8 @@ bool find_element_alias( * * @return True if at least on replacement was made */ -bool replace_all( - std::string &input, std::string pattern, std::string replace_with); +bool replace_all(std::string &input, const std::string &pattern, + const std::string &replace_with); /** * @brief Appends a vector to a vector.