Added dependencies filter

This commit is contained in:
Bartek Kryza
2022-04-18 12:50:19 +02:00
parent 11dccf1496
commit 4ff563354f
7 changed files with 92 additions and 10 deletions

View File

@@ -381,6 +381,11 @@ void diagram_filter::init_filters(const config::diagram &c)
class_diagram::model::class_>>(filter_t::kInclusive,
relationship_t::kDependency, c.include().dependants));
element_filters.emplace_back(
std::make_unique<tree_element_filter<class_diagram::model::diagram,
class_diagram::model::class_>>(filter_t::kInclusive,
relationship_t::kDependency, c.include().dependencies, true));
element_filters.emplace_back(std::make_unique<context_filter>(
filter_t::kInclusive, c.include().context));
@@ -410,6 +415,10 @@ void diagram_filter::init_filters(const config::diagram &c)
std::make_unique<tree_element_filter<class_diagram::model::diagram,
class_diagram::model::class_>>(filter_t::kExclusive,
relationship_t::kDependency, c.exclude().dependants));
add_exclusive_filter(
std::make_unique<tree_element_filter<class_diagram::model::diagram,
class_diagram::model::class_>>(filter_t::kExclusive,
relationship_t::kDependency, c.exclude().dependencies, true));
add_exclusive_filter(std::make_unique<context_filter>(
filter_t::kExclusive, c.exclude().context));
}

View File

@@ -115,10 +115,11 @@ private:
template <typename DiagramT, typename ElementT>
struct tree_element_filter : public filter_visitor {
tree_element_filter(filter_t type, relationship_t relationship,
std::vector<std::string> roots)
std::vector<std::string> roots, bool forward = false)
: filter_visitor{type}
, relationship_{relationship}
, roots_{roots}
, forward_{forward}
{
}
@@ -187,17 +188,40 @@ private:
}
};
while (found_new_template) {
found_new_template = false;
// For each element of type ElementT in the diagram
for (const auto &el : detail::view<ElementT>(cd)) {
// Check if any of its relationships of type relationship_
// points to an element already in the matching_elements_ set
for (const auto &rel : el->relationships()) {
reverse_relationship_match(rel, el);
if (!forward_)
while (found_new_template) {
found_new_template = false;
// For each element of type ElementT in the diagram
for (const auto &el : detail::view<ElementT>(cd)) {
// Check if any of its relationships of type relationship_
// points to an element already in the matching_elements_
// set
for (const auto &rel : el->relationships()) {
reverse_relationship_match(rel, el);
}
}
}
}
else
while (found_new_template) {
found_new_template = false;
// For each of the already matched elements
for (const auto &already_matching : matching_elements_)
// Check if any of its relationships of type relationship_
// points to an element already in the matching_elements_
// set
for (const auto &rel : already_matching->relationships()) {
if (rel.type() == relationship_) {
for (const auto &el : detail::view<ElementT>(cd)) {
if (rel.destination() == el->full_name(false)) {
auto inserted =
matching_elements_.insert(el);
if (inserted.second)
found_new_template = true;
}
}
}
}
}
initialized_ = true;
}
@@ -207,6 +231,7 @@ private:
mutable bool initialized_{false};
mutable std::unordered_set<type_safe::object_ref<const ElementT, false>>
matching_elements_;
bool forward_;
};
struct relationship_filter : public filter_visitor {