0.6.1
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 808 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)
 
virtual void reset ()
 
- 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 1173 of file diagram_filter.cc.

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

◆ ~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 1298 of file diagram_filter.cc.

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

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

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

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

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

Member Data Documentation

◆ paths_

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

Definition at line 826 of file diagram_filter.h.

◆ root_

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

Definition at line 827 of file diagram_filter.h.


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