0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
clanguml::common::model::paths_filter Struct Reference

Detailed Description

Match elements based on their source location, whether it matches to a specified file paths.

Definition at line 699 of file diagram_filter.h.

#include <diagram_filter.h>

Public Member Functions

 paths_filter (filter_t type, const std::vector< std::string > &p, const std::filesystem::path &root)
 
 ~paths_filter () override=default
 
tvl::value_t match (const diagram &d, const common::model::source_file &r) const override
 
tvl::value_t match (const diagram &d, const common::model::source_location &sl) const override
 
- Public Member Functions inherited from clanguml::common::model::filter_visitor
 filter_visitor (filter_t type)
 
virtual ~filter_visitor ()=default
 
virtual tvl::value_t match (const diagram &d, const common::model::element &e) const
 
virtual tvl::value_t match (const diagram &d, const common::model::relationship &r) const
 
virtual tvl::value_t match (const diagram &d, const common::model::relationship_t &r) const
 
virtual tvl::value_t match (const diagram &d, const common::model::access_t &a) const
 
virtual tvl::value_t match (const diagram &d, const common::model::namespace_ &ns) const
 
virtual tvl::value_t match (const diagram &d, const common::model::source_file &f) const
 
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
 
virtual tvl::value_t match (const diagram &d, const sequence_diagram::model::participant &p) const
 
bool is_inclusive () const
 
bool is_exclusive () const
 
filter_t type () const
 
filter_mode_t mode () const
 
void set_mode (filter_mode_t mode)
 

Private Attributes

std::vector< std::filesystem::path > paths_
 
std::filesystem::path root_
 

Constructor & Destructor Documentation

◆ paths_filter()

clanguml::common::model::paths_filter::paths_filter ( filter_t  type,
const std::vector< std::string > &  p,
const std::filesystem::path &  root 
)

Definition at line 958 of file diagram_filter.cc.

961 , root_{root}
962{
963 for (const auto &path : p) {
964 std::filesystem::path absolute_path;
965
966 if (path.empty() || path == ".")
967 absolute_path = root;
968 else if (std::filesystem::path{path}.is_relative())
969 absolute_path = root / path;
970 else
971 absolute_path = path;
972
973 bool match_successful{false};
974 for (auto &resolved_glob_path :
975 glob::glob(absolute_path.string(), true)) {
976 try {
977 auto resolved_absolute_path = absolute(resolved_glob_path);
978 resolved_absolute_path =
979 canonical(resolved_absolute_path.lexically_normal());
980
981 resolved_absolute_path.make_preferred();
982
983 LOG_DBG("Added path {} to paths_filter",
984 resolved_absolute_path.string());
985
986 paths_.emplace_back(std::move(resolved_absolute_path));
987
988 match_successful = true;
989 }
990 catch (std::filesystem::filesystem_error &e) {
991 LOG_WARN("Cannot add non-existent path {} to "
992 "paths filter",
993 absolute_path.string());
994 continue;
995 }
996 }
997
998 if (!match_successful)
999 LOG_WARN("Paths filter pattern '{}' did not match "
1000 "any files relative to '{}'",
1001 path, root_.string());
1002 }
1003}

◆ ~paths_filter()

clanguml::common::model::paths_filter::~paths_filter ( )
overridedefault

Member Function Documentation

◆ match() [1/2]

tvl::value_t clanguml::common::model::paths_filter::match ( const diagram d,
const common::model::source_file r 
) const
overridevirtual

Reimplemented from clanguml::common::model::filter_visitor.

Definition at line 1005 of file diagram_filter.cc.

1007{
1008 if (paths_.empty()) {
1009 return {};
1010 }
1011
1012 // Matching source paths doesn't make sense if they are not absolute
1013 if (!p.is_absolute()) {
1014 return {};
1015 }
1016
1017 auto pp = p.fs_path(root_);
1018 for (const auto &path : paths_) {
1019 if (pp.root_name().string() == path.root_name().string() &&
1020 util::starts_with(pp.relative_path(), path.relative_path())) {
1021
1022 return true;
1023 }
1024 }
1025
1026 return false;
1027}

◆ match() [2/2]

tvl::value_t clanguml::common::model::paths_filter::match ( const diagram d,
const common::model::source_location sl 
) const
overridevirtual

Reimplemented from clanguml::common::model::filter_visitor.

Definition at line 1029 of file diagram_filter.cc.

1031{
1032 if (paths_.empty()) {
1033 return {};
1034 }
1035
1036 auto sl_path = std::filesystem::path{p.file()};
1037
1038 // Matching source paths doesn't make sens if they are not absolute or
1039 // empty
1040 if (p.file().empty() || sl_path.is_relative()) {
1041 return {};
1042 }
1043
1044 for (const auto &path : paths_) {
1045 if (sl_path.root_name().string() == path.root_name().string() &&
1046 util::starts_with(sl_path.relative_path(), path.relative_path())) {
1047
1048 return true;
1049 }
1050 }
1051
1052 return false;
1053}

Member Data Documentation

◆ paths_

std::vector<std::filesystem::path> clanguml::common::model::paths_filter::paths_
private

Definition at line 712 of file diagram_filter.h.

◆ root_

std::filesystem::path clanguml::common::model::paths_filter::root_
private

Definition at line 713 of file diagram_filter.h.


The documentation for this struct was generated from the following files: