From e615f3b869c6ab3edd405cb99c5ec9ca2b263745 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Mon, 27 Sep 2021 00:05:47 +0200 Subject: [PATCH] Refactored decorated_element --- src/puml/class_diagram_generator.cc | 4 ++-- src/uml/class_diagram_model.cc | 22 ++++++++++++++++++---- src/uml/class_diagram_model.h | 14 +++++++++++--- src/uml/class_diagram_visitor.cc | 28 ++++++++++++++-------------- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/puml/class_diagram_generator.cc b/src/puml/class_diagram_generator.cc index 7b9c0543..79f4293e 100644 --- a/src/puml/class_diagram_generator.cc +++ b/src/puml/class_diagram_generator.cc @@ -273,7 +273,7 @@ void generator::generate(const class_ &c, std::ostream &ostr) const // // Process notes // - for (auto decorator : c.decorators) { + for (auto decorator : c.decorators()) { auto note = std::dynamic_pointer_cast(decorator); if (note && note->applies_to_diagram(m_config.name)) { ostr << "note " << note->position << " of " << c.alias() << '\n' @@ -334,7 +334,7 @@ void generator::generate(const enum_ &e, std::ostream &ostr) const // // Process notes // - for (auto decorator : e.decorators) { + for (auto decorator : e.decorators()) { auto note = std::dynamic_pointer_cast(decorator); if (note && note->applies_to_diagram(m_config.name)) { ostr << "note " << note->position << " of " << e.alias() << '\n' diff --git a/src/uml/class_diagram_model.cc b/src/uml/class_diagram_model.cc index 78f2e5f1..aaa44524 100644 --- a/src/uml/class_diagram_model.cc +++ b/src/uml/class_diagram_model.cc @@ -64,7 +64,7 @@ std::string stylable_element::style() const { return style_; } bool decorated_element::skip() const { - for (auto d : decorators) + for (auto d : decorators_) if (std::dynamic_pointer_cast(d)) return true; @@ -73,7 +73,7 @@ bool decorated_element::skip() const bool decorated_element::skip_relationship() const { - for (auto d : decorators) + for (auto d : decorators_) if (std::dynamic_pointer_cast(d)) return true; @@ -82,7 +82,7 @@ bool decorated_element::skip_relationship() const std::pair decorated_element::relationship() const { - for (auto &d : decorators) + for (auto &d : decorators_) if (std::dynamic_pointer_cast(d)) return {relationship_t::kAssociation, std::dynamic_pointer_cast(d) @@ -101,13 +101,27 @@ std::pair decorated_element::relationship() const std::string decorated_element::style_spec() { - for (auto d : decorators) + for (auto d : decorators_) if (std::dynamic_pointer_cast(d)) return std::dynamic_pointer_cast(d)->spec; return ""; } +const std::vector> & +decorated_element::decorators() const +{ + return decorators_; +} + +void decorated_element::add_decorators( + const std::vector> &decorators) +{ + for (auto d : decorators) { + decorators_.push_back(d); + } +} + // // element // diff --git a/src/uml/class_diagram_model.h b/src/uml/class_diagram_model.h index 29f52437..74f5f11f 100644 --- a/src/uml/class_diagram_model.h +++ b/src/uml/class_diagram_model.h @@ -63,9 +63,8 @@ private: std::string style_; }; -struct decorated_element { - std::vector> decorators; - +class decorated_element { +public: bool skip() const; bool skip_relationship() const; @@ -73,6 +72,15 @@ struct decorated_element { std::pair relationship() const; std::string style_spec(); + + const std::vector> & + decorators() const; + + void add_decorators( + const std::vector> &decorators); + +private: + std::vector> decorators_; }; struct class_element : public decorated_element { diff --git a/src/uml/class_diagram_visitor.cc b/src/uml/class_diagram_visitor.cc index 230f45f7..c06cf3dc 100644 --- a/src/uml/class_diagram_visitor.cc +++ b/src/uml/class_diagram_visitor.cc @@ -283,7 +283,7 @@ void tu_visitor::process_enum_declaration(const cppast::cpp_enum &enm) e.set_name(cx::util::full_name(ctx.namespace_, enm)); if (enm.comment().has_value()) - e.decorators = decorators::parse(enm.comment().value()); + e.add_decorators(decorators::parse(enm.comment().value())); if (e.skip()) return; @@ -292,7 +292,7 @@ void tu_visitor::process_enum_declaration(const cppast::cpp_enum &enm) // Process enum documentation comment if (enm.comment().has_value()) - e.decorators = decorators::parse(enm.comment().value()); + e.add_decorators(decorators::parse(enm.comment().value())); for (const auto &ev : enm) { if (ev.kind() == cppast::cpp_entity_kind::enum_value_t) { @@ -328,7 +328,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls, c.set_name(cx::util::full_name(ctx.namespace_, cls)); if (cls.comment().has_value()) - c.decorators = decorators::parse(cls.comment().value()); + c.add_decorators(decorators::parse(cls.comment().value())); cppast::cpp_access_specifier_kind last_access_specifier = cppast::cpp_access_specifier_kind::cpp_private; @@ -336,12 +336,12 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls, // Process class documentation comment if (cppast::is_templated(cls)) { if (cls.parent().value().comment().has_value()) - c.decorators = - decorators::parse(cls.parent().value().comment().value()); + c.add_decorators( + decorators::parse(cls.parent().value().comment().value())); } else { if (cls.comment().has_value()) - c.decorators = decorators::parse(cls.comment().value()); + c.add_decorators(decorators::parse(cls.comment().value())); } if (c.skip()) @@ -675,7 +675,7 @@ void tu_visitor::process_field(const cppast::cpp_member_variable &mv, class_ &c, m.is_static = false; if (mv.comment().has_value()) - m.decorators = decorators::parse(mv.comment().value()); + m.add_decorators(decorators::parse(mv.comment().value())); if (m.skip()) return; @@ -767,7 +767,7 @@ void tu_visitor::process_static_field(const cppast::cpp_variable &mv, class_ &c, m.is_static = true; if (mv.comment().has_value()) - m.decorators = decorators::parse(mv.comment().value()); + m.add_decorators(decorators::parse(mv.comment().value())); if (m.skip()) return; @@ -789,7 +789,7 @@ void tu_visitor::process_method(const cppast::cpp_member_function &mf, m.scope = detail::cpp_access_specifier_to_scope(as); if (mf.comment().has_value()) - m.decorators = decorators::parse(mf.comment().value()); + m.add_decorators(decorators::parse(mf.comment().value())); if (m.skip()) return; @@ -824,7 +824,7 @@ void tu_visitor::process_template_method( m.scope = detail::cpp_access_specifier_to_scope(as); if (mf.comment().has_value()) - m.decorators = decorators::parse(mf.comment().value()); + m.add_decorators(decorators::parse(mf.comment().value())); if (m.skip()) return; @@ -856,7 +856,7 @@ void tu_visitor::process_static_method(const cppast::cpp_function &mf, m.scope = detail::cpp_access_specifier_to_scope(as); if (mf.comment().has_value()) - m.decorators = decorators::parse(mf.comment().value()); + m.add_decorators(decorators::parse(mf.comment().value())); if (m.skip()) return; @@ -883,7 +883,7 @@ void tu_visitor::process_constructor(const cppast::cpp_constructor &mf, m.scope = detail::cpp_access_specifier_to_scope(as); if (mf.comment().has_value()) - m.decorators = decorators::parse(mf.comment().value()); + m.add_decorators(decorators::parse(mf.comment().value())); if (m.skip()) return; @@ -918,7 +918,7 @@ void tu_visitor::process_function_parameter( mp.name = param.name(); if (param.comment().has_value()) - m.decorators = decorators::parse(param.comment().value()); + m.add_decorators(decorators::parse(param.comment().value())); if (mp.skip()) return; @@ -1109,7 +1109,7 @@ void tu_visitor::process_friend(const cppast::cpp_friend &f, class_ &parent) r.label = "<>"; if (f.comment().has_value()) - r.decorators = decorators::parse(f.comment().value()); + r.add_decorators(decorators::parse(f.comment().value())); if (r.skip() || r.skip_relationship()) return;