Added initial support for directory based packages in class diagrams
This commit is contained in:
@@ -107,6 +107,8 @@ void inheritable_diagram_options::inherit(
|
||||
exclude.override(parent.exclude);
|
||||
puml.override(parent.puml);
|
||||
generate_method_arguments.override(parent.generate_method_arguments);
|
||||
generate_packages.override(parent.generate_packages);
|
||||
package_type.override(parent.package_type);
|
||||
generate_links.override(parent.generate_links);
|
||||
generate_system_headers.override(parent.generate_system_headers);
|
||||
git.override(parent.git);
|
||||
@@ -136,14 +138,20 @@ std::vector<std::string> diagram::get_translation_units() const
|
||||
{
|
||||
std::vector<std::string> translation_units{};
|
||||
|
||||
LOG_DBG("Looking for translation units in {}",
|
||||
std::filesystem::current_path().string());
|
||||
|
||||
for (const auto &g : glob()) {
|
||||
std::string glob_path =
|
||||
fmt::format("{}/{}", relative_to().string(), g.c_str());
|
||||
fmt::format("{}/{}", root_directory().string(), g.c_str());
|
||||
|
||||
LOG_DBG("Searching glob path {}", glob_path);
|
||||
|
||||
auto matches = glob::glob(glob_path, true, false);
|
||||
|
||||
for (const auto &match : matches) {
|
||||
const auto path = std::filesystem::canonical(relative_to() / match);
|
||||
const auto path =
|
||||
std::filesystem::canonical(root_directory() / match);
|
||||
translation_units.emplace_back(path.string());
|
||||
}
|
||||
}
|
||||
@@ -151,6 +159,17 @@ std::vector<std::string> diagram::get_translation_units() const
|
||||
return translation_units;
|
||||
}
|
||||
|
||||
std::filesystem::path diagram::root_directory() const
|
||||
{
|
||||
return canonical(absolute(base_directory() / relative_to()));
|
||||
}
|
||||
|
||||
std::filesystem::path diagram::make_path_relative(
|
||||
const std::filesystem::path &p) const
|
||||
{
|
||||
return relative(p, root_directory()).lexically_normal().string();
|
||||
}
|
||||
|
||||
std::optional<std::string> diagram::get_together_group(
|
||||
const std::string &full_name) const
|
||||
{
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace config {
|
||||
|
||||
enum class method_arguments { full, abbreviated, none };
|
||||
|
||||
enum class package_type_t { kNamespace, kDirectory };
|
||||
|
||||
std::string to_string(method_arguments ma);
|
||||
|
||||
enum class comment_parser_t { plain, clang };
|
||||
@@ -162,10 +164,17 @@ struct inheritable_diagram_options {
|
||||
option<method_arguments> generate_method_arguments{
|
||||
"generate_method_arguments", method_arguments::full};
|
||||
option<bool> generate_packages{"generate_packages", false};
|
||||
option<package_type_t> package_type{
|
||||
"package_type", package_type_t::kNamespace};
|
||||
option<generate_links_config> generate_links{"generate_links"};
|
||||
option<git_config> git{"git"};
|
||||
option<layout_hints> layout{"layout"};
|
||||
// This is the absolute filesystem path to the directory containing
|
||||
// the current .clang-uml config file - it is set automatically
|
||||
option<std::filesystem::path> base_directory{"__parent_path"};
|
||||
// This is the relative path with respect to the `base_directory`,
|
||||
// against which all matches are made, if not provided it defaults to the
|
||||
// `base_directory`
|
||||
option<std::filesystem::path> relative_to{"relative_to"};
|
||||
option<bool> generate_system_headers{"generate_system_headers", false};
|
||||
option<relationship_hints_t> relationship_hints{"relationship_hints"};
|
||||
@@ -190,6 +199,11 @@ struct diagram : public inheritable_diagram_options {
|
||||
|
||||
std::vector<std::string> get_translation_units() const;
|
||||
|
||||
std::filesystem::path make_path_relative(
|
||||
const std::filesystem::path &p) const;
|
||||
|
||||
std::filesystem::path root_directory() const;
|
||||
|
||||
std::optional<std::string> get_together_group(
|
||||
const std::string &full_name) const;
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ using clanguml::config::layout_hint;
|
||||
using clanguml::config::location_t;
|
||||
using clanguml::config::method_arguments;
|
||||
using clanguml::config::package_diagram;
|
||||
using clanguml::config::package_type_t;
|
||||
using clanguml::config::plantuml;
|
||||
using clanguml::config::relationship_hint_t;
|
||||
using clanguml::config::sequence_diagram;
|
||||
@@ -88,6 +89,22 @@ void get_option<method_arguments>(
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void get_option<package_type_t>(
|
||||
const Node &node, clanguml::config::option<package_type_t> &option)
|
||||
{
|
||||
if (node[option.name]) {
|
||||
const auto &val = node[option.name].as<std::string>();
|
||||
if (val == "namespace")
|
||||
option.set(package_type_t::kNamespace);
|
||||
else if (val == "directory")
|
||||
option.set(package_type_t::kDirectory);
|
||||
else
|
||||
throw std::runtime_error(
|
||||
"Invalid generate_method_arguments value: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void get_option<clanguml::config::comment_parser_t>(const Node &node,
|
||||
clanguml::config::option<clanguml::config::comment_parser_t> &option)
|
||||
@@ -403,6 +420,7 @@ template <> struct convert<class_diagram> {
|
||||
get_option(node, rhs.include_relations_also_as_members);
|
||||
get_option(node, rhs.generate_method_arguments);
|
||||
get_option(node, rhs.generate_packages);
|
||||
get_option(node, rhs.package_type);
|
||||
get_option(node, rhs.relationship_hints);
|
||||
get_option(node, rhs.type_aliases);
|
||||
get_option(node, rhs.relative_to);
|
||||
@@ -597,6 +615,7 @@ template <> struct convert<config> {
|
||||
get_option(node, rhs.puml);
|
||||
get_option(node, rhs.generate_method_arguments);
|
||||
get_option(node, rhs.generate_packages);
|
||||
get_option(node, rhs.package_type);
|
||||
get_option(node, rhs.generate_links);
|
||||
get_option(node, rhs.generate_system_headers);
|
||||
get_option(node, rhs.git);
|
||||
|
||||
Reference in New Issue
Block a user