Added support for C++20 module based packages in class diagrams (#101)
This commit is contained in:
@@ -187,6 +187,7 @@ void inheritable_diagram_options::inherit(
|
||||
{
|
||||
glob.override(parent.glob);
|
||||
using_namespace.override(parent.using_namespace);
|
||||
using_module.override(parent.using_module);
|
||||
include_relations_also_as_members.override(
|
||||
parent.include_relations_also_as_members);
|
||||
include.override(parent.include);
|
||||
@@ -229,6 +230,12 @@ std::string inheritable_diagram_options::simplify_template_type(
|
||||
return full_name;
|
||||
}
|
||||
|
||||
bool inheritable_diagram_options::generate_fully_qualified_name() const
|
||||
{
|
||||
return generate_packages() &&
|
||||
(package_type() == package_type_t::kNamespace);
|
||||
}
|
||||
|
||||
std::vector<std::string> diagram::get_translation_units() const
|
||||
{
|
||||
std::vector<std::string> translation_units{};
|
||||
@@ -264,6 +271,25 @@ std::filesystem::path diagram::make_path_relative(
|
||||
return relative(p, root_directory()).lexically_normal().string();
|
||||
}
|
||||
|
||||
std::vector<std::string> diagram::make_module_relative(
|
||||
const std::optional<std::string> &maybe_module) const
|
||||
{
|
||||
if (!maybe_module)
|
||||
return {};
|
||||
|
||||
auto module_path = util::split(maybe_module.value(), ".");
|
||||
|
||||
if (using_module.has_value) {
|
||||
auto using_module_path = util::split(using_module(), ".");
|
||||
|
||||
if (util::starts_with(module_path, using_module_path)) {
|
||||
util::remove_prefix(module_path, using_module_path);
|
||||
}
|
||||
}
|
||||
|
||||
return module_path;
|
||||
}
|
||||
|
||||
std::optional<std::string> diagram::get_together_group(
|
||||
const std::string &full_name) const
|
||||
{
|
||||
|
||||
@@ -87,7 +87,8 @@ std::string to_string(callee_type mt);
|
||||
/*! How packages in diagrams should be generated */
|
||||
enum class package_type_t {
|
||||
kNamespace, /*!< From namespaces */
|
||||
kDirectory /*!< From directories */
|
||||
kDirectory, /*!< From directories */
|
||||
kModule /*!< From modules */
|
||||
};
|
||||
|
||||
std::string to_string(package_type_t mt);
|
||||
@@ -469,6 +470,18 @@ struct inheritable_diagram_options {
|
||||
|
||||
std::string simplify_template_type(std::string full_name) const;
|
||||
|
||||
/**
|
||||
* @brief Whether the diagram element should be fully qualified in diagram
|
||||
*
|
||||
* This method determines whether an elements' name should include
|
||||
* fully qualified namespace name (however relative to using_namespace), or
|
||||
* whether it should just contain it's name. This depends on whether the
|
||||
* diagram has packages and if they are based on namespaces or sth else.
|
||||
*
|
||||
* @return True, if element should include it's namespace
|
||||
*/
|
||||
bool generate_fully_qualified_name() const;
|
||||
|
||||
/**
|
||||
* @brief Get reference to `relative_to` diagram config option
|
||||
*
|
||||
@@ -483,6 +496,7 @@ struct inheritable_diagram_options {
|
||||
|
||||
option<std::vector<std::string>> glob{"glob"};
|
||||
option<common::model::namespace_> using_namespace{"using_namespace"};
|
||||
option<std::string> using_module{"using_module"};
|
||||
option<bool> include_relations_also_as_members{
|
||||
"include_relations_also_as_members", true};
|
||||
option<filter> include{"include"};
|
||||
@@ -566,6 +580,15 @@ struct diagram : public inheritable_diagram_options {
|
||||
std::filesystem::path make_path_relative(
|
||||
const std::filesystem::path &p) const;
|
||||
|
||||
/**
|
||||
* @brief Make module path relative to `using_module` configuration option
|
||||
*
|
||||
* @param p Input path
|
||||
* @return Relative path
|
||||
*/
|
||||
std::vector<std::string> make_module_relative(
|
||||
const std::optional<std::string> &maybe_module) const;
|
||||
|
||||
/**
|
||||
* @brief Returns absolute path of the `relative_to` option
|
||||
*
|
||||
|
||||
@@ -58,6 +58,7 @@ types:
|
||||
package_type_t: !variant
|
||||
- namespace
|
||||
- directory
|
||||
- module
|
||||
member_order_t: !variant
|
||||
- lexical
|
||||
- as_is
|
||||
@@ -161,6 +162,7 @@ types:
|
||||
cmd: !optional string
|
||||
relative_to: !optional string
|
||||
using_namespace: !optional [string, [string]]
|
||||
using_module: !optional string
|
||||
generate_metadata: !optional bool
|
||||
title: !optional string
|
||||
#
|
||||
@@ -239,6 +241,7 @@ types:
|
||||
cmd: !optional string
|
||||
relative_to: !optional string
|
||||
using_namespace: !optional [string, [string]]
|
||||
using_module: !optional string
|
||||
generate_metadata: !optional bool
|
||||
title: !optional string
|
||||
#
|
||||
@@ -318,6 +321,7 @@ root:
|
||||
cmd: !optional string
|
||||
relative_to: !optional string
|
||||
using_namespace: !optional [string, [string]]
|
||||
using_module: !optional string
|
||||
generate_metadata: !optional bool
|
||||
#
|
||||
# Inheritable custom options
|
||||
|
||||
@@ -133,6 +133,8 @@ void get_option<package_type_t>(
|
||||
option.set(package_type_t::kNamespace);
|
||||
else if (val == "directory")
|
||||
option.set(package_type_t::kDirectory);
|
||||
else if (val == "module")
|
||||
option.set(package_type_t::kModule);
|
||||
else
|
||||
throw std::runtime_error(
|
||||
"Invalid generate_method_arguments value: " + val);
|
||||
@@ -573,6 +575,7 @@ template <typename T> bool decode_diagram(const Node &node, T &rhs)
|
||||
// Decode options common for all diagrams
|
||||
get_option(node, rhs.glob);
|
||||
get_option(node, rhs.using_namespace);
|
||||
get_option(node, rhs.using_module);
|
||||
get_option(node, rhs.include);
|
||||
get_option(node, rhs.exclude);
|
||||
get_option(node, rhs.puml);
|
||||
@@ -787,6 +790,7 @@ template <> struct convert<config> {
|
||||
{
|
||||
get_option(node, rhs.glob);
|
||||
get_option(node, rhs.using_namespace);
|
||||
get_option(node, rhs.using_module);
|
||||
get_option(node, rhs.output_directory);
|
||||
get_option(node, rhs.compilation_database_dir);
|
||||
get_option(node, rhs.add_compile_flags);
|
||||
|
||||
@@ -310,6 +310,7 @@ YAML::Emitter &operator<<(
|
||||
out << c.puml;
|
||||
out << c.relative_to;
|
||||
out << c.using_namespace;
|
||||
out << c.using_module;
|
||||
out << c.generate_metadata;
|
||||
|
||||
if (const auto *cd = dynamic_cast<const class_diagram *>(&c);
|
||||
|
||||
Reference in New Issue
Block a user