Applied clang-tidy fixes in util

This commit is contained in:
Bartek Kryza
2022-12-20 21:22:04 +01:00
parent d6f2007a2b
commit 204156d81b
4 changed files with 39 additions and 34 deletions

View File

@@ -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<void()> thread_pool_executor::get()
return res;
}
}
} // namespace clanguml::util

View File

@@ -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<std::thread> threads_;
};
}
} // namespace clanguml::util

View File

@@ -21,10 +21,9 @@
#include <regex>
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<char, 1024> buffer;
constexpr size_t kBufferSize{1024};
std::array<char, kBufferSize> buffer{};
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> 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<std::string> split(
if (!contains(str, delimiter))
result.push_back(str);
else
while (str.size()) {
while (static_cast<unsigned int>(!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<std::string, size_t, size_t> &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

View File

@@ -21,8 +21,8 @@
#include <spdlog/spdlog.h>
#include <algorithm>
#include <cstring>
#include <filesystem>
#include <string.h>
#include <string>
#include <type_traits>
#include <vector>
@@ -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.