Added scope symbol in front of relationships

This commit is contained in:
Bartek Kryza
2021-07-24 18:46:02 +02:00
parent f9bc218d90
commit ae5f2b2006
13 changed files with 62 additions and 46 deletions

View File

@@ -258,7 +258,7 @@ public:
<< m_model.to_alias(uns, ns_relative(uns, destination)); << m_model.to_alias(uns, ns_relative(uns, destination));
if (!r.label.empty()) if (!r.label.empty())
relstr << " : " << r.label; relstr << " : " << to_string(r.scope) << r.label;
relstr << std::endl; relstr << std::endl;
ostr << relstr.str(); ostr << relstr.str();

View File

@@ -36,7 +36,7 @@ namespace clanguml {
namespace model { namespace model {
namespace class_diagram { namespace class_diagram {
enum class scope_t { kPublic, kProtected, kPrivate }; enum class scope_t { kPublic, kProtected, kPrivate, kNone };
enum class relationship_t { enum class relationship_t {
kNone, kNone,
@@ -121,6 +121,7 @@ struct class_relationship {
std::string cardinality_source; std::string cardinality_source;
std::string cardinality_destination; std::string cardinality_destination;
std::string label; std::string label;
scope_t scope{scope_t::kNone};
friend bool operator==( friend bool operator==(
const class_relationship &l, const class_relationship &r) const class_relationship &l, const class_relationship &r)

View File

@@ -171,6 +171,7 @@ void tu_visitor::operator()(const cppast::cpp_entity &file)
r.destination = tinst.base_template_usr; r.destination = tinst.base_template_usr;
r.type = relationship_t::kInstantiation; r.type = relationship_t::kInstantiation;
r.label = ""; r.label = "";
r.scope = scope_t::kNone;
tinst.add_relationship(std::move(r)); tinst.add_relationship(std::move(r));
LOG_DBG("Created template instantiation: {}, {}, {}", LOG_DBG("Created template instantiation: {}, {}, {}",
@@ -206,6 +207,7 @@ void tu_visitor::process_enum_declaration(const cppast::cpp_enum &enm)
containment.type = relationship_t::kContainment; containment.type = relationship_t::kContainment;
containment.destination = containment.destination =
cx::util::full_name(ctx.namespace_, cur.value()); cx::util::full_name(ctx.namespace_, cur.value());
containment.scope = scope_t::kNone;
e.relationships.emplace_back(std::move(containment)); e.relationships.emplace_back(std::move(containment));
LOG_DBG("Added relationship {} +-- {}", e.name, LOG_DBG("Added relationship {} +-- {}", e.name,
@@ -398,6 +400,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls,
r.type = relationship_t::kInstantiation; r.type = relationship_t::kInstantiation;
r.label = ""; r.label = "";
r.destination = base_template_usr; r.destination = base_template_usr;
r.scope = scope_t::kNone;
c.add_relationship(std::move(r)); c.add_relationship(std::move(r));
} }
else { else {
@@ -484,7 +487,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls,
void tu_visitor::process_field_with_template_instantiation( void tu_visitor::process_field_with_template_instantiation(
const cppast::cpp_member_variable &mv, const cppast::cpp_type &tr, const cppast::cpp_member_variable &mv, const cppast::cpp_type &tr,
class_ &c) class_ &c, cppast::cpp_access_specifier_kind as)
{ {
LOG_DBG("Processing field with template instatiation type {}", LOG_DBG("Processing field with template instatiation type {}",
cppast::to_string(tr)); cppast::to_string(tr));
@@ -527,6 +530,7 @@ void tu_visitor::process_field_with_template_instantiation(
} }
r.type = relationship_t::kInstantiation; r.type = relationship_t::kInstantiation;
r.label = ""; r.label = "";
r.scope = scope_t::kNone;
tinst.add_relationship(std::move(r)); tinst.add_relationship(std::move(r));
class_relationship rr; class_relationship rr;
@@ -537,9 +541,12 @@ void tu_visitor::process_field_with_template_instantiation(
else else
rr.type = relationship_t::kAggregation; rr.type = relationship_t::kAggregation;
rr.label = mv.name(); rr.label = mv.name();
rr.scope = detail::cpp_access_specifier_to_scope(as);
LOG_DBG("Adding field instantiation relationship {} {} {} : {}", LOG_DBG("Adding field instantiation relationship {} {} {} : {}",
rr.destination, model::class_diagram::to_string(rr.type), c.usr, rr.destination, model::class_diagram::to_string(rr.type), c.usr,
rr.label); rr.label);
c.add_relationship(std::move(rr)); c.add_relationship(std::move(rr));
LOG_DBG("Created template instantiation: {}, {}", tinst.name, LOG_DBG("Created template instantiation: {}, {}", tinst.name,
@@ -572,7 +579,7 @@ void tu_visitor::process_field(const cppast::cpp_member_variable &mv, class_ &c,
cppast::to_string(tr), mv.name()); cppast::to_string(tr), mv.name());
} }
else if (tr.kind() == cppast::cpp_type_kind::template_instantiation_t) { else if (tr.kind() == cppast::cpp_type_kind::template_instantiation_t) {
process_field_with_template_instantiation(mv, resolve_alias(tr), c); process_field_with_template_instantiation(mv, resolve_alias(tr), c, as);
} }
else if (tr.kind() == cppast::cpp_type_kind::unexposed_t) { else if (tr.kind() == cppast::cpp_type_kind::unexposed_t) {
LOG_DBG( LOG_DBG(
@@ -592,6 +599,7 @@ void tu_visitor::process_field(const cppast::cpp_member_variable &mv, class_ &c,
r.destination = type; r.destination = type;
r.type = relationship_type; r.type = relationship_type;
r.label = m.name; r.label = m.name;
r.scope = m.scope;
LOG_DBG("Adding field relationship {} {} {} : {}", LOG_DBG("Adding field relationship {} {} {} : {}",
r.destination, model::class_diagram::to_string(r.type), r.destination, model::class_diagram::to_string(r.type),

View File

@@ -165,7 +165,8 @@ public:
void process_field_with_template_instantiation( void process_field_with_template_instantiation(
const cppast::cpp_member_variable &mv, const cppast::cpp_type &tr, const cppast::cpp_member_variable &mv, const cppast::cpp_type &tr,
clanguml::model::class_diagram::class_ &c); clanguml::model::class_diagram::class_ &c,
cppast::cpp_access_specifier_kind as);
void process_static_field(const cppast::cpp_variable &mv, void process_static_field(const cppast::cpp_variable &mv,
clanguml::model::class_diagram::class_ &c, clanguml::model::class_diagram::class_ &c,

View File

@@ -53,7 +53,7 @@ TEST_CASE("t00002", "[test-case][class]")
REQUIRE_THAT(puml, (IsMethod<Public, Abstract>("foo_a"))); REQUIRE_THAT(puml, (IsMethod<Public, Abstract>("foo_a")));
REQUIRE_THAT(puml, (IsMethod<Public, Abstract>("foo_c"))); REQUIRE_THAT(puml, (IsMethod<Public, Abstract>("foo_c")));
REQUIRE_THAT(puml, IsAssociation(_A("D"), _A("A"), "as")); REQUIRE_THAT(puml, IsAssociation(_A("D"), _A("A"), "-as"));
save_puml( save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml); "./" + config.output_directory + "/" + diagram->name + ".puml", puml);

View File

@@ -61,17 +61,17 @@ TEST_CASE("t00005", "[test-case][class]")
REQUIRE_THAT(puml, (IsField<Public>("some_int_pointer", "int*"))); REQUIRE_THAT(puml, (IsField<Public>("some_int_pointer", "int*")));
REQUIRE_THAT(puml, (IsField<Public>("some_int_pointer_pointer", "int**"))); REQUIRE_THAT(puml, (IsField<Public>("some_int_pointer_pointer", "int**")));
REQUIRE_THAT(puml, IsAggregation(_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("B"), "+b"));
REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("C"), "c")); 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("D"), "+d"));
REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("E"), "e")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("E"), "+e"));
REQUIRE_THAT(puml, IsAggregation(_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("G"), "+g"));
REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("H"), "h")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("H"), "+h"));
REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("I"), "i")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("I"), "+i"));
REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("J"), "j")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("J"), "+j"));
REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("K"), "k")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("K"), "+k"));
save_puml( save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml); "./" + config.output_directory + "/" + diagram->name + ".puml", puml);

View File

@@ -65,22 +65,22 @@ TEST_CASE("t00006", "[test-case][class]")
REQUIRE_THAT(puml, REQUIRE_THAT(puml,
IsInstantiation(_A("custom_container<T>"), _A("custom_container<E>"))); IsInstantiation(_A("custom_container<T>"), _A("custom_container<E>")));
REQUIRE_THAT(puml, IsAggregation(_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("B"), "+b"));
REQUIRE_THAT(puml, IsAggregation(_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, IsAssociation(_A("R"), _A("D"), "+d"));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("custom_container<E>"), "e")); REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("custom_container<E>"), "+e"));
REQUIRE_THAT(puml, IsAggregation(_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("G"), "+g"));
REQUIRE_THAT(puml, IsAggregation(_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, IsAssociation(_A("R"), _A("I"), "+i"));
REQUIRE_THAT(puml, IsAggregation(_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, IsAssociation(_A("R"), _A("K"), "+k"));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("L"), "lm")); 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("M"), "+lm"));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("N"), "ns")); 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("NN"), "+ns"));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("NNN"), "ns")); REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("NNN"), "+ns"));
save_puml( save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml); "./" + config.output_directory + "/" + diagram->name + ".puml", puml);

