diff --git a/src/uml/class_diagram_model.h b/src/uml/class_diagram_model.h index 05250b11..39ee4cb2 100644 --- a/src/uml/class_diagram_model.h +++ b/src/uml/class_diagram_model.h @@ -117,6 +117,13 @@ struct class_relationship { std::string cardinality_source; std::string cardinality_destination; std::string label; + + friend bool operator==( + const class_relationship &l, const class_relationship &r) + { + return l.type == r.type && l.destination == r.destination && + l.label == r.label; + } }; struct class_template { @@ -140,6 +147,13 @@ public: std::vector templates; std::string base_template_usr; + void add_relationship(class_relationship &&cr) + { + auto it = std::find(relationships.begin(), relationships.end(), cr); + if (it == relationships.end()) + relationships.emplace_back(std::move(cr)); + } + std::string full_name( const std::vector &using_namespaces) const { diff --git a/src/uml/class_diagram_visitor.h b/src/uml/class_diagram_visitor.h index 0d4d807c..2f36e536 100644 --- a/src/uml/class_diagram_visitor.h +++ b/src/uml/class_diagram_visitor.h @@ -239,7 +239,7 @@ static enum CXChildVisitResult method_parameter_visitor( assert(ctx->parent_class != nullptr); - ctx->parent_class->relationships.emplace_back(std::move(r)); + ctx->parent_class->add_relationship(std::move(r)); } ret = CXChildVisit_Continue; diff --git a/tests/t00013/t00013.cc b/tests/t00013/t00013.cc index 7928d5fb..731b17b8 100644 --- a/tests/t00013/t00013.cc +++ b/tests/t00013/t00013.cc @@ -33,6 +33,8 @@ public: // TODO: int get_b(const B &b) { return b.b; } int get_c(C c) { return c.c; } int get_d(D &&d) { return d.d; } + // Dependency relationship should be rendered only once + int get_d2(D &&d) { return d.d; } }; } }