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

Detailed Description

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

Definition at line 232 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)
 

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

309 , namespaces_{std::move(namespaces)}
310{
311}

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

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

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

315{
316 if (ns.is_empty())
317 return {};
318
319 auto res = tvl::any_of(namespaces_.begin(), namespaces_.end(),
320 [&ns, is_inclusive = is_inclusive()](const auto &nsit) {
321 if (std::holds_alternative<namespace_>(nsit.value())) {
322 const auto &ns_pattern = std::get<namespace_>(nsit.value());
323 if (is_inclusive)
324 return ns.starts_with(ns_pattern) ||
325 ns_pattern.starts_with(ns);
326
327 return ns.starts_with(ns_pattern);
328 }
329
330 const auto &regex = std::get<common::regex>(nsit.value());
331 return regex %= ns.to_string();
332 });
333
334 if ((type() == filter_t::kInclusive && tvl::is_false(res)) ||
335 (type() == filter_t::kExclusive && tvl::is_true(res))) {
336 LOG_TRACE("Namespace {} rejected by namespace_filter", ns.to_string());
337 }
338
339 return res;
340}

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

430{
431 return match(d, dynamic_cast<const element &>(p));
432}

Member Data Documentation

◆ namespaces_

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

Definition at line 246 of file diagram_filter.h.


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