Added package diagram test case with C++20 module partitions

This commit is contained in:
Bartek Kryza
2023-12-23 19:23:40 +01:00
parent bf7b69bcca
commit 453f265feb
14 changed files with 191 additions and 10 deletions

View File

@@ -301,7 +301,8 @@ tvl::value_t modules_filter::match(
if (!e.module().has_value())
return {false};
auto module_toks = util::split(e.module().value(), ".", true); // NOLINT
auto module_toks =
path::split(e.module().value(), path_type::kModule); // NOLINT
if (dynamic_cast<const package *>(&e) != nullptr &&
e.get_namespace().type() == path_type::kModule) {
@@ -312,7 +313,8 @@ tvl::value_t modules_filter::match(
[&e, &module_toks](const auto &modit) {
if (std::holds_alternative<std::string>(modit.value())) {
const auto &modit_str = std::get<std::string>(modit.value());
const auto modit_toks = util::split(modit_str, ".", true);
const auto modit_toks =
path::split(modit_str, path_type::kModule);
return e.module() == modit_str ||
util::starts_with(module_toks, modit_toks);

View File

@@ -39,8 +39,6 @@ class element : public diagram_element {
public:
element(namespace_ using_namespace, path_type pt = path_type::kNamespace);
element(path_type pt);
~element() override = default;
/**

View File

@@ -50,9 +50,9 @@ class path {
*
* @return Path separator
*/
const char *separator() const
static const char *separator(path_type pt)
{
switch (path_type_) {
switch (pt) {
case path_type::kNamespace:
return "::";
case path_type::kModule:
@@ -68,9 +68,38 @@ class path {
return "::";
}
/**
* Returns the path separator based on the type of the instance path.
*
* @return Path separator
*/
const char *separator() const { return separator(path_type_); }
public:
using container_type = std::vector<std::string>;
static container_type split(
const std::string &ns, path_type pt = path_type::kNamespace)
{
container_type result;
if (pt == path_type::kModule) {
auto path_toks = util::split(ns, separator(pt));
for (const auto &pt : path_toks) {
const auto subtoks = util::split(pt, ":");
if (subtoks.size() == 2) {
result.push_back(subtoks.at(0));
result.push_back(fmt::format(":{}", subtoks.at(1)));
}
else
result.push_back(subtoks.at(0));
}
}
else
result = util::split(ns, separator(pt));
return result;
}
path(path_type pt = path_type::kNamespace)
: path_type_{pt}
{
@@ -82,7 +111,7 @@ public:
if (ns.empty())
return;
path_ = util::split(ns, separator());
path_ = split(ns, pt);
}
virtual ~path() = default;
@@ -163,7 +192,14 @@ public:
*/
std::string to_string() const
{
return fmt::format("{}", fmt::join(path_, std::string{separator()}));
auto result =
fmt::format("{}", fmt::join(path_, std::string{separator()}));
if (path_type_ == path_type::kModule) {
util::replace_all(result, ".:", ":");
}
return result;
}
/**

View File

@@ -277,10 +277,14 @@ std::vector<std::string> diagram::make_module_relative(
if (!maybe_module)
return {};
auto module_path = util::split(maybe_module.value(), ".");
auto module_path = common::model::path(
maybe_module.value(), common::model::path_type::kModule)
.tokens();
if (using_module.has_value) {
auto using_module_path = util::split(using_module(), ".");
auto using_module_path = common::model::path(
using_module(), common::model::path_type::kModule)
.tokens();
if (util::starts_with(module_path, using_module_path)) {
util::remove_prefix(module_path, using_module_path);