View File

@@ -50,9 +50,9 @@ TEST_CASE("t00007", "[test-case][class]")
REQUIRE_THAT(puml, IsClass(_A("C"))); REQUIRE_THAT(puml, IsClass(_A("C")));
REQUIRE_THAT(puml, IsClass(_A("R"))); REQUIRE_THAT(puml, IsClass(_A("R")));
REQUIRE_THAT(puml, IsAggregation(_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("B"), "+b"));
REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("C"), "c")); REQUIRE_THAT(puml, IsAssociation(_A("R"), _A("C"), "+c"));
save_puml( save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml); "./" + config.output_directory + "/" + diagram->name + ".puml", puml);

View File

@@ -54,10 +54,11 @@ TEST_CASE("t00009", "[test-case][class]")
REQUIRE_THAT(puml, IsInstantiation(_A("A<T>"), _A("A<int>"))); REQUIRE_THAT(puml, IsInstantiation(_A("A<T>"), _A("A<int>")));
REQUIRE_THAT(puml, IsInstantiation(_A("A<T>"), _A("A<std::string>"))); REQUIRE_THAT(puml, IsInstantiation(_A("A<T>"), _A("A<std::string>")));
REQUIRE_THAT(puml, IsAggregation(_A("B"), _A("A<int>"), "aint")); REQUIRE_THAT(puml, IsAggregation(_A("B"), _A("A<int>"), "+aint"));
REQUIRE_THAT(puml, IsAssociation(_A("B"), _A("A<std::string>"), "astring")); REQUIRE_THAT(
puml, IsAssociation(_A("B"), _A("A<std::string>"), "+astring"));
REQUIRE_THAT(puml, REQUIRE_THAT(puml,
IsAssociation(_A("B"), _A("A<std::vector<std::string>>"), "avector")); IsAssociation(_A("B"), _A("A<std::vector<std::string>>"), "+avector"));
save_puml( save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml); "./" + config.output_directory + "/" + diagram->name + ".puml", puml);

