Applied clang-tidy fixes in util
This commit is contained in:
@@ -31,7 +31,7 @@ thread_pool_executor::thread_pool_executor(unsigned int pool_size)
|
|||||||
pool_size = std::thread::hardware_concurrency();
|
pool_size = std::thread::hardware_concurrency();
|
||||||
|
|
||||||
for (auto i = 0U; i < pool_size; i++) {
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace clanguml::util
|
||||||
|
|||||||
@@ -27,7 +27,12 @@ class thread_pool_executor {
|
|||||||
public:
|
public:
|
||||||
thread_pool_executor();
|
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();
|
~thread_pool_executor();
|
||||||
|
|
||||||
@@ -48,4 +53,4 @@ private:
|
|||||||
|
|
||||||
std::vector<std::thread> threads_;
|
std::vector<std::thread> threads_;
|
||||||
};
|
};
|
||||||
}
|
} // namespace clanguml::util
|
||||||
@@ -21,10 +21,9 @@
|
|||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
namespace clanguml {
|
namespace clanguml::util {
|
||||||
namespace util {
|
|
||||||
|
|
||||||
const std::string WHITESPACE = " \n\r\t\f\v";
|
static const auto WHITESPACE = " \n\r\t\f\v";
|
||||||
|
|
||||||
void setup_logging(int verbose)
|
void setup_logging(int verbose)
|
||||||
{
|
{
|
||||||
@@ -49,7 +48,9 @@ void setup_logging(int verbose)
|
|||||||
|
|
||||||
std::string get_process_output(const std::string &command)
|
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::string result;
|
||||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(
|
||||||
popen(command.c_str(), "r"), pclose);
|
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)
|
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)
|
if (value == nullptr)
|
||||||
return {};
|
return {};
|
||||||
@@ -93,7 +94,7 @@ bool is_git_repository()
|
|||||||
|
|
||||||
std::string get_git_branch()
|
std::string get_git_branch()
|
||||||
{
|
{
|
||||||
const auto env = get_env("CLANGUML_GIT_BRANCH");
|
auto env = get_env("CLANGUML_GIT_BRANCH");
|
||||||
|
|
||||||
if (!env.empty())
|
if (!env.empty())
|
||||||
return env;
|
return env;
|
||||||
@@ -103,7 +104,7 @@ std::string get_git_branch()
|
|||||||
|
|
||||||
std::string get_git_revision()
|
std::string get_git_revision()
|
||||||
{
|
{
|
||||||
const auto env = get_env("CLANGUML_GIT_REVISION");
|
auto env = get_env("CLANGUML_GIT_REVISION");
|
||||||
|
|
||||||
if (!env.empty())
|
if (!env.empty())
|
||||||
return env;
|
return env;
|
||||||
@@ -113,7 +114,7 @@ std::string get_git_revision()
|
|||||||
|
|
||||||
std::string get_git_commit()
|
std::string get_git_commit()
|
||||||
{
|
{
|
||||||
const auto env = get_env("CLANGUML_GIT_COMMIT");
|
auto env = get_env("CLANGUML_GIT_COMMIT");
|
||||||
|
|
||||||
if (!env.empty())
|
if (!env.empty())
|
||||||
return env;
|
return env;
|
||||||
@@ -123,7 +124,7 @@ std::string get_git_commit()
|
|||||||
|
|
||||||
std::string get_git_toplevel_dir()
|
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())
|
if (!env.empty())
|
||||||
return env;
|
return env;
|
||||||
@@ -153,7 +154,7 @@ std::vector<std::string> split(
|
|||||||
if (!contains(str, delimiter))
|
if (!contains(str, delimiter))
|
||||||
result.push_back(str);
|
result.push_back(str);
|
||||||
else
|
else
|
||||||
while (str.size()) {
|
while (static_cast<unsigned int>(!str.empty()) != 0U) {
|
||||||
auto index = str.find(delimiter);
|
auto index = str.find(delimiter);
|
||||||
if (index != std::string::npos) {
|
if (index != std::string::npos) {
|
||||||
auto tok = str.substr(0, index);
|
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(
|
bool find_element_alias(
|
||||||
const std::string &input, std::tuple<std::string, size_t, size_t> &result)
|
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 =
|
auto alias_it =
|
||||||
std::sregex_iterator(input.begin(), input.end(), alias_regex);
|
std::sregex_iterator(input.begin(), input.end(), alias_regex);
|
||||||
@@ -229,8 +230,8 @@ bool find_element_alias(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool replace_all(
|
bool replace_all(std::string &input, const std::string &pattern,
|
||||||
std::string &input, std::string pattern, std::string replace_with)
|
const std::string &replace_with)
|
||||||
{
|
{
|
||||||
bool replaced{false};
|
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());
|
return std::equal(suffix.rbegin(), suffix.rend(), value.rbegin());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace clanguml::util
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstring>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -34,28 +34,28 @@ std::string ltrim(const std::string &s);
|
|||||||
std::string rtrim(const std::string &s);
|
std::string rtrim(const std::string &s);
|
||||||
std::string trim(const std::string &s);
|
std::string trim(const std::string &s);
|
||||||
|
|
||||||
#define __FILENAME__ \
|
#define FILENAME_ \
|
||||||
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||||
|
|
||||||
#define LOG_ERROR(fmt__, ...) \
|
#define LOG_ERROR(fmt__, ...) \
|
||||||
spdlog::get("console")->error(std::string("[{}:{}] ") + fmt__, \
|
spdlog::get("console")->error( \
|
||||||
__FILENAME__, __LINE__, ##__VA_ARGS__)
|
std::string("[{}:{}] ") + fmt__, FILENAME_, __LINE__, ##__VA_ARGS__)
|
||||||
|
|
||||||
#define LOG_WARN(fmt__, ...) \
|
#define LOG_WARN(fmt__, ...) \
|
||||||
spdlog::get("console")->warn(std::string("[{}:{}] ") + fmt__, \
|
spdlog::get("console")->warn( \
|
||||||
__FILENAME__, __LINE__, ##__VA_ARGS__)
|
std::string("[{}:{}] ") + fmt__, FILENAME_, __LINE__, ##__VA_ARGS__)
|
||||||
|
|
||||||
#define LOG_INFO(fmt__, ...) \
|
#define LOG_INFO(fmt__, ...) \
|
||||||
spdlog::get("console")->info(std::string("[{}:{}] ") + fmt__, \
|
spdlog::get("console")->info( \
|
||||||
__FILENAME__, __LINE__, ##__VA_ARGS__)
|
std::string("[{}:{}] ") + fmt__, FILENAME_, __LINE__, ##__VA_ARGS__)
|
||||||
|
|
||||||
#define LOG_DBG(fmt__, ...) \
|
#define LOG_DBG(fmt__, ...) \
|
||||||
spdlog::get("console")->debug(std::string("[{}:{}] ") + fmt__, \
|
spdlog::get("console")->debug( \
|
||||||
__FILENAME__, __LINE__, ##__VA_ARGS__)
|
std::string("[{}:{}] ") + fmt__, FILENAME_, __LINE__, ##__VA_ARGS__)
|
||||||
|
|
||||||
#define LOG_TRACE(fmt__, ...) \
|
#define LOG_TRACE(fmt__, ...) \
|
||||||
spdlog::get("console")->trace(std::string("[{}:{}] ") + fmt__, \
|
spdlog::get("console")->trace( \
|
||||||
__FILENAME__, __LINE__, ##__VA_ARGS__)
|
std::string("[{}:{}] ") + fmt__, FILENAME_, __LINE__, ##__VA_ARGS__)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Setup spdlog logger.
|
* @brief Setup spdlog logger.
|
||||||
@@ -114,7 +114,7 @@ std::string unqualify(const std::string &s);
|
|||||||
* @param max_length Maximum length
|
* @param max_length Maximum length
|
||||||
* @return Abbreviated string
|
* @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
|
* @brief Find element alias in Puml note
|
||||||
@@ -136,8 +136,8 @@ bool find_element_alias(
|
|||||||
*
|
*
|
||||||
* @return True if at least on replacement was made
|
* @return True if at least on replacement was made
|
||||||
*/
|
*/
|
||||||
bool replace_all(
|
bool replace_all(std::string &input, const std::string &pattern,
|
||||||
std::string &input, std::string pattern, std::string replace_with);
|
const std::string &replace_with);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Appends a vector to a vector.
|
* @brief Appends a vector to a vector.
|
||||||
|
|||||||
Reference in New Issue
Block a user