Added regex support to dependencies and dependants filter
This commit is contained in:
@@ -640,6 +640,29 @@ bool diagram_filter::should_include(
|
||||
|
||||
void diagram_filter::init_filters(const config::diagram &c)
|
||||
{
|
||||
using specializations_filter_t =
|
||||
edge_traversal_filter<class_diagram::model::diagram,
|
||||
class_diagram::model::class_, common::string_or_regex>;
|
||||
|
||||
using class_dependants_filter_t =
|
||||
edge_traversal_filter<class_diagram::model::diagram,
|
||||
class_diagram::model::class_, common::string_or_regex>;
|
||||
using class_dependencies_filter_t =
|
||||
edge_traversal_filter<class_diagram::model::diagram,
|
||||
class_diagram::model::class_, common::string_or_regex>;
|
||||
|
||||
using package_dependants_filter_t =
|
||||
edge_traversal_filter<package_diagram::model::diagram,
|
||||
common::model::package, common::string_or_regex>;
|
||||
using package_dependencies_filter_t =
|
||||
edge_traversal_filter<package_diagram::model::diagram,
|
||||
common::model::package, common::string_or_regex>;
|
||||
|
||||
using source_file_dependency_filter_t =
|
||||
edge_traversal_filter<include_diagram::model::diagram,
|
||||
common::model::source_file, std::string,
|
||||
common::model::source_file>;
|
||||
|
||||
// Process inclusive filters
|
||||
if (c.include) {
|
||||
add_inclusive_filter(std::make_unique<namespace_filter>(
|
||||
@@ -682,58 +705,55 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
element_filters.emplace_back(std::make_unique<parents_filter>(
|
||||
filter_t::kInclusive, c.include().parents));
|
||||
|
||||
element_filters.emplace_back(std::make_unique<
|
||||
edge_traversal_filter<class_diagram::model::diagram,
|
||||
class_diagram::model::class_, common::string_or_regex>>(
|
||||
filter_t::kInclusive, relationship_t::kInstantiation,
|
||||
c.include().specializations));
|
||||
element_filters.emplace_back(
|
||||
std::make_unique<specializations_filter_t>(filter_t::kInclusive,
|
||||
relationship_t::kInstantiation,
|
||||
c.include().specializations));
|
||||
|
||||
element_filters.emplace_back(std::make_unique<
|
||||
edge_traversal_filter<class_diagram::model::diagram,
|
||||
class_diagram::model::class_>>(filter_t::kInclusive,
|
||||
relationship_t::kDependency, c.include().dependants));
|
||||
element_filters.emplace_back(
|
||||
std::make_unique<class_dependants_filter_t>(
|
||||
filter_t::kInclusive, relationship_t::kDependency,
|
||||
c.include().dependants));
|
||||
|
||||
element_filters.emplace_back(std::make_unique<
|
||||
edge_traversal_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<class_dependencies_filter_t>(
|
||||
filter_t::kInclusive, relationship_t::kDependency,
|
||||
c.include().dependencies, true));
|
||||
}
|
||||
else if (c.type() == diagram_t::kPackage) {
|
||||
element_filters.emplace_back(std::make_unique<edge_traversal_filter<
|
||||
package_diagram::model::diagram, common::model::package>>(
|
||||
filter_t::kInclusive, relationship_t::kDependency,
|
||||
c.include().dependants));
|
||||
element_filters.emplace_back(
|
||||
std::make_unique<package_dependants_filter_t>(
|
||||
filter_t::kInclusive, relationship_t::kDependency,
|
||||
c.include().dependants));
|
||||
|
||||
element_filters.emplace_back(std::make_unique<edge_traversal_filter<
|
||||
package_diagram::model::diagram, common::model::package>>(
|
||||
filter_t::kInclusive, relationship_t::kDependency,
|
||||
c.include().dependencies, true));
|
||||
element_filters.emplace_back(
|
||||
std::make_unique<package_dependencies_filter_t>(
|
||||
filter_t::kInclusive, relationship_t::kDependency,
|
||||
c.include().dependencies, true));
|
||||
}
|
||||
else if (c.type() == diagram_t::kInclude) {
|
||||
std::vector<std::string> dependants;
|
||||
std::vector<std::string> dependencies;
|
||||
|
||||
for (auto &&path : c.include().dependants) {
|
||||
const std::filesystem::path dep_path{path};
|
||||
const std::filesystem::path dep_path{*path.get<std::string>()};
|
||||
dependants.emplace_back(dep_path.lexically_normal().string());
|
||||
}
|
||||
|
||||
for (auto &&path : c.include().dependencies) {
|
||||
const std::filesystem::path dep_path{path};
|
||||
const std::filesystem::path dep_path{*path.get<std::string>()};
|
||||
dependencies.emplace_back(dep_path.lexically_normal().string());
|
||||
}
|
||||
|
||||
element_filters.emplace_back(std::make_unique<edge_traversal_filter<
|
||||
include_diagram::model::diagram, common::model::source_file,
|
||||
std::string, common::model::source_file>>(
|
||||
filter_t::kInclusive, relationship_t::kAssociation,
|
||||
dependants));
|
||||
element_filters.emplace_back(
|
||||
std::make_unique<source_file_dependency_filter_t>(
|
||||
filter_t::kInclusive, relationship_t::kAssociation,
|
||||
dependants));
|
||||
|
||||
element_filters.emplace_back(std::make_unique<edge_traversal_filter<
|
||||
include_diagram::model::diagram, common::model::source_file,
|
||||
std::string, common::model::source_file>>(
|
||||
filter_t::kInclusive, relationship_t::kAssociation,
|
||||
dependencies, true));
|
||||
element_filters.emplace_back(
|
||||
std::make_unique<source_file_dependency_filter_t>(
|
||||
filter_t::kInclusive, relationship_t::kAssociation,
|
||||
dependencies, true));
|
||||
}
|
||||
|
||||
element_filters.emplace_back(std::make_unique<context_filter>(
|
||||
@@ -781,29 +801,23 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
add_exclusive_filter(std::make_unique<parents_filter>(
|
||||
filter_t::kExclusive, c.exclude().parents));
|
||||
|
||||
add_exclusive_filter(std::make_unique<
|
||||
edge_traversal_filter<class_diagram::model::diagram,
|
||||
class_diagram::model::class_, common::string_or_regex>>(
|
||||
filter_t::kExclusive, relationship_t::kInstantiation,
|
||||
c.exclude().specializations));
|
||||
add_exclusive_filter(
|
||||
std::make_unique<specializations_filter_t>(filter_t::kExclusive,
|
||||
relationship_t::kInstantiation, c.exclude().specializations));
|
||||
|
||||
add_exclusive_filter(std::make_unique<edge_traversal_filter<
|
||||
class_diagram::model::diagram, class_diagram::model::class_>>(
|
||||
filter_t::kExclusive, relationship_t::kDependency,
|
||||
c.exclude().dependants));
|
||||
add_exclusive_filter(
|
||||
std::make_unique<class_dependants_filter_t>(filter_t::kExclusive,
|
||||
relationship_t::kDependency, c.exclude().dependants));
|
||||
|
||||
add_exclusive_filter(std::make_unique<edge_traversal_filter<
|
||||
package_diagram::model::diagram, common::model::package>>(
|
||||
filter_t::kExclusive, relationship_t::kDependency,
|
||||
c.exclude().dependants));
|
||||
add_exclusive_filter(
|
||||
std::make_unique<package_dependants_filter_t>(filter_t::kExclusive,
|
||||
relationship_t::kDependency, c.exclude().dependants));
|
||||
|
||||
add_exclusive_filter(std::make_unique<edge_traversal_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<class_dependencies_filter_t>(filter_t::kExclusive,
|
||||
relationship_t::kDependency, c.exclude().dependencies, true));
|
||||
|
||||
add_exclusive_filter(std::make_unique<edge_traversal_filter<
|
||||
package_diagram::model::diagram, common::model::package>>(
|
||||
add_exclusive_filter(std::make_unique<package_dependencies_filter_t>(
|
||||
filter_t::kExclusive, relationship_t::kDependency,
|
||||
c.exclude().dependencies, true));
|
||||
|
||||
@@ -812,9 +826,9 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
std::vector<std::string> dependencies;
|
||||
|
||||
for (auto &&path : c.exclude().dependants) {
|
||||
std::filesystem::path dep_path{path};
|
||||
std::filesystem::path dep_path{*path.get<std::string>()};
|
||||
if (dep_path.is_relative()) {
|
||||
dep_path = c.base_directory() / path;
|
||||
dep_path = c.base_directory() / *path.get<std::string>();
|
||||
dep_path = relative(dep_path, c.relative_to());
|
||||
}
|
||||
|
||||
@@ -822,9 +836,9 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
}
|
||||
|
||||
for (auto &&path : c.exclude().dependencies) {
|
||||
std::filesystem::path dep_path{path};
|
||||
std::filesystem::path dep_path{*path.get<std::string>()};
|
||||
if (dep_path.is_relative()) {
|
||||
dep_path = c.base_directory() / path;
|
||||
dep_path = c.base_directory() / *path.get<std::string>();
|
||||
dep_path = relative(dep_path, c.relative_to());
|
||||
}
|
||||
|
||||
|
||||
@@ -289,8 +289,7 @@ private:
|
||||
for (const auto &root_pattern : roots_) {
|
||||
if constexpr (std::is_same_v<ConfigEntryT,
|
||||
common::string_or_regex>) {
|
||||
auto root_refs = cd.template find<class_diagram::model::class_>(
|
||||
root_pattern);
|
||||
auto root_refs = cd.template find<ElementT>(root_pattern);
|
||||
|
||||
for (auto &root : root_refs) {
|
||||
if (root.has_value())
|
||||
|
||||
@@ -207,6 +207,14 @@ template <typename T> struct or_regex {
|
||||
return std::get<T>(value_) == v;
|
||||
}
|
||||
|
||||
template <typename Ret> std::optional<Ret> get() const
|
||||
{
|
||||
if (!std::holds_alternative<Ret>(value_))
|
||||
return std::nullopt;
|
||||
|
||||
return std::get<Ret>(value_);
|
||||
}
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
if (std::holds_alternative<regex>(value_))
|
||||
|
||||
@@ -103,9 +103,9 @@ struct filter {
|
||||
|
||||
std::vector<common::string_or_regex> specializations;
|
||||
|
||||
std::vector<std::string> dependants;
|
||||
std::vector<common::string_or_regex> dependants;
|
||||
|
||||
std::vector<std::string> dependencies;
|
||||
std::vector<common::string_or_regex> dependencies;
|
||||
|
||||
std::vector<common::string_or_regex> context;
|
||||
|
||||
|
||||
@@ -58,6 +58,10 @@ public:
|
||||
template <typename ElementT>
|
||||
opt_ref<ElementT> find(diagram_element::id_t id) const;
|
||||
|
||||
template <typename ElementT>
|
||||
std::vector<opt_ref<ElementT>> find(
|
||||
const clanguml::common::string_or_regex &pattern) const;
|
||||
|
||||
template <typename ElementT>
|
||||
bool add(const path &parent_path, std::unique_ptr<ElementT> &&e)
|
||||
{
|
||||
@@ -106,6 +110,23 @@ opt_ref<ElementT> diagram::find(diagram_element::id_t id) const
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename ElementT>
|
||||
std::vector<opt_ref<ElementT>> diagram::find(
|
||||
const common::string_or_regex &pattern) const
|
||||
{
|
||||
std::vector<opt_ref<ElementT>> result;
|
||||
|
||||
for (const auto &element : element_view<ElementT>::view()) {
|
||||
const auto full_name = element.get().full_name(false);
|
||||
|
||||
if (pattern == full_name) {
|
||||
result.emplace_back(element);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename ElementT>
|
||||
bool diagram::add_with_namespace_path(std::unique_ptr<ElementT> &&p)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user