Added include_relations_also_as_members flag

This commit is contained in:
Bartek Kryza
2021-07-24 19:40:12 +02:00
parent adb1296aa5
commit ea8f0e83c1
10 changed files with 297 additions and 41 deletions

View File

@@ -165,6 +165,8 @@ struct class_diagram : public diagram {
virtual ~class_diagram() = default;
std::vector<std::string> classes;
bool include_relations_also_as_members{true};
bool has_class(std::string clazz)
{
for (const auto &c : classes) {
@@ -316,6 +318,11 @@ template <> struct convert<class_diagram> {
if (!decode_diagram(node, rhs))
return false;
if (node["include_relations_also_as_members"])
rhs.include_relations_also_as_members =
node["include_relations_also_as_members"]
.as<decltype(rhs.include_relations_also_as_members)>();
return true;
}
};

View File

@@ -195,6 +195,56 @@ public:
ostr << std::endl;
}
//
// Process relationships
//
std::set<std::string> rendered_relations;
std::stringstream all_relations_str;
for (const auto &r : c.relationships) {
if (!m_config.should_include_relationship(name(r.type)))
continue;
std::stringstream relstr;
std::string destination;
try {
if (r.destination.find("#") != std::string::npos ||
r.destination.find("@") != std::string::npos) {
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
// debugging
if (destination.empty()) {
relstr << "' ";
destination = r.destination;
}
}
else {
destination = r.destination;
}
relstr << m_model.to_alias(
uns, ns_relative(uns, c.full_name(uns)))
<< " " << to_string(r.type) << " "
<< m_model.to_alias(uns, ns_relative(uns, destination));
if (!r.label.empty()) {
relstr << " : " << to_string(r.scope) << r.label;
rendered_relations.emplace(r.label);
}
relstr << std::endl;
all_relations_str << relstr.str();
}
catch (error::uml_alias_missing &e) {
LOG_ERROR("Skipping {} relation from {} to {} due "
"to: {}",
to_string(r.type), c.full_name(uns), destination, e.what());
}
}
//
// Process members
//
@@ -202,6 +252,10 @@ public:
if (!m_config.should_include(m.scope))
continue;
if (!m_config.include_relations_also_as_members &&
rendered_relations.find(m.name) != rendered_relations.end())
continue;
if (m.is_static)
ostr << "{static} ";
@@ -228,47 +282,8 @@ public:
}
}
for (const auto &r : c.relationships) {
if (!m_config.should_include_relationship(name(r.type)))
continue;
std::stringstream relstr;
std::string destination;
try {
if (r.destination.find("#") != std::string::npos ||
r.destination.find("@") != std::string::npos) {
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
// debugging
if (destination.empty()) {
relstr << "' ";
destination = r.destination;
}
}
else {
destination = r.destination;
}
relstr << m_model.to_alias(
uns, ns_relative(uns, c.full_name(uns)))
<< " " << to_string(r.type) << " "
<< m_model.to_alias(uns, ns_relative(uns, destination));
if (!r.label.empty())
relstr << " : " << to_string(r.scope) << r.label;
relstr << std::endl;
ostr << relstr.str();
}
catch (error::uml_alias_missing &e) {
LOG_ERROR("Skipping {} relation from {} to {} due "
"to: {}",
to_string(r.type), c.full_name(uns), destination, e.what());
}
}
// Print relationships
ostr << all_relations_str.str();
}
void generate(const enum_ &e, std::ostream &ostr) const