diff --git a/src/puml/class_diagram_generator.h b/src/puml/class_diagram_generator.h index 08dd096a..d00a1ea3 100644 --- a/src/puml/class_diagram_generator.h +++ b/src/puml/class_diagram_generator.h @@ -142,6 +142,9 @@ public: void generate(const class_ &c, std::ostream &ostr) const { + + const auto uns = m_config.using_namespace; + std::string class_type{"class"}; if (c.is_abstract()) class_type = "abstract"; @@ -187,7 +190,7 @@ public: if (m.is_defaulted) ostr << " = default"; - ostr << " : " << ns_relative(m_config.using_namespace, type); + ostr << " : " << ns_relative(uns, type); ostr << std::endl; } @@ -203,7 +206,7 @@ public: ostr << "{static} "; ostr << to_string(m.scope) << m.name << " : " - << ns_relative(m_config.using_namespace, m.type) << std::endl; + << ns_relative(uns, m.type) << std::endl; } ostr << "}" << std::endl; @@ -212,11 +215,9 @@ public: for (const auto &b : c.bases) { std::stringstream relstr; try { - relstr << m_model.to_alias(m_config.using_namespace, - ns_relative(m_config.using_namespace, b.name)) + relstr << m_model.to_alias(uns, ns_relative(uns, b.name)) << " <|-- " - << m_model.to_alias(m_config.using_namespace, - ns_relative(m_config.using_namespace, c.name)) + << m_model.to_alias(uns, ns_relative(uns, c.name)) << std::endl; ostr << relstr.str(); } @@ -237,8 +238,7 @@ public: try { if (r.destination.find("#") != std::string::npos || r.destination.find("@") != std::string::npos) { - destination = m_model.usr_to_name( - m_config.using_namespace, r.destination); + destination = m_model.usr_to_name(uns, r.destination); // If something went wrong and we have an empty destination // generate the relationship but comment it out for @@ -252,13 +252,10 @@ public: destination = r.destination; } - relstr << m_model.to_alias(m_config.using_namespace, - ns_relative(m_config.using_namespace, - c.full_name(m_config.using_namespace))) + relstr << m_model.to_alias( + uns, ns_relative(uns, c.full_name(uns))) << " " << to_string(r.type) << " " - << m_model.to_alias(m_config.using_namespace, - ns_relative( - m_config.using_namespace, destination)); + << m_model.to_alias(uns, ns_relative(uns, destination)); if (!r.label.empty()) relstr << " : " << r.label; @@ -269,8 +266,7 @@ public: catch (error::uml_alias_missing &e) { LOG_ERROR("Skipping {} relation from {} to {} due " "to: {}", - to_string(r.type), c.full_name(m_config.using_namespace), - destination, e.what()); + to_string(r.type), c.full_name(uns), destination, e.what()); } } } diff --git a/src/uml/class_diagram_visitor.cc b/src/uml/class_diagram_visitor.cc index 731ab0dd..2bade83c 100644 --- a/src/uml/class_diagram_visitor.cc +++ b/src/uml/class_diagram_visitor.cc @@ -535,7 +535,7 @@ void tu_visitor::process_field_with_template_instantiation( mv.type().kind() == cppast::cpp_type_kind::reference_t) rr.type = relationship_t::kAssociation; else - rr.type = relationship_t::kComposition; + rr.type = relationship_t::kAggregation; rr.label = mv.name(); LOG_DBG("Adding field instantiation relationship {} {} {} : {}", rr.destination, model::class_diagram::to_string(rr.type), c.usr, @@ -956,7 +956,7 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_, if (t.kind() == cppast::cpp_type_kind::array_t) { auto &a = static_cast(t); find_relationships( - a.value_type(), relationships, relationship_t::kComposition); + a.value_type(), relationships, relationship_t::kAggregation); return; } @@ -981,7 +981,7 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_, // container list if (name.find("std::unique_ptr") == 0) { find_relationships(args[0u].type().value(), relationships, - relationship_t::kComposition); + relationship_t::kAggregation); } else if (name.find("std::shared_ptr") == 0) { find_relationships(args[0u].type().value(), relationships, @@ -993,7 +993,7 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_, } else if (name.find("std::vector") == 0) { find_relationships(args[0u].type().value(), relationships, - relationship_t::kComposition); + relationship_t::kAggregation); } else { for (const auto &arg : args) { @@ -1014,7 +1014,7 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_, auto &r = static_cast(t_); auto rt = relationship_t::kAssociation; if (r.reference_kind() == cppast::cpp_reference::cpp_ref_rvalue) { - rt = relationship_t::kComposition; + rt = relationship_t::kAggregation; } if (relationship_hint == relationship_t::kDependency) rt = relationship_hint; @@ -1030,7 +1030,7 @@ void tu_visitor::find_relationships(const cppast::cpp_type &t_, cppast::to_string(t), relationship_type); else relationships.emplace_back( - cppast::to_string(t), relationship_t::kComposition); + cppast::to_string(t), relationship_t::kAggregation); } // Check if t_ has an alias in the alias index diff --git a/tests/t00005/test_case.h b/tests/t00005/test_case.h index f8bfc865..c3706fe8 100644 --- a/tests/t00005/test_case.h +++ b/tests/t00005/test_case.h @@ -61,12 +61,12 @@ TEST_CASE("t00005", "[test-case][class]") REQUIRE_THAT(puml, (IsField("some_int_pointer", "int*"))); REQUIRE_THAT(puml, (IsField("some_int_pointer_pointer", "int**"))); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("A"), "a")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("A"), "a")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("B"), "b")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("C"), "c")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("D"), "d")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("E"), "e")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("F"), "f")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("F"), "f")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("G"), "g")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("H"), "h")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("I"), "i")); diff --git a/tests/t00006/test_case.h b/tests/t00006/test_case.h index 65d6f490..75e35d4b 100644 --- a/tests/t00006/test_case.h +++ b/tests/t00006/test_case.h @@ -65,22 +65,22 @@ TEST_CASE("t00006", "[test-case][class]") REQUIRE_THAT(puml, IsInstantiation(_A("custom_container"), _A("custom_container"))); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("A"), "a")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("A"), "a")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("B"), "b")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("C"), "c")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("C"), "c")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("D"), "d")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("custom_container"), "e")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("F"), "f")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("custom_container"), "e")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("F"), "f")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("G"), "g")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("H"), "h")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("H"), "h")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("I"), "i")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("J"), "j")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("J"), "j")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("K"), "k")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("L"), "lm")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("M"), "lm")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("N"), "ns")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("NN"), "ns")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("NNN"), "ns")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("L"), "lm")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("M"), "lm")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("N"), "ns")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("NN"), "ns")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("NNN"), "ns")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml); diff --git a/tests/t00007/test_case.h b/tests/t00007/test_case.h index 5d188ec6..948afe32 100644 --- a/tests/t00007/test_case.h +++ b/tests/t00007/test_case.h @@ -50,7 +50,7 @@ TEST_CASE("t00007", "[test-case][class]") REQUIRE_THAT(puml, IsClass(_A("C"))); REQUIRE_THAT(puml, IsClass(_A("R"))); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("A"), "a")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("A"), "a")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("B"), "b")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("C"), "c")); diff --git a/tests/t00009/test_case.h b/tests/t00009/test_case.h index 22d67ed0..1cd8d33e 100644 --- a/tests/t00009/test_case.h +++ b/tests/t00009/test_case.h @@ -54,7 +54,7 @@ TEST_CASE("t00009", "[test-case][class]") REQUIRE_THAT(puml, IsInstantiation(_A("A"), _A("A"))); REQUIRE_THAT(puml, IsInstantiation(_A("A"), _A("A"))); - REQUIRE_THAT(puml, IsComposition(_A("B"), _A("A"), "aint")); + REQUIRE_THAT(puml, IsAggregation(_A("B"), _A("A"), "aint")); REQUIRE_THAT(puml, IsAssociation(_A("B"), _A("A"), "astring")); REQUIRE_THAT(puml, IsAssociation(_A("B"), _A("A>"), "avector")); diff --git a/tests/t00010/test_case.h b/tests/t00010/test_case.h index e699e378..ad68f487 100644 --- a/tests/t00010/test_case.h +++ b/tests/t00010/test_case.h @@ -52,8 +52,8 @@ TEST_CASE("t00010", "[test-case][class]") REQUIRE_THAT(puml, IsInstantiation(_A("B"), _A("B"))); REQUIRE_THAT( - puml, IsComposition(_A("B"), _A("A"), "astring")); - REQUIRE_THAT(puml, IsComposition(_A("C"), _A("B"), "aintstring")); + puml, IsAggregation(_A("B"), _A("A"), "astring")); + REQUIRE_THAT(puml, IsAggregation(_A("C"), _A("B"), "aintstring")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml); diff --git a/tests/t00013/test_case.h b/tests/t00013/test_case.h index e9109c69..00e1acd3 100644 --- a/tests/t00013/test_case.h +++ b/tests/t00013/test_case.h @@ -56,7 +56,7 @@ TEST_CASE("t00013", "[test-case][class]") REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E"))); REQUIRE_THAT(puml, IsInstantiation(_A("E"), _A("E"))); REQUIRE_THAT(puml, IsInstantiation(_A("E"), _A("E"))); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("E"), "estring")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("E"), "estring")); REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F"))); REQUIRE_THAT(puml, IsInstantiation(_A("ABCD::F"), _A("ABCD::F"))); REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F"))); diff --git a/tests/t00014/test_case.h b/tests/t00014/test_case.h index ff674d17..1f82924e 100644 --- a/tests/t00014/test_case.h +++ b/tests/t00014/test_case.h @@ -52,11 +52,11 @@ TEST_CASE("t00014", "[test-case][class]") REQUIRE_THAT( puml, IsInstantiation(_A("A"), _A("AString"))); REQUIRE_THAT( - puml, IsComposition(_A("R"), _A("A"), "boolstring")); + puml, IsAggregation(_A("R"), _A("A"), "boolstring")); REQUIRE_THAT( - puml, IsComposition(_A("R"), _A("AString"), "floatstring")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("B"), "bs")); - REQUIRE_THAT(puml, IsComposition(_A("R"), _A("B"), "bs2")); + puml, IsAggregation(_A("R"), _A("AString"), "floatstring")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "bs")); + REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "bs2")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml);