0.6.0
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 709 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
 
tvl::value_t match (const diagram &d, const common::model::element &e) 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 class_diagram::model::objc_method &m) const
 
virtual tvl::value_t match (const diagram &d, const class_diagram::model::objc_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)
 
- Public Member Functions inherited from clanguml::util::memoized< std::filesystem::path, bool, std::filesystem::path >
auto memoize (bool is_complete, F &&f, Args... args) const
 
void invalidate (Args... args) const
 

Private Attributes

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

Additional Inherited Members

- Public Types inherited from clanguml::util::memoized< std::filesystem::path, bool, std::filesystem::path >
using key_t = std::tuple< Args... >
 
using value_t = bool
 

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 1171 of file diagram_filter.cc.

1174 , root_{root}
1175{
1176 for (const auto &path : p) {
1177 std::filesystem::path absolute_path;
1178
1179 if (path.empty() || path == ".")
1180 absolute_path = root;
1181 else if (std::filesystem::path{path}.is_relative())
1182 absolute_path = root / path;
1183 else
1184 absolute_path = path;
1185
1186 bool match_successful{false};
1187 for (auto &resolved_glob_path :
1188 glob::glob(absolute_path.string(), true)) {
1189 try {
1190 auto resolved_absolute_path = absolute(resolved_glob_path);
1191 resolved_absolute_path =
1192 canonical(resolved_absolute_path.lexically_normal());
1193
1194 resolved_absolute_path.make_preferred();
1195
1196 LOG_DBG("Added path {} to paths_filter",
1197 resolved_absolute_path.string());
1198
1199 paths_.emplace_back(std::move(resolved_absolute_path));
1200
1201 match_successful = true;
1202 }
1203 catch (std::filesystem::filesystem_error &e) {
1204 LOG_WARN("Cannot add non-existent path {} to "
1205 "paths filter",
1206 absolute_path.string());
1207 continue;
1208 }
1209 }
1210
1211 if (!match_successful)
1212 LOG_WARN("Paths filter pattern '{}' did not match "
1213 "any files relative to '{}'",
1214 path, root_.string());
1215 }
1216}

◆ ~paths_filter()

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

Member Function Documentation

◆ match() [1/3]

tvl::value_t clanguml::common::model::paths_filter::match ( const diagram d,
const common::model::element e 
) const
overridevirtual

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

Definition at line 1296 of file diagram_filter.cc.

1298{
1299 return match(d, dynamic_cast<const common::model::source_location &>(e));
1300}

◆ match() [2/3]

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 1218 of file diagram_filter.cc.

1220{
1221 if (paths_.empty()) {
1222 return {};
1223 }
1224
1225 // Matching source paths doesn't make sense if they are not absolute
1226 if (!p.is_absolute()) {
1227 return {};
1228 }
1229
1230 const auto source_file_path = p.fs_path(root_);
1231
1232 auto res = memoize(
1233 true,
1234 [this](const std::filesystem::path &sfp) {
1235 return std::any_of(
1236 paths_.begin(), paths_.end(), [&](const auto &path) {
1237 return sfp.root_name().string() ==
1238 path.root_name().string() &&
1239 util::is_relative_to(
1240 sfp.relative_path(), path.relative_path());
1241 });
1242 },
1243 source_file_path);
1244
1245 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
1246 (type() == filter_t::kExclusive && tvl::is_true(res))) {
1247 LOG_TRACE("Source file {} [{}] rejected by paths_filter",
1248 p.full_name(false), source_file_path.string());
1249 }
1250
1251 if ((type() == filter_t::kInclusive && tvl::is_true(res)) ||
1252 (type() == filter_t::kExclusive && tvl::is_false(res))) {
1253 LOG_TRACE("Source file {} [{}] accepted by paths_filter",
1254 p.full_name(false), source_file_path.string());
1255 }
1256
1257 return res;
1258}

◆ match() [3/3]

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 1260 of file diagram_filter.cc.

1262{
1263 if (paths_.empty()) {
1264 return {};
1265 }
1266
1267 const auto source_location_path = std::filesystem::path{p.file()};
1268
1269 // Matching source paths doesn't make sense if they are not absolute or
1270 // empty
1271 if (p.file().empty() || source_location_path.is_relative()) {
1272 return {};
1273 }
1274
1275 auto res = memoize(
1276 true,
1277 [this](const std::filesystem::path &p) {
1278 return std::any_of(
1279 paths_.begin(), paths_.end(), [&](const auto &path) {
1280 return p.root_name().string() ==
1281 path.root_name().string() &&
1282 util::is_relative_to(
1283 p.relative_path(), path.relative_path());
1284 });
1285 },
1286 source_location_path);
1287
1288 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
1289 (type() == filter_t::kExclusive && tvl::is_true(res))) {
1290 LOG_TRACE("Source location {} rejected by paths_filter", p.file());
1291 }
1292
1293 return res;
1294}

Member Data Documentation

◆ paths_

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

Definition at line 727 of file diagram_filter.h.

◆ root_

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

Definition at line 728 of file diagram_filter.h.


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