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

Detailed Description

Match element's name to a set of names or regex patterns.

Definition at line 267 of file diagram_filter.h.

#include <diagram_filter.h>

Public Member Functions

 element_filter (filter_t type, std::vector< config::element_filter_t > elements)
 
 ~element_filter () override=default
 
tvl::value_t match (const diagram &d, const element &e) const override
 
tvl::value_t match (const diagram &d, const class_diagram::model::class_method &m) const override
 
tvl::value_t match (const diagram &d, const class_diagram::model::class_member &m) const override
 
tvl::value_t match (const diagram &d, const class_diagram::model::objc_method &m) const override
 
tvl::value_t match (const diagram &d, const class_diagram::model::objc_member &m) 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)
 

Private Attributes

std::vector< config::element_filter_telements_
 

Constructor & Destructor Documentation

◆ element_filter()

clanguml::common::model::element_filter::element_filter ( filter_t  type,
std::vector< config::element_filter_t elements 
)

Definition at line 480 of file diagram_filter.cc.

483 , elements_{std::move(elements)}
484{
485}

◆ ~element_filter()

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

Member Function Documentation

◆ match() [1/6]

tvl::value_t clanguml::common::model::element_filter::match ( const diagram d,
const class_diagram::model::class_member m 
) const
overridevirtual

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

Definition at line 535 of file diagram_filter.cc.

537{
538 auto res = tvl::any_of(elements_.begin(), elements_.end(),
539 [&m](const auto &ef) -> tvl::value_t {
540 // Apply this filter only if it had `member` type, do not apply
541 // `any` filters to methods for backward compatibility
542 if (ef.type != config::element_filter_t::filtered_type::member)
543 return {};
544
545 return ef.name == m.qualified_name();
546 });
547
548 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
549 (type() == filter_t::kExclusive && tvl::is_true(res))) {
550 LOG_TRACE(
551 "Class member {} rejected by element_filter", m.qualified_name());
552 }
553
554 return res;
555}

◆ match() [2/6]

tvl::value_t clanguml::common::model::element_filter::match ( const diagram d,
const class_diagram::model::class_method m 
) const
overridevirtual

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

Definition at line 513 of file diagram_filter.cc.

515{
516 auto res = tvl::any_of(elements_.begin(), elements_.end(),
517 [&m](const auto &ef) -> tvl::value_t {
518 // Apply this filter only if it had `method` type, do not apply
519 // `any` filters to methods for backward compatibility
520 if (ef.type != config::element_filter_t::filtered_type::method)
521 return {};
522
523 return ef.name == m.qualified_name();
524 });
525
526 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
527 (type() == filter_t::kExclusive && tvl::is_true(res))) {
528 LOG_TRACE(
529 "Class method {} rejected by element_filter", m.display_name());
530 }
531
532 return res;
533}

◆ match() [3/6]

tvl::value_t clanguml::common::model::element_filter::match ( const diagram d,
const class_diagram::model::objc_member m 
) const
overridevirtual

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

Definition at line 579 of file diagram_filter.cc.

581{
582 auto res = tvl::any_of(elements_.begin(), elements_.end(),
583 [&m](const auto &ef) -> tvl::value_t {
584 // Apply this filter only if it had `method` type, do not apply
585 // `any` filters to methods for backward compatibility
586 if (ef.type != config::element_filter_t::filtered_type::objc_member)
587 return {};
588
589 return ef.name == m.qualified_name();
590 });
591
592 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
593 (type() == filter_t::kExclusive && tvl::is_true(res))) {
594 LOG_TRACE(
595 "ObjC member {} rejected by element_filter", m.qualified_name());
596 }
597
598 return res;
599}

◆ match() [4/6]

tvl::value_t clanguml::common::model::element_filter::match ( const diagram d,
const class_diagram::model::objc_method m 
) const
overridevirtual

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

Definition at line 557 of file diagram_filter.cc.

559{
560 auto res = tvl::any_of(elements_.begin(), elements_.end(),
561 [&m](const auto &ef) -> tvl::value_t {
562 // Apply this filter only if it had `objc_method` type, do not apply
563 // `any` filters to methods for backward compatibility
564 if (ef.type != config::element_filter_t::filtered_type::objc_method)
565 return {};
566
567 return ef.name == m.qualified_name();
568 });
569
570 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
571 (type() == filter_t::kExclusive && tvl::is_true(res))) {
572 LOG_TRACE(
573 "ObjC method {} rejected by element_filter", m.qualified_name());
574 }
575
576 return res;
577}

◆ match() [5/6]

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

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

Definition at line 487 of file diagram_filter.cc.

488{
489 // Do not apply element filter to packages in class diagrams
490 if (d.type() == diagram_t::kClass && e.type_name() == "package")
491 return std::nullopt;
492
493 auto res =
494 tvl::any_of(elements_.begin(), elements_.end(), [&e](const auto &el) {
495 // First check if elements type matches the filter
496 if ((el.type != config::element_filter_t::filtered_type::any) &&
497 (config::to_string(el.type) != e.type_name())) {
498 return false;
499 }
500
501 return ((el.name == e.full_name(false)) ||
502 (el.name == fmt::format("::{}", e.full_name(false))));
503 });
504
505 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
506 (type() == filter_t::kExclusive && tvl::is_true(res))) {
507 LOG_TRACE("Element {} rejected by element_filter", e.full_name(false));
508 }
509
510 return res;
511}

◆ match() [6/6]

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

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

Definition at line 601 of file diagram_filter.cc.

603{
604 using sequence_diagram::model::method;
605 using sequence_diagram::model::participant;
606
607 if (d.type() != diagram_t::kSequence)
608 return {};
609
610 const auto &sequence_model =
611 dynamic_cast<const sequence_diagram::model::diagram &>(d);
612 auto res = tvl::any_of(elements_.begin(), elements_.end(),
613 [&sequence_model, &p](const auto &el) {
614 // First check if elements type matches the filter
615 if (el.type != config::element_filter_t::filtered_type::any &&
616 config::to_string(el.type) != p.type_name()) {
617 return false;
618 }
619
620 if (p.type_name() == "method") {
621 const auto &m = dynamic_cast<const method &>(p);
622 const auto class_id = m.class_id();
623 const auto &class_participant =
624 sequence_model.get_participant<participant>(class_id)
625 .value();
626
627 return (el.name == p.name_and_ns()) ||
628 (el.name == p.full_name(false)) ||
629 (el.name == class_participant.full_name(false));
630 }
631
632 if (p.type_name() == "objc_method") {
633 const auto &m =
634 dynamic_cast<const sequence_diagram::model::objc_method &>(
635 p);
636 const auto class_id = m.class_id();
637 const auto &class_participant =
638 sequence_model.get_participant<participant>(class_id)
639 .value();
640
641 return (el.name == p.name_and_ns()) ||
642 (el.name == p.full_name(false)) ||
643 (el.name == class_participant.full_name(false));
644 }
645
646 return el.name == p.full_name(false);
647 });
648
649 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
650 (type() == filter_t::kExclusive && tvl::is_true(res))) {
651 LOG_TRACE(
652 "Participant {} rejected by element_filter", p.full_name(false));
653 }
654
655 return res;
656}

Member Data Documentation

◆ elements_

std::vector<config::element_filter_t> clanguml::common::model::element_filter::elements_
private

Definition at line 291 of file diagram_filter.h.


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