Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/common/model/diagram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,20 @@ bool diagram::should_include(const element &e) const
if (filter_.get() == nullptr)
return true;

if (!complete()) {
// In the basic mode, apply the paths filter as soon as possible
// to limit processing unnecessary files
if (filter_->mode() == filter_mode_t::basic) {
return filter_->should_include(
dynamic_cast<const source_location &>(e));
}

return filter_->should_include(e) &&
filter_->should_include(dynamic_cast<const source_location &>(e));
// In advanced mode, we have to wait until the diagram model is complete
// before we can filter anything out
if (filter_->mode() == filter_mode_t::advanced && !complete()) {
return true;
}

return filter_->should_include(e);
}

bool diagram::should_include(const namespace_ &ns) const
Expand Down
10 changes: 10 additions & 0 deletions src/common/model/filters/diagram_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,12 @@ tvl::value_t paths_filter::match(
return false;
}

tvl::value_t paths_filter::match(
const diagram &d, const common::model::element &e) const
{
return match(d, dynamic_cast<const common::model::source_location &>(e));
}

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}
Expand Down Expand Up @@ -1052,6 +1058,10 @@ bool diagram_filter::should_include(
return false;
}

filter_mode_t diagram_filter::mode() const { return mode_; }

void diagram_filter::set_mode(filter_mode_t mode) { mode_ = mode; }

template <>
bool diagram_filter::should_include<std::string>(const std::string &name) const
{
Expand Down
9 changes: 9 additions & 0 deletions src/common/model/filters/diagram_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ struct paths_filter : public filter_visitor {
tvl::value_t match(const diagram &d,
const common::model::source_location &sl) const override;

tvl::value_t match(
const diagram &d, const common::model::element &e) const override;

private:
std::vector<std::filesystem::path> paths_;
std::filesystem::path root_;
Expand Down Expand Up @@ -802,6 +805,10 @@ class diagram_filter {
return static_cast<bool>(tvl::is_undefined(inc) || tvl::is_true(inc));
}

filter_mode_t mode() const;

void set_mode(filter_mode_t mode);

friend class diagram_filter_factory;

private:
Expand All @@ -813,6 +820,8 @@ class diagram_filter {

/*! Reference to the diagram model */
const common::model::diagram &diagram_;

filter_mode_t mode_{filter_mode_t::basic};
};

template <typename Collection>
Expand Down
4 changes: 3 additions & 1 deletion src/common/model/filters/diagram_filter_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class diagram_filter_factory {
auto filter = std::make_unique<diagram_filter>(
d, c, diagram_filter::private_constructor_tag_t{});

if (c.filter_mode() == config::filter_mode_t::basic) {
filter->set_mode(c.filter_mode());

if (filter->mode() == config::filter_mode_t::basic) {
basic_diagram_filter_initializer init{c, *filter};
init.initialize();
}
Expand Down
12 changes: 12 additions & 0 deletions tests/test_config_data/filters_advanced.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ diagrams:
anyof:
namespaces:
- ns1::ns2::detail
anyof_paths_test:
type: class
relative_to: ../../../src
glob:
- src/**/*.cc
- src/**/*.h
include:
anyof:
paths:
- .
elements:
- std::thread
modules_test:
type: class
include:
Expand Down
34 changes: 34 additions & 0 deletions tests/test_filters_advanced.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,40 @@ TEST_CASE("Test advanced diagram filter anyof")
CHECK_FALSE(filter.should_include(namespace_{"ns1::ns2::detail"}));
}

TEST_CASE("Test advanced diagram filter anyof with paths")
{
auto cfg =
clanguml::config::load("./test_config_data/filters_advanced.yml");

auto &config = *cfg.diagrams["anyof_paths_test"];
clanguml::include_diagram::model::diagram diagram;

diagram.set_complete(true);

auto filter_ptr = diagram_filter_factory::create(diagram, config);
diagram_filter &filter = *filter_ptr;

CHECK(config.filter_mode() == filter_mode_t::advanced);

clanguml::common::model::element std_thread{{}};
std_thread.set_namespace(namespace_{"std"});
std_thread.set_name("thread");
std_thread.set_file("/usr/include/thread");
CHECK(filter.should_include(std_thread));

std_thread.set_name("jthread");
CHECK_FALSE(filter.should_include(std_thread));

clanguml::common::model::element myclass{{}};
myclass.set_namespace(namespace_{"myns"});
myclass.set_name("myclass");

auto myclass_path = config.root_directory() / "include/myclass.h";

myclass.set_file(weakly_canonical(myclass_path).string());
CHECK(filter.should_include(myclass));
}

TEST_CASE("Test advanced diagram filter modules")
{
auto cfg =
Expand Down