From d6b88e68ec7701f3870da45cdf7773d33896cc35 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Sun, 26 Sep 2021 23:50:27 +0200 Subject: [PATCH] Refactored stylable_element --- src/puml/class_diagram_generator.cc | 10 +++++----- src/uml/class_diagram_model.cc | 7 +++++++ src/uml/class_diagram_model.h | 9 +++++++-- src/uml/class_diagram_visitor.cc | 8 ++++---- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/puml/class_diagram_generator.cc b/src/puml/class_diagram_generator.cc index e1733e0e..7b9c0543 100644 --- a/src/puml/class_diagram_generator.cc +++ b/src/puml/class_diagram_generator.cc @@ -130,8 +130,8 @@ void generator::generate(const class_ &c, std::ostream &ostr) const ostr << class_type << " " << c.alias(); - if (!c.style.empty()) - ostr << " " << c.style; + if (!c.style().empty()) + ostr << " " << c.style(); ostr << " {" << '\n'; @@ -203,7 +203,7 @@ void generator::generate(const class_ &c, std::ostream &ostr) const if (!r.multiplicity_source.empty()) puml_relation += "\"" + r.multiplicity_source + "\" "; - puml_relation += to_string(r.type, r.style); + puml_relation += to_string(r.type, r.style()); if (!r.multiplicity_destination.empty()) puml_relation += " \"" + r.multiplicity_destination + "\""; @@ -290,8 +290,8 @@ void generator::generate(const enum_ &e, std::ostream &ostr) const { ostr << "enum " << e.alias(); - if (!e.style.empty()) - ostr << " " << e.style; + if (!e.style().empty()) + ostr << " " << e.style(); ostr << " {" << '\n'; diff --git a/src/uml/class_diagram_model.cc b/src/uml/class_diagram_model.cc index e9d939e4..78f2e5f1 100644 --- a/src/uml/class_diagram_model.cc +++ b/src/uml/class_diagram_model.cc @@ -51,6 +51,13 @@ std::string to_string(relationship_t r) } } +// +// stylable_element +// +void stylable_element::set_style(const std::string &style) { style_ = style; } + +std::string stylable_element::style() const { return style_; } + // // decorated_element // diff --git a/src/uml/class_diagram_model.h b/src/uml/class_diagram_model.h index 98ae8fe6..29f52437 100644 --- a/src/uml/class_diagram_model.h +++ b/src/uml/class_diagram_model.h @@ -54,8 +54,13 @@ enum class relationship_t { std::string to_string(relationship_t r); -struct stylable_element { - std::string style; +class stylable_element { +public: + void set_style(const std::string &style); + std::string style() const; + +private: + std::string style_; }; struct decorated_element { diff --git a/src/uml/class_diagram_visitor.cc b/src/uml/class_diagram_visitor.cc index 8687a5be..230f45f7 100644 --- a/src/uml/class_diagram_visitor.cc +++ b/src/uml/class_diagram_visitor.cc @@ -288,7 +288,7 @@ void tu_visitor::process_enum_declaration(const cppast::cpp_enum &enm) if (e.skip()) return; - e.style = e.style_spec(); + e.set_style(e.style_spec()); // Process enum documentation comment if (enm.comment().has_value()) @@ -347,7 +347,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls, if (c.skip()) return; - c.style = c.style_spec(); + c.set_style(c.style_spec()); // Process class child entities if (c.is_struct()) @@ -633,7 +633,7 @@ bool tu_visitor::process_field_with_template_instantiation( rr.type = relationship_t::kAggregation; rr.label = mv.name(); rr.scope = detail::cpp_access_specifier_to_scope(as); - rr.style = m.style_spec(); + rr.set_style(m.style_spec()); // Process field decorators auto [decorator_rtype, decorator_rmult] = m.relationship(); @@ -718,7 +718,7 @@ void tu_visitor::process_field(const cppast::cpp_member_variable &mv, class_ &c, r.type = relationship_type; r.label = m.name; r.scope = m.scope; - r.style = m.style_spec(); + r.set_style(m.style_spec()); auto [decorator_rtype, decorator_rmult] = m.relationship(); if (decorator_rtype != relationship_t::kNone) {