Copyright (c) 2021-2025 Bartek Kryza bkryz.nosp@m.a@gm.nosp@m.ail.c.nosp@m.om
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Classes | |
class | memoized |
Simple memoization implementation for expensive methods. More... | |
class | memoized< T, Ret > |
class | memoized< T, Ret, bool > |
class | query_driver_output_extractor |
Executed compiler frontend and extract default system paths. More... | |
class | thread_pool_executor |
Simple thread pool executor for parallelizing diagram generation. More... | |
Functions | |
std::string | get_process_output (const std::string &command) |
Execute a shell command and return console output as string. | |
void | check_process_output (const std::string &command) |
Execute command shell and throw exception if command fails. | |
std::string | get_env (const std::string &name) |
Get value of an environment variable. | |
bool | is_git_repository () |
Check if $PWD is in a Git repository. | |
std::string | run_git_command (const std::string &cmd, const std::string &env_override) |
std::string | get_git_branch () |
Get current Git branch. | |
std::string | get_git_revision () |
Get current Git revision. | |
std::string | get_git_commit () |
Get current Git commit. | |
std::string | get_git_toplevel_dir () |
Get path to the top level Git directory. | |
std::string | get_os_name () |
Get descriptive name of the current operating system. | |
std::string | ltrim (const std::string &s) |
Left trim a string. | |
std::string | rtrim (const std::string &s) |
Right trim a string. | |
std::string | trim_typename (const std::string &s) |
Remove typename prefix from a string if exists. | |
std::string | trim (const std::string &s) |
Trim a string. | |
std::optional< std::pair< std::string, std::string > > | split_at_first (const std::string &separator, const std::string &input) |
Split string at first occurence of separator. | |
std::vector< std::string > | split (std::string str, std::string_view delimiter, bool skip_empty=true) |
Split a string using delimiter. | |
std::vector< std::string > | split_isspace (std::string str) |
std::string | join (const std::vector< std::string > &toks, std::string_view delimiter) |
Join toks into string using delimiter as separator. | |
std::string | abbreviate (const std::string &s, unsigned int max_length) |
Abbreviate string to max_length, and replace last 3 characters with ellipsis. | |
bool | find_element_alias (const std::string &input, std::tuple< std::string, size_t, size_t > &result) |
Find element alias in Puml note. | |
bool | replace_all (std::string &input, const std::string &pattern, const std::string &replace_with) |
Find and replace in string. | |
template<> | |
bool | starts_with (const std::string &s, const std::string &prefix) |
template<> | |
bool | ends_with (const std::string &value, const std::string &suffix) |
std::size_t | hash_seed (std::size_t seed) |
Generate a hash seed. | |
std::string | path_to_url (const std::filesystem::path &p) |
Convert filesystem path to url path. | |
std::filesystem::path | ensure_path_is_absolute (const std::filesystem::path &p, const std::filesystem::path &root=std::filesystem::current_path()) |
Ensure path is absolute. | |
bool | 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 | format_message_comment (const std::string &comment, unsigned width) |
std::optional< std::pair< std::string, std::string > > | find_entry_by_path_prefix (const std::map< std::string, std::string > &m, const std::string &path) |
template<typename T , typename S > | |
std::unique_ptr< T > | unique_pointer_cast (std::unique_ptr< S > &&p) noexcept |
template<typename T , typename F > | |
void | erase_if (std::vector< T > &v, F &&f) |
Remove and erase elements from a vector. | |
template<typename... Args> | |
std::string | join (std::string_view delimiter, Args... args) |
Join args into string using delimiter as separator. | |
template<typename T > | |
void | append (std::vector< T > &l, const std::vector< T > &r) |
Appends a vector to a vector. | |
template<typename T > | |
bool | starts_with (const T &col, const T &prefix) |
Checks if collection starts with a prefix. | |
template<> | |
bool | starts_with (const std::string &s, const std::string &prefix) |
template<typename T > | |
bool | ends_with (const T &value, const T &suffix) |
template<> | |
bool | ends_with (const std::string &value, const std::string &suffix) |
template<typename T > | |
bool | ends_with (const std::vector< T > &col, const std::vector< T > &suffix) |
template<typename T > | |
void | 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 | contains (const T &container, const E &element) |
template<typename T , typename F > | |
void | for_each (const T &collection, F &&func) |
template<typename R , typename T , typename F > | |
std::vector< R > | map (const std::vector< T > &in, F &&f) |
template<typename T , typename F , typename FElse > | |
void | if_not_null (const T *pointer, F &&func, FElse &&func_else) |
template<typename T , typename F > | |
void | if_not_null (const T *pointer, F &&func) |
template<typename F , typename FElse > | |
void | _if (const bool condition, F &&func, FElse &&func_else) |
template<typename F > | |
void | _if (const bool condition, F &&func) |
template<typename T > | |
void | remove_duplicates (T &coll) |
Variables | |
static const auto | WHITESPACE = " \n\r\t\f\v" |
constexpr unsigned | kDefaultMessageCommentWidth {25U} |
void clanguml::util::_if | ( | const bool | condition, |
F && | func | ||
) |
void clanguml::util::_if | ( | const bool | condition, |
F && | func, | ||
FElse && | func_else | ||
) |
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.
s | Input string |
max_length | Maximum length |
Definition at line 333 of file util.cc.
void clanguml::util::append | ( | std::vector< T > & | l, |
const std::vector< T > & | r | ||
) |
void clanguml::util::check_process_output | ( | const std::string & | command | ) |
Execute command shell and throw exception if command fails.
command | Command to execute |
Definition at line 97 of file util.cc.
bool clanguml::util::contains | ( | const T & | container, |
const E & | element | ||
) |
Returns true if element exists in container.
T | |
E |
container | |
element |
Definition at line 321 of file util.h.
bool clanguml::util::ends_with | ( | const std::string & | value, |
const std::string & | suffix | ||
) |
bool clanguml::util::ends_with | ( | const std::string & | value, |
const std::string & | suffix | ||
) |
bool clanguml::util::ends_with | ( | const std::vector< T > & | col, |
const std::vector< T > & | suffix | ||
) |
bool clanguml::util::ends_with | ( | const T & | value, |
const T & | suffix | ||
) |
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.
If path is absolute, return the p. If path is not absolute, make it absolute with respect to root directory.
p | Path to modify |
root | Root against which the path should be made absolute |
Definition at line 435 of file util.cc.
void clanguml::util::erase_if | ( | std::vector< T > & | v, |
F && | f | ||
) |
Remove and erase elements from a vector.
T | Element type |
F | Functor type |
v | Vector to remove elements from |
f | Functor to decide which elements to remove |
Definition at line 182 of file util.h.
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.
Finds aliases of the form (entity_name) in the Puml notes or directives. The match, if any, is returned in the result tuple: (entity_name, offset, length)
Definition at line 349 of file util.cc.
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 | ||
) |
Definition at line 500 of file util.cc.
void clanguml::util::for_each | ( | const T & | collection, |
F && | func | ||
) |
std::string clanguml::util::format_message_comment | ( | const std::string & | comment, |
unsigned | width | ||
) |
Definition at line 464 of file util.cc.
std::string clanguml::util::get_env | ( | const std::string & | name | ) |
Get value of an environment variable.
name | Name of the environment variable |
Definition at line 121 of file util.cc.
std::string clanguml::util::get_git_branch | ( | ) |
std::string clanguml::util::get_git_commit | ( | ) |
Get current Git commit.
std::string clanguml::util::get_git_revision | ( | ) |
Get current Git revision.
Generates a Git revision tag using git describe --tags --always
command
std::string clanguml::util::get_git_toplevel_dir | ( | ) |
std::string clanguml::util::get_os_name | ( | ) |
Get descriptive name of the current operating system.
Definition at line 206 of file util.cc.
std::string clanguml::util::get_process_output | ( | const std::string & | command | ) |
Execute a shell command
and return console output as string.
command | Shell command to execute |
Definition at line 70 of file util.cc.
std::size_t clanguml::util::hash_seed | ( | std::size_t | seed | ) |
Generate a hash seed.
seed | Initial seed. |
Definition at line 398 of file util.cc.
void clanguml::util::if_not_null | ( | const T * | pointer, |
F && | func | ||
) |
void clanguml::util::if_not_null | ( | const T * | pointer, |
F && | func, | ||
FElse && | func_else | ||
) |
bool clanguml::util::is_git_repository | ( | ) |
Check if $PWD
is in a Git repository.
This can be overridden by exporting CLANGUML_GIT_COMMIT
environment variable.
Definition at line 144 of file util.cc.
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.
parent | The path to be checked for relativity. |
right | The base path against which the relativity is checked. |
Definition at line 448 of file util.cc.
std::string clanguml::util::join | ( | const std::vector< std::string > & | toks, |
std::string_view | delimiter | ||
) |
std::string clanguml::util::join | ( | std::string_view | delimiter, |
Args... | args | ||
) |
Join args
into string using delimiter
as separator.
Args | Element type |
delimiter | Separator to use to join elements |
args | Elements to join into string |
Definition at line 206 of file util.h.
std::string clanguml::util::ltrim | ( | const std::string & | s | ) |
std::vector< R > clanguml::util::map | ( | const std::vector< T > & | in, |
F && | f | ||
) |
std::string clanguml::util::path_to_url | ( | const std::filesystem::path & | p | ) |
Convert filesystem path to url path.
The purpose of this function is to make sure that a path can be used in a URL, e.g. it's separators are POSIX-style.
p | Path to convert |
Definition at line 407 of file util.cc.
void clanguml::util::remove_duplicates | ( | T & | coll | ) |
void clanguml::util::remove_prefix | ( | std::vector< T > & | col, |
const std::vector< T > & | prefix | ||
) |
bool clanguml::util::replace_all | ( | std::string & | input, |
const std::string & | pattern, | ||
const std::string & | replace_with | ||
) |
Find and replace in string.
Replaces all occurences of pattern with replace_with in input string.
Definition at line 371 of file util.cc.
std::string clanguml::util::rtrim | ( | const std::string & | s | ) |
std::string clanguml::util::run_git_command | ( | const std::string & | cmd, |
const std::string & | env_override | ||
) |
Definition at line 163 of file util.cc.
std::vector< std::string > clanguml::util::split | ( | std::string | str, |
std::string_view | delimiter, | ||
bool | skip_empty = true |
||
) |
Split a string using delimiter.
Basic string split function, because C++ stdlib does not have one. In case the string does not contain the delimiter, the original string is returned as the only element of the vector.
str | String to split |
delimiter | Delimiter string |
skip_empty | Skip empty toks between delimiters if true |
Definition at line 270 of file util.cc.
std::optional< std::pair< std::string, std::string > > clanguml::util::split_at_first | ( | const std::string & | separator, |
const std::string & | input | ||
) |
Split string at first occurence of separator.
separator | |
input |
Definition at line 252 of file util.cc.
std::vector< std::string > clanguml::util::split_isspace | ( | std::string | str | ) |
Definition at line 305 of file util.cc.
bool clanguml::util::starts_with | ( | const std::string & | s, |
const std::string & | prefix | ||
) |
bool clanguml::util::starts_with | ( | const std::string & | s, |
const std::string & | prefix | ||
) |
bool clanguml::util::starts_with | ( | const T & | col, |
const T & | prefix | ||
) |
Checks if collection starts with a prefix.
T | e.g. std::vector<std::string> |
col | Collection to be checked against prefix |
prefix | Container, which specifies the prefix |
Definition at line 270 of file util.h.
std::string clanguml::util::trim | ( | const std::string & | s | ) |
std::string clanguml::util::trim_typename | ( | const std::string & | s | ) |
|
noexcept |
|
constexpr |