0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Namespaces | Macros | Functions | Variables
util.h File Reference
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#include <algorithm>
#include <cstring>
#include <filesystem>
#include <map>
#include <optional>
#include <string>
#include <type_traits>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  clanguml
 
namespace  clanguml::util
 

Macros

#define LOG_ERROR(fmt__, ...)
 
#define LOG_WARN(fmt__, ...)
 
#define LOG_INFO(fmt__, ...)
 
#define LOG_DBG(fmt__, ...)
 
#define LOG_TRACE(fmt__, ...)
 
#define FILENAME_    (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
 

Functions

std::string clanguml::util::ltrim (const std::string &s)
 Left trim a string.
 
std::string clanguml::util::rtrim (const std::string &s)
 Right trim a string.
 
std::string clanguml::util::trim (const std::string &s)
 Trim a string.
 
std::string clanguml::util::trim_typename (const std::string &s)
 Remove typename prefix from a string if exists.
 
std::string clanguml::util::get_process_output (const std::string &command)
 Execute a shell command and return console output as string.
 
void clanguml::util::check_process_output (const std::string &command)
 Execute command shell and throw exception if command fails.
 
std::string clanguml::util::get_env (const std::string &name)
 Get value of an environment variable.
 
bool clanguml::util::is_git_repository ()
 Check if $PWD is in a Git repository.
 
std::string clanguml::util::get_git_branch ()
 Get current Git branch.
 
std::string clanguml::util::get_git_revision ()
 Get current Git revision.
 
std::string clanguml::util::get_git_commit ()
 Get current Git commit.
 
std::string clanguml::util::get_git_toplevel_dir ()
 Get path to the top level Git directory.
 
std::string clanguml::util::get_os_name ()
 Get descriptive name of the current operating system.
 
template<typename T , typename S >
std::unique_ptr< T > clanguml::util::unique_pointer_cast (std::unique_ptr< S > &&p) noexcept
 
std::vector< std::string > clanguml::util::split (std::string str, std::string_view delimiter, bool skip_empty=true)
 Split a string using delimiter.
 
std::vector< std::string > clanguml::util::split_isspace (std::string str)
 
template<typename T , typename F >
void clanguml::util::erase_if (std::vector< T > &v, F &&f)
 Remove and erase elements from a vector.
 
std::string clanguml::util::join (const std::vector< std::string > &toks, std::string_view delimiter)
 Join toks into string using delimiter as separator.
 
template<typename... Args>
std::string clanguml::util::join (std::string_view delimiter, Args... args)
 Join args into string using delimiter as separator.
 
std::string clanguml::util::abbreviate (const std::string &s, unsigned int max_length)
 Abbreviate string to max_length, and replace last 3 characters with ellipsis.
 
bool clanguml::util::find_element_alias (const std::string &input, std::tuple< std::string, size_t, size_t > &result)
 Find element alias in Puml note.
 
bool clanguml::util::replace_all (std::string &input, const std::string &pattern, const std::string &replace_with)
 Find and replace in string.
 
template<typename T >
void clanguml::util::append (std::vector< T > &l, const std::vector< T > &r)
 Appends a vector to a vector.
 
template<typename T >
bool clanguml::util::starts_with (const T &col, const T &prefix)
 Checks if collection starts with a prefix.
 
template<>
bool clanguml::util::starts_with (const std::filesystem::path &path, const std::filesystem::path &prefix)
 
template<>
bool clanguml::util::starts_with (const std::string &s, const std::string &prefix)
 
template<typename T >
bool clanguml::util::ends_with (const T &value, const T &suffix)
 
template<>
bool clanguml::util::ends_with (const std::string &value, const std::string &suffix)
 
template<typename T >
bool clanguml::util::ends_with (const std::vector< T > &col, const std::vector< T > &suffix)
 
template<typename T >
void clanguml::util::remove_prefix (std::vector< T > &col, const std::vector< T > &prefix)
 Removes prefix sequence of elements from the beginning of col.
 
template<typename T , typename E >
bool clanguml::util::contains (const T &container, const E &element)
 
template<typename T , typename F >
void clanguml::util::for_each (const T &collection, F &&func)
 
template<typename T , typename C , typename F >
void clanguml::util::for_each_if (const T &collection, C &&cond, F &&func)
 
template<typename R , typename T , typename F >
std::vector< R > clanguml::util::map (const std::vector< T > &in, F &&f)
 
template<typename T , typename F , typename FElse >
void clanguml::util::if_not_null (const T *pointer, F &&func, FElse &&func_else)
 
template<typename T , typename F >
void clanguml::util::if_not_null (const T *pointer, F &&func)
 
template<typename F , typename FElse >
void clanguml::util::_if (const bool condition, F &&func, FElse &&func_else)
 
template<typename F >
void clanguml::util::_if (const bool condition, F &&func)
 
std::size_t clanguml::util::hash_seed (std::size_t seed)
 Generate a hash seed.
 
std::string clanguml::util::path_to_url (const std::filesystem::path &p)
 Convert filesystem path to url path.
 
std::filesystem::path clanguml::util::ensure_path_is_absolute (const std::filesystem::path &p, const std::filesystem::path &root=std::filesystem::current_path())
 Ensure path is absolute.
 
bool clanguml::util::is_relative_to (const std::filesystem::path &parent, const std::filesystem::path &child)
 Check if a given path is relative to another path.
 
std::string clanguml::util::format_message_comment (const std::string &comment, unsigned width)
 
bool clanguml::util::is_subpath (const std::filesystem::path &path, const std::filesystem::path &base)
 
std::optional< std::pair< std::string, std::string > > clanguml::util::find_entry_by_path_prefix (const std::map< std::string, std::string > &m, const std::string &path)
 

Variables

constexpr unsigned clanguml::util::kDefaultMessageCommentWidth {25U}
 

Macro Definition Documentation

◆ FILENAME_

#define FILENAME_    (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

Definition at line 59 of file util.h.

◆ LOG_DBG

#define LOG_DBG (   fmt__,
  ... 
)
Value:
spdlog::get("clanguml-logger") \
->debug(fmt::runtime(std::string("[{}:{}] ") + fmt__), FILENAME_, \
__LINE__, ##__VA_ARGS__)

Definition at line 47 of file util.h.

◆ LOG_ERROR

#define LOG_ERROR (   fmt__,
  ... 
)
Value:
spdlog::get("clanguml-logger") \
->error(fmt::runtime(std::string("[{}:{}] ") + fmt__), FILENAME_, \
__LINE__, ##__VA_ARGS__)

Definition at line 32 of file util.h.

◆ LOG_INFO

#define LOG_INFO (   fmt__,
  ... 
)
Value:
spdlog::get("clanguml-logger") \
->info(fmt::runtime(std::string("[{}:{}] ") + fmt__), FILENAME_, \
__LINE__, ##__VA_ARGS__)

Definition at line 42 of file util.h.

◆ LOG_TRACE

#define LOG_TRACE (   fmt__,
  ... 
)
Value:
spdlog::get("clanguml-logger") \
->trace(fmt::runtime(std::string("[{}:{}] ") + fmt__), FILENAME_, \
__LINE__, ##__VA_ARGS__)

Definition at line 52 of file util.h.

◆ LOG_WARN

#define LOG_WARN (   fmt__,
  ... 
)
Value:
spdlog::get("clanguml-logger") \
->warn(fmt::runtime(std::string("[{}:{}] ") + fmt__), FILENAME_, \
__LINE__, ##__VA_ARGS__)

Definition at line 37 of file util.h.