Fixed package generation in class diagrams
This commit is contained in:
@@ -210,7 +210,7 @@ void generator::generate(
|
|||||||
<< " <|-- "
|
<< " <|-- "
|
||||||
<< m_model.to_alias(ns_relative(uns, c.full_name()))
|
<< m_model.to_alias(ns_relative(uns, c.full_name()))
|
||||||
<< '\n';
|
<< '\n';
|
||||||
ostr << relstr.str();
|
all_relations_str << relstr.str();
|
||||||
}
|
}
|
||||||
catch (error::uml_alias_missing &e) {
|
catch (error::uml_alias_missing &e) {
|
||||||
LOG_ERROR("=== Skipping inheritance relation from {} to {} due "
|
LOG_ERROR("=== Skipping inheritance relation from {} to {} due "
|
||||||
@@ -300,15 +300,17 @@ void generator::generate(const package &p, std::ostream &ostr,
|
|||||||
|
|
||||||
for (const auto &subpackage : p) {
|
for (const auto &subpackage : p) {
|
||||||
if (dynamic_cast<package *>(subpackage.get())) {
|
if (dynamic_cast<package *>(subpackage.get())) {
|
||||||
generate(
|
// TODO: add option - generate_empty_packages
|
||||||
dynamic_cast<package &>(*subpackage), ostr, relationships_ostr);
|
const auto &sp = dynamic_cast<package &>(*subpackage);
|
||||||
|
if (!sp.is_empty())
|
||||||
|
generate(sp, ostr, relationships_ostr);
|
||||||
}
|
}
|
||||||
if (dynamic_cast<class_ *>(subpackage.get())) {
|
else if (dynamic_cast<class_ *>(subpackage.get())) {
|
||||||
generate_alias(dynamic_cast<class_ &>(*subpackage), ostr);
|
generate_alias(dynamic_cast<class_ &>(*subpackage), ostr);
|
||||||
generate(
|
generate(
|
||||||
dynamic_cast<class_ &>(*subpackage), ostr, relationships_ostr);
|
dynamic_cast<class_ &>(*subpackage), ostr, relationships_ostr);
|
||||||
}
|
}
|
||||||
if (dynamic_cast<enum_ *>(subpackage.get())) {
|
else if (dynamic_cast<enum_ *>(subpackage.get())) {
|
||||||
generate_alias(dynamic_cast<enum_ &>(*subpackage), ostr);
|
generate_alias(dynamic_cast<enum_ &>(*subpackage), ostr);
|
||||||
generate(
|
generate(
|
||||||
dynamic_cast<enum_ &>(*subpackage), ostr, relationships_ostr);
|
dynamic_cast<enum_ &>(*subpackage), ostr, relationships_ostr);
|
||||||
@@ -326,26 +328,28 @@ void generator::generate(std::ostream &ostr) const
|
|||||||
{
|
{
|
||||||
ostr << "@startuml" << '\n';
|
ostr << "@startuml" << '\n';
|
||||||
|
|
||||||
std::stringstream relationship_ostr;
|
std::stringstream relationships_ostr;
|
||||||
|
|
||||||
generate_plantuml_directives(ostr, m_config.puml().before);
|
generate_plantuml_directives(ostr, m_config.puml().before);
|
||||||
|
|
||||||
for (const auto &p : m_model) {
|
for (const auto &p : m_model) {
|
||||||
if (dynamic_cast<package *>(p.get())) {
|
if (dynamic_cast<package *>(p.get())) {
|
||||||
generate(dynamic_cast<package &>(*p), ostr, relationship_ostr);
|
const auto &sp = dynamic_cast<package &>(*p);
|
||||||
|
if (!sp.is_empty())
|
||||||
|
generate(sp, ostr, relationships_ostr);
|
||||||
}
|
}
|
||||||
if (dynamic_cast<class_ *>(p.get())) {
|
else if (dynamic_cast<class_ *>(p.get())) {
|
||||||
generate_alias(dynamic_cast<class_ &>(*p), ostr);
|
generate_alias(dynamic_cast<class_ &>(*p), ostr);
|
||||||
generate(dynamic_cast<class_ &>(*p), ostr, relationship_ostr);
|
generate(dynamic_cast<class_ &>(*p), ostr, relationships_ostr);
|
||||||
}
|
}
|
||||||
if (dynamic_cast<enum_ *>(p.get())) {
|
else if (dynamic_cast<enum_ *>(p.get())) {
|
||||||
generate_alias(dynamic_cast<enum_ &>(*p), ostr);
|
generate_alias(dynamic_cast<enum_ &>(*p), ostr);
|
||||||
generate(dynamic_cast<enum_ &>(*p), ostr, relationship_ostr);
|
generate(dynamic_cast<enum_ &>(*p), ostr, relationships_ostr);
|
||||||
}
|
}
|
||||||
ostr << '\n';
|
ostr << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
ostr << relationship_ostr.str();
|
ostr << relationships_ostr.str();
|
||||||
|
|
||||||
generate_config_layout_hints(ostr);
|
generate_config_layout_hints(ostr);
|
||||||
|
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ void translation_unit_visitor::process_namespace(
|
|||||||
|
|
||||||
auto usn = util::split(ctx.config().using_namespace()[0], "::");
|
auto usn = util::split(ctx.config().using_namespace()[0], "::");
|
||||||
|
|
||||||
if (!util::starts_with(usn, package_path)) {
|
if (ctx.config().should_include_package(util::join(package_path, "::"))) {
|
||||||
auto p = std::make_unique<common::model::package>(usn);
|
auto p = std::make_unique<common::model::package>(usn);
|
||||||
util::remove_prefix(package_path, usn);
|
util::remove_prefix(package_path, usn);
|
||||||
|
|
||||||
@@ -362,6 +362,7 @@ void translation_unit_visitor::process_class_declaration(
|
|||||||
fmt::ptr(reinterpret_cast<const void *>(&cls)));
|
fmt::ptr(reinterpret_cast<const void *>(&cls)));
|
||||||
|
|
||||||
assert(c_ptr);
|
assert(c_ptr);
|
||||||
|
if (ctx.config().should_include(c.full_name(false)))
|
||||||
ctx.diagram().add_class(std::move(c_ptr));
|
ctx.diagram().add_class(std::move(c_ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1105,6 +1106,7 @@ void translation_unit_visitor::
|
|||||||
|
|
||||||
c.add_relationship(std::move(rr));
|
c.add_relationship(std::move(rr));
|
||||||
|
|
||||||
|
if (ctx.config().should_include(c.full_name(false)))
|
||||||
ctx.diagram().add_class(std::move(tinst_ptr));
|
ctx.diagram().add_class(std::move(tinst_ptr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,8 @@ public:
|
|||||||
elements_.end();
|
elements_.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_empty() const { return elements_.empty(); }
|
||||||
|
|
||||||
auto begin() { return elements_.begin(); }
|
auto begin() { return elements_.begin(); }
|
||||||
auto end() { return elements_.end(); }
|
auto end() { return elements_.end(); }
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,31 @@ bool diagram::should_include(const std::string &name_) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool diagram::should_include_package(const std::string &name) const
|
||||||
|
{
|
||||||
|
|
||||||
|
for (const auto &ex : exclude().namespaces) {
|
||||||
|
if (name.find(ex) == 0) {
|
||||||
|
LOG_DBG("Skipping from diagram: {}", name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no inclusive namespaces are provided,
|
||||||
|
// allow all
|
||||||
|
if (include().namespaces.empty())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for (const auto &in : include().namespaces) {
|
||||||
|
if (in.find(name) == 0 || name.find(in) == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DBG("Skipping from diagram: {}", name);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool diagram::should_include(const clanguml::common::model::scope_t scope) const
|
bool diagram::should_include(const clanguml::common::model::scope_t scope) const
|
||||||
{
|
{
|
||||||
for (const auto &s : exclude().scopes) {
|
for (const auto &s : exclude().scopes) {
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ struct diagram : public inheritable_diagram_options {
|
|||||||
|
|
||||||
bool should_include_relationship(const std::string &rel);
|
bool should_include_relationship(const std::string &rel);
|
||||||
|
|
||||||
|
bool should_include_package(const std::string &name) const;
|
||||||
|
|
||||||
bool should_include(
|
bool should_include(
|
||||||
const std::pair<std::vector<std::string>, std::string> &name) const;
|
const std::pair<std::vector<std::string>, std::string> &name) const;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
type: class
|
type: class
|
||||||
include_relations_also_as_members: false
|
include_relations_also_as_members: false
|
||||||
generate_method_arguments: none
|
generate_method_arguments: none
|
||||||
|
generate_packages: true
|
||||||
glob:
|
glob:
|
||||||
- src/common/model/*.h
|
- src/common/model/*.h
|
||||||
- src/common/model/*.cc
|
- src/common/model/*.cc
|
||||||
@@ -11,7 +12,7 @@ include:
|
|||||||
- clanguml::common::model
|
- clanguml::common::model
|
||||||
- clanguml::class_diagram::model
|
- clanguml::class_diagram::model
|
||||||
using_namespace:
|
using_namespace:
|
||||||
- clanguml::class_diagram::model
|
- clanguml
|
||||||
plantuml:
|
plantuml:
|
||||||
before:
|
before:
|
||||||
- 'title clang-uml class diagram model'
|
- 'title clang-uml class diagram model'
|
||||||
Reference in New Issue
Block a user