From e119baee5b26441260c001b601d36f833329096b Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Mon, 27 Sep 2021 22:11:02 +0200 Subject: [PATCH] Refactored method_parameter --- src/uml/class_diagram_model.cc | 22 ++++++++++++++++++---- src/uml/class_diagram_model.h | 19 +++++++++++++++---- src/uml/class_diagram_visitor.cc | 16 ++++++++-------- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/uml/class_diagram_model.cc b/src/uml/class_diagram_model.cc index 917cb062..23e3f770 100644 --- a/src/uml/class_diagram_model.cc +++ b/src/uml/class_diagram_model.cc @@ -208,16 +208,30 @@ const std::vector &element::relationships() const // // method_parameter // +void method_parameter::set_type(const std::string &type) { type_ = type; } + +std::string method_parameter::type() const { return type_; } + +void method_parameter::set_name(const std::string &name) { name_ = name; } + +std::string method_parameter::name() const { return name_; } + +void method_parameter::set_default_value(const std::string &value) +{ + default_value_ = value; +} + +std::string method_parameter::default_value() const { return default_value_; } std::string method_parameter::to_string( const std::vector &using_namespaces) const { using namespace clanguml::util; - auto t = ns_relative(using_namespaces, type); - if (default_value.empty()) - return fmt::format("{} {}", t, name); + auto t = ns_relative(using_namespaces, type()); + if (default_value().empty()) + return fmt::format("{} {}", t, name()); - return fmt::format("{} {} = {}", t, name, default_value); + return fmt::format("{} {} = {}", t, name(), default_value()); } // diff --git a/src/uml/class_diagram_model.h b/src/uml/class_diagram_model.h index 05d5d2da..9726dd98 100644 --- a/src/uml/class_diagram_model.h +++ b/src/uml/class_diagram_model.h @@ -114,13 +114,24 @@ private: bool is_static_{false}; }; -struct method_parameter : public decorated_element { - std::string type; - std::string name; - std::string default_value; +class method_parameter : public decorated_element { +public: + void set_type(const std::string &type); + std::string type() const; + + void set_name(const std::string &name); + std::string name() const; + + void set_default_value(const std::string &value); + std::string default_value() const; std::string to_string( const std::vector &using_namespaces) const; + +private: + std::string type_; + std::string name_; + std::string default_value_; }; class class_method : public class_element { diff --git a/src/uml/class_diagram_visitor.cc b/src/uml/class_diagram_visitor.cc index b0f16f68..e1b8869f 100644 --- a/src/uml/class_diagram_visitor.cc +++ b/src/uml/class_diagram_visitor.cc @@ -901,7 +901,7 @@ void tu_visitor::process_function_parameter( const std::set &template_parameter_names) { method_parameter mp; - mp.name = param.name(); + mp.set_name(param.name()); if (param.comment().has_value()) m.add_decorators(decorators::parse(param.comment().value())); @@ -915,29 +915,29 @@ void tu_visitor::process_function_parameter( // TODO: Template instantiation parameters are not fully prefixed // so we have to deduce the correct namespace prefix of the // template which is being instantiated - mp.type = cppast::to_string(param.type()); + mp.set_type(cppast::to_string(param.type())); } else { - mp.type = cppast::to_string(param.type()); + mp.set_type(cppast::to_string(param.type())); } auto dv = param.default_value(); if (dv) { switch (dv.value().kind()) { case cppast::cpp_expression_kind::literal_t: - mp.default_value = + mp.set_default_value( static_cast(dv.value()) - .value(); + .value()); break; case cppast::cpp_expression_kind::unexposed_t: - mp.default_value = + mp.set_default_value( static_cast( dv.value()) .expression() - .as_string(); + .as_string()); break; default: - mp.default_value = "{}"; + mp.set_default_value("{}"); } }