Added method type diagram filter (#145)
This commit is contained in:
@@ -59,6 +59,7 @@ public:
|
||||
std::string name() const;
|
||||
|
||||
void set_filter(std::unique_ptr<diagram_filter> filter);
|
||||
const diagram_filter &filter() const { return *filter_; }
|
||||
|
||||
void set_complete(bool complete);
|
||||
bool complete() const;
|
||||
|
||||
@@ -127,6 +127,18 @@ tvl::value_t filter_visitor::match(
|
||||
return {};
|
||||
}
|
||||
|
||||
tvl::value_t filter_visitor::match(
|
||||
const diagram &d, const class_diagram::model::class_method &m) const
|
||||
{
|
||||
return match(d, m.access());
|
||||
}
|
||||
|
||||
tvl::value_t filter_visitor::match(
|
||||
const diagram &d, const class_diagram::model::class_member &m) const
|
||||
{
|
||||
return match(d, m.access());
|
||||
}
|
||||
|
||||
bool filter_visitor::is_inclusive() const
|
||||
{
|
||||
return type_ == filter_t::kInclusive;
|
||||
@@ -236,6 +248,37 @@ tvl::value_t element_type_filter::match(
|
||||
});
|
||||
}
|
||||
|
||||
method_type_filter::method_type_filter(
|
||||
filter_t type, std::vector<config::method_type> method_types)
|
||||
: filter_visitor{type}
|
||||
, method_types_{std::move(method_types)}
|
||||
{
|
||||
}
|
||||
|
||||
tvl::value_t method_type_filter::match(
|
||||
const diagram &d, const class_diagram::model::class_method &m) const
|
||||
{
|
||||
return tvl::any_of(
|
||||
method_types_.begin(), method_types_.end(), [&m](auto mt) {
|
||||
switch (mt) {
|
||||
case config::method_type::constructor:
|
||||
return m.is_constructor() || m.is_destructor();
|
||||
case config::method_type::assignment:
|
||||
return m.is_copy_assignment() || m.is_move_assignment();
|
||||
case config::method_type::operator_:
|
||||
return m.is_operator();
|
||||
case config::method_type::defaulted:
|
||||
return m.is_defaulted();
|
||||
case config::method_type::deleted:
|
||||
return m.is_deleted();
|
||||
case config::method_type::static_:
|
||||
return m.is_static();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
subclass_filter::subclass_filter(filter_t type, std::vector<std::string> roots)
|
||||
: filter_visitor{type}
|
||||
, roots_{std::move(roots)}
|
||||
@@ -494,6 +537,36 @@ tvl::value_t paths_filter::match(
|
||||
return false;
|
||||
}
|
||||
|
||||
class_method_filter::class_method_filter(filter_t type,
|
||||
std::unique_ptr<access_filter> af, std::unique_ptr<method_type_filter> mtf)
|
||||
: filter_visitor{type}
|
||||
, access_filter_{std::move(af)}
|
||||
, method_type_filter_{std::move(mtf)}
|
||||
{
|
||||
}
|
||||
|
||||
tvl::value_t class_method_filter::match(
|
||||
const diagram &d, const class_diagram::model::class_method &m) const
|
||||
{
|
||||
tvl::value_t res = tvl::or_(
|
||||
access_filter_->match(d, m.access()), method_type_filter_->match(d, m));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
class_member_filter::class_member_filter(
|
||||
filter_t type, std::unique_ptr<access_filter> af)
|
||||
: filter_visitor{type}
|
||||
, access_filter_{std::move(af)}
|
||||
{
|
||||
}
|
||||
|
||||
tvl::value_t class_member_filter::match(
|
||||
const diagram &d, const class_diagram::model::class_member &m) const
|
||||
{
|
||||
return access_filter_->match(d, m.access());
|
||||
}
|
||||
|
||||
diagram_filter::diagram_filter(
|
||||
const common::model::diagram &d, const config::diagram &c)
|
||||
: diagram_{d}
|
||||
@@ -541,6 +614,18 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
add_inclusive_filter(std::make_unique<paths_filter>(
|
||||
filter_t::kInclusive, c.root_directory(), c.include().paths));
|
||||
|
||||
add_inclusive_filter(
|
||||
std::make_unique<class_method_filter>(filter_t::kInclusive,
|
||||
std::make_unique<access_filter>(
|
||||
filter_t::kInclusive, c.include().access),
|
||||
std::make_unique<method_type_filter>(
|
||||
filter_t::kInclusive, c.include().method_types)));
|
||||
|
||||
add_inclusive_filter(
|
||||
std::make_unique<class_member_filter>(filter_t::kInclusive,
|
||||
std::make_unique<access_filter>(
|
||||
filter_t::kInclusive, c.include().access)));
|
||||
|
||||
// Include any of these matches even if one them does not match
|
||||
std::vector<std::unique_ptr<filter_visitor>> element_filters;
|
||||
|
||||
@@ -637,6 +722,18 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
add_exclusive_filter(std::make_unique<access_filter>(
|
||||
filter_t::kExclusive, c.exclude().access));
|
||||
|
||||
add_exclusive_filter(
|
||||
std::make_unique<class_method_filter>(filter_t::kExclusive,
|
||||
std::make_unique<access_filter>(
|
||||
filter_t::kExclusive, c.exclude().access),
|
||||
std::make_unique<method_type_filter>(
|
||||
filter_t::kExclusive, c.exclude().method_types)));
|
||||
|
||||
add_exclusive_filter(
|
||||
std::make_unique<class_member_filter>(filter_t::kExclusive,
|
||||
std::make_unique<access_filter>(
|
||||
filter_t::kExclusive, c.exclude().access)));
|
||||
|
||||
add_exclusive_filter(std::make_unique<subclass_filter>(
|
||||
filter_t::kExclusive, c.exclude().subclasses));
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "class_diagram/model/class_member.h"
|
||||
#include "class_diagram/model/class_method.h"
|
||||
#include "class_diagram/model/diagram.h"
|
||||
#include "common/clang_utils.h"
|
||||
#include "common/model/diagram.h"
|
||||
@@ -78,6 +80,12 @@ public:
|
||||
virtual tvl::value_t match(
|
||||
const diagram &d, const common::model::source_location &f) const;
|
||||
|
||||
virtual tvl::value_t match(
|
||||
const diagram &d, const class_diagram::model::class_method &m) const;
|
||||
|
||||
virtual tvl::value_t match(
|
||||
const diagram &d, const class_diagram::model::class_member &m) const;
|
||||
|
||||
bool is_inclusive() const;
|
||||
bool is_exclusive() const;
|
||||
|
||||
@@ -138,6 +146,19 @@ private:
|
||||
std::vector<std::string> element_types_;
|
||||
};
|
||||
|
||||
struct method_type_filter : public filter_visitor {
|
||||
method_type_filter(
|
||||
filter_t type, std::vector<config::method_type> method_types);
|
||||
|
||||
~method_type_filter() override = default;
|
||||
|
||||
tvl::value_t match(const diagram &d,
|
||||
const class_diagram::model::class_method &e) const override;
|
||||
|
||||
private:
|
||||
std::vector<config::method_type> method_types_;
|
||||
};
|
||||
|
||||
struct subclass_filter : public filter_visitor {
|
||||
subclass_filter(filter_t type, std::vector<std::string> roots);
|
||||
|
||||
@@ -354,6 +375,32 @@ private:
|
||||
std::filesystem::path root_;
|
||||
};
|
||||
|
||||
struct class_method_filter : public filter_visitor {
|
||||
class_method_filter(filter_t type, std::unique_ptr<access_filter> af,
|
||||
std::unique_ptr<method_type_filter> mtf);
|
||||
|
||||
~class_method_filter() override = default;
|
||||
|
||||
tvl::value_t match(const diagram &d,
|
||||
const class_diagram::model::class_method &m) const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<access_filter> access_filter_;
|
||||
std::unique_ptr<method_type_filter> method_type_filter_;
|
||||
};
|
||||
|
||||
struct class_member_filter : public filter_visitor {
|
||||
class_member_filter(filter_t type, std::unique_ptr<access_filter> af);
|
||||
|
||||
~class_member_filter() override = default;
|
||||
|
||||
tvl::value_t match(const diagram &d,
|
||||
const class_diagram::model::class_member &m) const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<access_filter> access_filter_;
|
||||
};
|
||||
|
||||
class diagram_filter {
|
||||
public:
|
||||
diagram_filter(const common::model::diagram &d, const config::diagram &c);
|
||||
|
||||
@@ -24,6 +24,31 @@ namespace clanguml::common::model::tvl {
|
||||
|
||||
using value_t = std::optional<bool>;
|
||||
|
||||
inline value_t and_(const value_t &l, const value_t &r)
|
||||
{
|
||||
if (!l.has_value())
|
||||
return r;
|
||||
|
||||
if (!r.has_value())
|
||||
return l;
|
||||
|
||||
return r.value() && l.value();
|
||||
}
|
||||
|
||||
inline value_t or_(const value_t &l, const value_t &r)
|
||||
{
|
||||
if (!l.has_value() && !r.has_value())
|
||||
return {};
|
||||
|
||||
if (l.has_value() && l.value())
|
||||
return true;
|
||||
|
||||
if (r.has_value() && r.value())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool is_true(const value_t &v) { return v.has_value() && v.value(); }
|
||||
|
||||
inline bool is_false(const value_t &v) { return v.has_value() && !v.value(); }
|
||||
|
||||
Reference in New Issue
Block a user