Added rendering of concept requirements in concept body

This commit is contained in:
Bartek Kryza
2023-02-26 23:29:55 +01:00
parent 2ab6ed627e
commit dbb3e68c3f
12 changed files with 232 additions and 69 deletions

View File

@@ -17,6 +17,7 @@
*/
#include "concept.h"
#include "method_parameter.h"
#include <sstream>
@@ -69,4 +70,24 @@ std::string concept_::full_name(bool relative) const
return res;
}
void concept_::add_parameter(method_parameter mp)
{
requires_parameters_.emplace_back(std::move(mp));
}
const std::vector<method_parameter> &concept_::requires_parameters() const
{
return requires_parameters_;
}
void concept_::add_statement(std::string stmt)
{
requires_statements_.emplace_back(std::move(stmt));
}
const std::vector<std::string> &concept_::requires_statements() const
{
return requires_statements_;
}
}

View File

@@ -17,6 +17,7 @@
*/
#pragma once
#include "class_diagram/model/method_parameter.h"
#include "common/model/element.h"
#include "common/model/stylable_element.h"
#include "common/model/template_parameter.h"
@@ -52,8 +53,19 @@ public:
std::string full_name_no_ns() const override;
void add_parameter(method_parameter mp);
const std::vector<method_parameter> &requires_parameters() const;
void add_statement(std::string stmt);
const std::vector<std::string> &requires_statements() const;
private:
std::vector<std::string> requires_expression_;
std::string full_name_;
std::vector<method_parameter> requires_parameters_;
std::vector<std::string> requires_statements_;
};
}

View File

@@ -22,6 +22,14 @@
namespace clanguml::class_diagram::model {
method_parameter::method_parameter(
std::string type, std::string name, std::string default_value)
: type_{std::move(type)}
, name_{std::move(name)}
, default_value_{std::move(default_value)}
{
}
void method_parameter::set_type(const std::string &type) { type_ = type; }
std::string method_parameter::type() const { return type_; }
@@ -43,10 +51,14 @@ std::string method_parameter::to_string(
using namespace clanguml::util;
auto type_ns =
using_namespace.relative(common::model::namespace_{type()}.to_string());
if (default_value().empty())
return fmt::format("{} {}", type_ns, name());
return fmt::format("{} {} = {}", type_ns, name(), default_value());
auto name_ns =
using_namespace.relative(common::model::namespace_{name()}.to_string());
if (default_value().empty())
return fmt::format("{} {}", type_ns, name_ns);
return fmt::format("{} {} = {}", type_ns, name_ns, default_value());
}
} // namespace clanguml::class_diagram::model

View File

@@ -27,6 +27,10 @@ namespace clanguml::class_diagram::model {
class method_parameter : public common::model::decorated_element {
public:
method_parameter() = default;
method_parameter(
std::string type, std::string name, std::string default_value = {});
void set_type(const std::string &type);
std::string type() const;