Added relationship decorators

This commit is contained in:
Bartek Kryza
2021-07-31 19:15:55 +02:00
parent 3f8100a050
commit 841f97eeb5
13 changed files with 366 additions and 13 deletions

View File

@@ -224,9 +224,18 @@ public:
destination = r.destination;
}
std::string puml_relation;
if (!r.multiplicity_source.empty())
puml_relation += "\"" + r.multiplicity_source + "\" ";
puml_relation += to_string(r.type);
if (!r.multiplicity_destination.empty())
puml_relation += " \"" + r.multiplicity_destination + "\"";
relstr << m_model.to_alias(
uns, ns_relative(uns, c.full_name(uns)))
<< " " << to_string(r.type) << " "
<< " " << puml_relation << " "
<< m_model.to_alias(uns, ns_relative(uns, destination));
if (!r.label.empty()) {

View File

@@ -57,7 +57,7 @@ std::string to_string(relationship_t r);
struct decorated_element {
std::vector<std::shared_ptr<decorators::decorator>> decorators;
bool skip()
bool skip() const
{
for (auto d : decorators)
if (std::dynamic_pointer_cast<decorators::skip>(d))
@@ -66,7 +66,7 @@ struct decorated_element {
return false;
}
bool skip_relationship()
bool skip_relationship() const
{
for (auto d : decorators)
if (std::dynamic_pointer_cast<decorators::skip_relationship>(d))
@@ -74,6 +74,25 @@ struct decorated_element {
return false;
}
std::pair<relationship_t, std::string> relationship() const
{
for (auto &d : decorators)
if (std::dynamic_pointer_cast<decorators::association>(d))
return {relationship_t::kAssociation,
std::dynamic_pointer_cast<decorators::relationship>(d)
->multiplicity};
else if (std::dynamic_pointer_cast<decorators::aggregation>(d))
return {relationship_t::kAggregation,
std::dynamic_pointer_cast<decorators::relationship>(d)
->multiplicity};
else if (std::dynamic_pointer_cast<decorators::composition>(d))
return {relationship_t::kComposition,
std::dynamic_pointer_cast<decorators::relationship>(d)
->multiplicity};
return {relationship_t::kNone, ""};
}
};
class element : public decorated_element {
@@ -141,8 +160,8 @@ struct class_parent {
struct class_relationship : public decorated_element {
relationship_t type{relationship_t::kAssociation};
std::string destination;
std::string cardinality_source;
std::string cardinality_destination;
std::string multiplicity_source;
std::string multiplicity_destination;
std::string label;
scope_t scope{scope_t::kNone};

View File

@@ -647,6 +647,16 @@ void tu_visitor::process_field(const cppast::cpp_member_variable &mv, class_ &c,
r.label = m.name;
r.scope = m.scope;
auto [decorator_rtype, decorator_rmult] = m.relationship();
if (decorator_rtype != relationship_t::kNone) {
r.type = decorator_rtype;
auto mult = util::split(decorator_rmult, ":");
if (mult.size() == 2) {
r.multiplicity_source = mult[0];
r.multiplicity_destination = mult[1];
}
}
LOG_DBG("Adding field relationship {} {} {} : {}",
r.destination, model::class_diagram::to_string(r.type),
c.usr, r.label);

View File

@@ -30,6 +30,8 @@ const std::string skip::label = "skip";
const std::string skip_relationship::label = "skiprelationship";
const std::string style::label = "style";
const std::string aggregation::label = "aggregation";
const std::string composition::label = "composition";
const std::string association::label = "association";
std::shared_ptr<decorator> decorator::from_string(std::string_view c)
{
@@ -48,6 +50,12 @@ std::shared_ptr<decorator> decorator::from_string(std::string_view c)
else if (c.find(aggregation::label) == 0) {
return aggregation::from_string(c);
}
else if (c.find(composition::label) == 0) {
return composition::from_string(c);
}
else if (c.find(association::label) == 0) {
return association::from_string(c);
}
return {};
}
@@ -151,6 +159,28 @@ std::shared_ptr<decorator> aggregation::from_string(std::string_view c)
return res;
}
std::shared_ptr<decorator> composition::from_string(std::string_view c)
{
auto res = std::make_shared<composition>();
auto toks = res->tokenize(composition::label, c);
res->diagrams = toks.diagrams;
res->multiplicity = toks.param;
return res;
}
std::shared_ptr<decorator> association::from_string(std::string_view c)
{
auto res = std::make_shared<association>();
auto toks = res->tokenize(association::label, c);
res->diagrams = toks.diagrams;
res->multiplicity = toks.param;
return res;
}
std::vector<std::shared_ptr<decorator>> parse(
std::string documentation_block, std::string clanguml_tag)
{

View File

@@ -72,10 +72,25 @@ struct style : public decorator {
static std::shared_ptr<decorator> from_string(std::string_view c);
};
struct aggregation : public decorator {
struct relationship : public decorator {
std::string multiplicity;
};
struct aggregation : public relationship {
static const std::string label;
static std::shared_ptr<decorator> from_string(std::string_view c);
};
struct composition : public relationship {
static const std::string label;
static std::shared_ptr<decorator> from_string(std::string_view c);
};
struct association : public relationship {
static const std::string label;
std::string multiplicity;
static std::shared_ptr<decorator> from_string(std::string_view c);
};