Fixed relative package diagram generation based on using_namespace
This commit is contained in:
@@ -25,7 +25,6 @@ diagrams:
|
|||||||
## Source code
|
## Source code
|
||||||
File t30001.cc
|
File t30001.cc
|
||||||
```cpp
|
```cpp
|
||||||
|
|
||||||
namespace clanguml {
|
namespace clanguml {
|
||||||
namespace t30001 {
|
namespace t30001 {
|
||||||
namespace A {
|
namespace A {
|
||||||
@@ -48,8 +47,8 @@ namespace BBB {
|
|||||||
namespace BB {
|
namespace BB {
|
||||||
} // namespace BB
|
} // namespace BB
|
||||||
} // namespace B
|
} // namespace B
|
||||||
}
|
} // namespace t30001
|
||||||
}
|
} // namespace clanguml
|
||||||
|
|
||||||
```
|
```
|
||||||
## Generated UML diagrams
|
## Generated UML diagrams
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 8.8 KiB |
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* src/class_diagram/generators/plantuml/class_diagram_generator.cc
|
* src/package_diagram/generators/plantuml/package_diagram_generator.cc
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
|
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -79,7 +79,8 @@ std::string generator::name(relationship_t r) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generator::generate(const package &p, std::ostream &ostr) const
|
void generator::generate(
|
||||||
|
const package &p, std::ostream &ostr) const
|
||||||
{
|
{
|
||||||
const auto uns = m_config.using_namespace;
|
const auto uns = m_config.using_namespace;
|
||||||
|
|
||||||
@@ -143,12 +144,8 @@ void generator::generate(std::ostream &ostr) const
|
|||||||
std::string note{b};
|
std::string note{b};
|
||||||
std::tuple<std::string, size_t, size_t> alias_match;
|
std::tuple<std::string, size_t, size_t> alias_match;
|
||||||
while (util::find_element_alias(note, alias_match)) {
|
while (util::find_element_alias(note, alias_match)) {
|
||||||
auto full_name =
|
auto alias = m_model.to_alias(ns_relative(
|
||||||
fmt::format("{}::{}", fmt::join(m_config.using_namespace, "::"),
|
m_config.using_namespace, std::get<0>(alias_match)));
|
||||||
ns_relative(
|
|
||||||
m_config.using_namespace, std::get<0>(alias_match)));
|
|
||||||
|
|
||||||
auto alias = m_model.to_alias(full_name);
|
|
||||||
note.replace(
|
note.replace(
|
||||||
std::get<1>(alias_match), std::get<2>(alias_match), alias);
|
std::get<1>(alias_match), std::get<2>(alias_match), alias);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,12 +90,23 @@ void translation_unit_visitor::operator()(const cppast::cpp_entity &file)
|
|||||||
if (!ns_declaration.is_anonymous() &&
|
if (!ns_declaration.is_anonymous() &&
|
||||||
!ns_declaration.is_inline()) {
|
!ns_declaration.is_inline()) {
|
||||||
|
|
||||||
auto p = std::make_unique<package>(
|
auto package_path = ctx.get_namespace();
|
||||||
ctx.config().using_namespace);
|
package_path.push_back(e.name());
|
||||||
p->set_name(e.name());
|
|
||||||
p->set_namespace(ctx.get_namespace());
|
auto usn =
|
||||||
ctx.diagram().add_package(
|
util::split(ctx.config().using_namespace[0], "::");
|
||||||
ctx.get_namespace(), std::move(p));
|
|
||||||
|
if (!starts_with(usn, package_path)) {
|
||||||
|
auto p = std::make_unique<package>(
|
||||||
|
ctx.config().using_namespace);
|
||||||
|
remove_prefix(package_path, usn);
|
||||||
|
package_path.pop_back();
|
||||||
|
|
||||||
|
p->set_name(e.name());
|
||||||
|
p->set_namespace(package_path);
|
||||||
|
ctx.diagram().add_package(
|
||||||
|
package_path, std::move(p));
|
||||||
|
}
|
||||||
|
|
||||||
ctx.push_namespace(e.name());
|
ctx.push_namespace(e.name());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,4 +145,13 @@ bool starts_with(const std::vector<T> &col, const std::vector<T> &prefix)
|
|||||||
return std::vector<std::string>(prefix.begin(), prefix.end()) ==
|
return std::vector<std::string>(prefix.begin(), prefix.end()) ==
|
||||||
std::vector<std::string>(col.begin(), col.begin() + prefix.size());
|
std::vector<std::string>(col.begin(), col.begin() + prefix.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void remove_prefix(std::vector<T> &col, const std::vector<T> &prefix)
|
||||||
|
{
|
||||||
|
if(!starts_with(col, prefix))
|
||||||
|
return;
|
||||||
|
|
||||||
|
col = std::vector<T>(col.begin()+prefix.size(), col.end());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user