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::namespace_filter Struct Reference

Detailed Description

Match namespace or diagram element to a set of specified namespaces or regex patterns.

Definition at line 238 of file diagram_filter.h.

#include <diagram_filter.h>

Public Member Functions

 namespace_filter (filter_t type, std::vector< common::namespace_or_regex > namespaces)
 
 ~namespace_filter () override=default
 
tvl::value_t match (const diagram &d, const namespace_ &ns) const override
 
tvl::value_t match (const diagram &d, const element &e) const override
 
tvl::value_t match (const diagram &d, const sequence_diagram::model::participant &p) 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 ()
 

Private Attributes

std::vector< common::namespace_or_regexnamespaces_
 

Constructor & Destructor Documentation

◆ namespace_filter()

clanguml::common::model::namespace_filter::namespace_filter ( filter_t  type,
std::vector< common::namespace_or_regex namespaces 
)

Definition at line 319 of file diagram_filter.cc.

322 , namespaces_{std::move(namespaces)}
323{
324}

◆ ~namespace_filter()

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

Member Function Documentation

◆ match() [1/3]

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

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

Definition at line 355 of file diagram_filter.cc.

356{
357 tvl::value_t res;
358 if (d.type() != diagram_t::kPackage &&
359 dynamic_cast<const package *>(&e) != nullptr) {
360 res = tvl::any_of(namespaces_.begin(), namespaces_.end(),
361 [&e, is_inclusive = is_inclusive()](const auto &nsit) {
362 if (std::holds_alternative<namespace_>(nsit.value())) {
363 const auto &ns_pattern = std::get<namespace_>(nsit.value());
364
365 auto element_full_name_starts_with_namespace =
366 namespace_{e.name_and_ns()}.starts_with(ns_pattern);
367
368 auto element_full_name_equals_pattern =
369 namespace_{e.name_and_ns()} == ns_pattern;
370
371 auto pattern_starts_with_element_full_name =
372 ns_pattern.starts_with(namespace_{e.name_and_ns()});
373
374 auto result = element_full_name_starts_with_namespace ||
375 element_full_name_equals_pattern;
376
377 if (is_inclusive)
378 result =
379 result || pattern_starts_with_element_full_name;
380
381 return result;
382 }
383
384 return std::get<common::regex>(nsit.value()) %=
385 e.full_name(false);
386 });
387
388 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
389 (type() == filter_t::kExclusive && tvl::is_true(res))) {
390 LOG_TRACE(
391 "Element {} rejected by namespace_filter", e.full_name(false));
392 }
393
394 return res;
395 }
396
397 if (d.type() == diagram_t::kPackage) {
398 res = tvl::any_of(namespaces_.begin(), namespaces_.end(),
399 [&e, is_inclusive = is_inclusive()](const auto &nsit) {
400 if (std::holds_alternative<namespace_>(nsit.value())) {
401 auto e_ns = namespace_{e.full_name(false)};
402 auto nsit_ns = std::get<namespace_>(nsit.value());
403
404 if (is_inclusive)
405 return e_ns.starts_with(nsit_ns) ||
406 nsit_ns.starts_with(e_ns) || e_ns == nsit_ns;
407
408 return e_ns.starts_with(nsit_ns) || e_ns == nsit_ns;
409 }
410
411 return std::get<common::regex>(nsit.value()) %=
412 e.full_name(false);
413 });
414
415 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
416 (type() == filter_t::kExclusive && tvl::is_true(res))) {
417 LOG_TRACE(
418 "Element {} rejected by namespace_filter", e.full_name(false));
419 }
420 return res;
421 }
422
423 res = tvl::any_of(
424 namespaces_.begin(), namespaces_.end(), [&e](const auto &nsit) {
425 if (std::holds_alternative<namespace_>(nsit.value())) {
426 return e.get_namespace().starts_with(
427 std::get<namespace_>(nsit.value()));
428 }
429
430 return std::get<common::regex>(nsit.value()) %= e.full_name(false);
431 });
432
433 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
434 (type() == filter_t::kExclusive && tvl::is_true(res))) {
435 LOG_TRACE(
436 "Element {} rejected by namespace_filter", e.full_name(false));
437 }
438 return res;
439}

◆ match() [2/3]

tvl::value_t clanguml::common::model::namespace_filter::match ( const diagram d,
const namespace_ ns 
) const
overridevirtual

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

Definition at line 326 of file diagram_filter.cc.

328{
329 if (ns.is_empty())
330 return {};
331
332 auto res = tvl::any_of(namespaces_.begin(), namespaces_.end(),
333 [&ns, is_inclusive = is_inclusive()](const auto &nsit) {
334 if (std::holds_alternative<namespace_>(nsit.value())) {
335 const auto &ns_pattern = std::get<namespace_>(nsit.value());
336 if (is_inclusive)
337 return ns.starts_with(ns_pattern) ||
338 ns_pattern.starts_with(ns);
339
340 return ns.starts_with(ns_pattern);
341 }
342
343 const auto &regex = std::get<common::regex>(nsit.value());
344 return regex %= ns.to_string();
345 });
346
347 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
348 (type() == filter_t::kExclusive && tvl::is_true(res))) {
349 LOG_TRACE("Namespace {} rejected by namespace_filter", ns.to_string());
350 }
351
352 return res;
353}

◆ match() [3/3]

tvl::value_t clanguml::common::model::namespace_filter::match ( const diagram d,
const sequence_diagram::model::participant p 
) const
overridevirtual

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

Definition at line 441 of file diagram_filter.cc.

443{
444 return match(d, dynamic_cast<const element &>(p));
445}

Member Data Documentation

◆ namespaces_

std::vector<common::namespace_or_regex> clanguml::common::model::namespace_filter::namespaces_
private

Definition at line 252 of file diagram_filter.h.


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