Added callee_filter for including/excluding messages based on receiver type (#152)

This commit is contained in:
Bartek Kryza
2023-07-01 21:19:51 +02:00
parent 213483dd3b
commit e50a7b1846
24 changed files with 590 additions and 43 deletions

View File

@@ -79,10 +79,37 @@ std::string to_string(method_type mt)
return "deleted";
case method_type::static_:
return "static";
default:
assert(false);
return "";
}
assert(false);
return "";
}
std::string to_string(callee_type mt)
{
switch (mt) {
case callee_type::constructor:
return "constructor";
case callee_type::assignment:
return "assignment";
case callee_type::operator_:
return "operator";
case callee_type::defaulted:
return "defaulted";
case callee_type::static_:
return "static";
case callee_type::method:
return "method";
case callee_type::function:
return "function";
case callee_type::function_template:
return "function_template";
case callee_type::lambda:
return "lambda";
}
assert(false);
return "";
}
std::string to_string(const comment_parser_t cp)

View File

@@ -63,6 +63,21 @@ enum class method_type {
std::string to_string(method_type mt);
/*! Types of call expressions, which can be used in sequence diagram filters */
enum class callee_type {
constructor,
assignment,
operator_,
defaulted,
static_,
method,
function,
function_template,
lambda
};
std::string to_string(callee_type mt);
/*! How packages in diagrams should be generated */
enum class package_type_t {
kNamespace, /*!< From namespaces */
@@ -313,6 +328,23 @@ struct filter {
* ```
*/
std::vector<method_type> method_types;
/*! @brief Callee types filter
*
* This filter allows to filter sequence diagram calls by callee types.
*
* @see method_type
*
* Example:
*
* ```yaml
* exclude:
* callee_types:
* - constructor
* - operator
* ```
*/
std::vector<callee_type> callee_types;
};
enum class hint_t { up, down, left, right, together, row, column };

View File

@@ -24,6 +24,7 @@ using clanguml::common::namespace_or_regex;
using clanguml::common::string_or_regex;
using clanguml::common::model::access_t;
using clanguml::common::model::relationship_t;
using clanguml::config::callee_type;
using clanguml::config::class_diagram;
using clanguml::config::config;
using clanguml::config::diagram_template;
@@ -252,6 +253,38 @@ template <> struct convert<method_type> {
}
};
//
// config callee_type decoder
//
template <> struct convert<callee_type> {
static bool decode(const Node &node, callee_type &rhs)
{
const auto &val = node.as<std::string>();
if (val == to_string(callee_type::constructor))
rhs = callee_type::constructor;
else if (val == to_string(callee_type::assignment))
rhs = callee_type::assignment;
else if (val == to_string(callee_type::operator_))
rhs = callee_type::operator_;
else if (val == to_string(callee_type::defaulted))
rhs = callee_type::defaulted;
else if (val == to_string(callee_type::static_))
rhs = callee_type::static_;
else if (val == to_string(callee_type::function))
rhs = callee_type::function;
else if (val == to_string(callee_type::function_template))
rhs = callee_type::function_template;
else if (val == to_string(callee_type::method))
rhs = callee_type::method;
else if (val == to_string(callee_type::lambda))
rhs = callee_type::lambda;
else
return false;
return true;
}
};
//
// config relationship_t decoder
//
@@ -432,6 +465,10 @@ template <> struct convert<filter> {
if (node["paths"])
rhs.paths = node["paths"].as<decltype(rhs.paths)>();
if (node["callee_types"])
rhs.callee_types =
node["callee_types"].as<decltype(rhs.callee_types)>();
return true;
}
};

View File

@@ -82,6 +82,12 @@ YAML::Emitter &operator<<(YAML::Emitter &out, const method_type &m)
return out;
}
YAML::Emitter &operator<<(YAML::Emitter &out, const callee_type &m)
{
out << to_string(m);
return out;
}
YAML::Emitter &operator<<(YAML::Emitter &out, const filter &f)
{
out << YAML::BeginMap;
@@ -112,7 +118,8 @@ YAML::Emitter &operator<<(YAML::Emitter &out, const filter &f)
out << YAML::Key << "subclasses" << YAML::Value << f.subclasses;
if (!f.parents.empty())
out << YAML::Key << "parents" << YAML::Value << f.parents;
if (!f.method_types.empty())
out << YAML::Key << "callee_types" << YAML::Value << f.callee_types;
out << YAML::EndMap;
return out;
}