View File

@@ -52,8 +52,8 @@ TEST_CASE("t00010", "[test-case][class]")
REQUIRE_THAT(puml, IsInstantiation(_A("B<T>"), _A("B<int>"))); REQUIRE_THAT(puml, IsInstantiation(_A("B<T>"), _A("B<int>")));
REQUIRE_THAT( REQUIRE_THAT(
puml, IsAggregation(_A("B<T>"), _A("A<T,std::string>"), "astring")); puml, IsAggregation(_A("B<T>"), _A("A<T,std::string>"), "+astring"));
REQUIRE_THAT(puml, IsAggregation(_A("C"), _A("B<int>"), "aintstring")); REQUIRE_THAT(puml, IsAggregation(_A("C"), _A("B<int>"), "+aintstring"));
save_puml( save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml); "./" + config.output_directory + "/" + diagram->name + ".puml", puml);

View File

@@ -56,7 +56,8 @@ TEST_CASE("t00013", "[test-case][class]")
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E<int>"))); REQUIRE_THAT(puml, IsDependency(_A("R"), _A("E<int>")));
REQUIRE_THAT(puml, IsInstantiation(_A("E<T>"), _A("E<int>"))); REQUIRE_THAT(puml, IsInstantiation(_A("E<T>"), _A("E<int>")));
REQUIRE_THAT(puml, IsInstantiation(_A("E<T>"), _A("E<std::string>"))); REQUIRE_THAT(puml, IsInstantiation(_A("E<T>"), _A("E<std::string>")));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("E<std::string>"), "estring")); REQUIRE_THAT(
puml, IsAggregation(_A("R"), _A("E<std::string>"), "-estring"));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F<T>"))); REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F<T>")));
REQUIRE_THAT(puml, IsInstantiation(_A("ABCD::F<T>"), _A("ABCD::F<int>"))); REQUIRE_THAT(puml, IsInstantiation(_A("ABCD::F<T>"), _A("ABCD::F<int>")));
REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F<int>"))); REQUIRE_THAT(puml, IsDependency(_A("R"), _A("ABCD::F<int>")));

View File

@@ -48,7 +48,11 @@ class R {
AString<float> floatstring; AString<float> floatstring;
AIntString intstring; AIntString intstring;
AStringString stringstring; AStringString stringstring;
protected:
BVector bs; BVector bs;
public:
BVector2 bs2; BVector2 bs2;
GeneralCallback<AIntString> cb; GeneralCallback<AIntString> cb;
VoidCallback vcb; VoidCallback vcb;

View File

@@ -49,11 +49,11 @@ TEST_CASE("t00014", "[test-case][class]")
REQUIRE_THAT( REQUIRE_THAT(
puml, IsInstantiation(_A("A<T,std::string>"), _A("AString<float>"))); puml, IsInstantiation(_A("A<T,std::string>"), _A("AString<float>")));
REQUIRE_THAT( REQUIRE_THAT(
puml, IsAggregation(_A("R"), _A("A<bool,std::string>"), "boolstring")); puml, IsAggregation(_A("R"), _A("A<bool,std::string>"), "-boolstring"));
REQUIRE_THAT( REQUIRE_THAT(
puml, IsAggregation(_A("R"), _A("AString<float>"), "floatstring")); puml, IsAggregation(_A("R"), _A("AString<float>"), "-floatstring"));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "bs")); REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "#bs"));
REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "bs2")); REQUIRE_THAT(puml, IsAggregation(_A("R"), _A("B"), "+bs2"));
save_puml( save_puml(
"./" + config.output_directory + "/" + diagram->name + ".puml", puml); "./" + config.output_directory + "/" + diagram->name + ".puml", puml);