0.6.2
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
clanguml::config::diagram Struct Referenceabstract

Common diagram configuration type. More...

Detailed Description

Common diagram configuration type.

This class provides common interface for diagram configuration sections of different diagram types.

Definition at line 714 of file config.h.

#include <config.h>

Public Member Functions

 ~diagram () override=default
 
virtual common::model::diagram_t type () const =0
 
std::vector< std::string > glob_translation_units (const std::vector< std::string > &compilation_database_files, bool is_fixed=false) const
 Filter translation units based on glob patterns.
 
std::filesystem::path make_path_relative (const std::filesystem::path &p) const
 Make path relative to the relative_to config option.
 
std::vector< std::string > make_module_relative (const std::optional< std::string > &maybe_module) const
 Make module path relative to using_module configuration option.
 
std::optional< std::string > get_together_group (const std::string &full_name) const
 
void initialize_type_aliases ()
 Initialize predefined set of C++ type aliases.
 
- Public Member Functions inherited from clanguml::config::inheritable_diagram_options
virtual ~inheritable_diagram_options ()=default
 
void inherit (const inheritable_diagram_options &parent)
 
std::string simplify_template_type (std::string full_name) const
 
bool generate_fully_qualified_name () const
 Whether the diagram element should be fully qualified in diagram.
 
std::filesystem::path root_directory () const
 Returns absolute path of the relative_to option.
 
option< std::filesystem::path > & get_relative_to ()
 Get reference to relative_to diagram config option.
 

Public Attributes

std::string name
 
option< std::string > title {"title"}
 
- Public Attributes inherited from clanguml::config::inheritable_diagram_options
option< glob_tglob {"glob"}
 
option< common::model::namespace_using_namespace {"using_namespace"}
 
option< std::string > using_module {"using_module"}
 
option< bool > include_relations_also_as_members
 
option< filter_mode_tfilter_mode {"filter_mode", filter_mode_t::basic}
 
option< bool > include_system_headers {"include_system_headers", false}
 
option< filterinclude {"include"}
 
option< filterexclude {"exclude"}
 
option< plantumlpuml {"plantuml", option_inherit_mode::kAppend}
 
option< struct mermaidmermaid {"mermaid", option_inherit_mode::kAppend}
 
option< struct graphmlgraphml {"graphml", option_inherit_mode::kAppend}
 
option< method_argumentsgenerate_method_arguments
 
option< bool > generate_method_argument_names
 
option< bool > generate_concept_requirements
 
option< bool > group_methods {"group_methods", true}
 
option< member_order_tmember_order
 
option< bool > generate_packages {"generate_packages", false}
 
option< package_type_tpackage_type
 
option< bool > generate_template_argument_dependencies
 
option< bool > skip_redundant_dependencies
 
option< generate_links_configgenerate_links {"generate_links"}
 
option< git_configgit {"git"}
 
option< layout_hintslayout {"layout"}
 
option< std::filesystem::path > base_directory {"__parent_path"}
 
option< bool > generate_system_headers {"generate_system_headers", false}
 
option< relationship_hints_trelationship_hints {"relationship_hints"}
 
option< type_aliases_ttype_aliases
 
option< comment_parser_tcomment_parser
 
option< bool > combine_free_functions_into_file_participants
 
option< bool > inline_lambda_messages {"inline_lambda_messages", false}
 
option< bool > generate_return_types {"generate_return_types", false}
 
option< bool > generate_return_values {"generate_return_values", false}
 
option< bool > generate_condition_statements
 
option< std::vector< std::string > > participants_order {"participants_order"}
 
option< bool > generate_message_comments {"generate_message_comments", false}
 
option< bool > fold_repeated_activities {"fold_repeated_activities", false}
 
option< unsigned > message_comment_width
 
option< unsigned > message_name_width
 
option< bool > debug_mode {"debug_mode", false}
 
option< bool > generate_metadata {"generate_metadata", true}
 
option< bool > allow_empty_diagrams {"allow_empty_diagrams", false}
 
option< inja::json > user_data {"user_data", {}, option_inherit_mode::kAppend}
 

Additional Inherited Members

- Protected Attributes inherited from clanguml::config::inheritable_diagram_options
option< std::filesystem::path > relative_to {"relative_to"}
 

Constructor & Destructor Documentation

◆ ~diagram()

clanguml::config::diagram::~diagram ( )
overridedefault

Member Function Documentation

◆ get_together_group()

std::optional< std::string > clanguml::config::diagram::get_together_group ( const std::string &  full_name) const

Definition at line 524 of file config.cc.

526{
527 const auto relative_name = using_namespace().relative(full_name);
528
529 for (const auto &[hint_target, hints] : layout()) {
530 for (const auto &hint : hints) {
531 if (hint.hint == hint_t::together) {
532 const auto &together_others =
533 std::get<std::vector<std::string>>(hint.entity);
534
535 if ((full_name == hint_target) ||
536 util::contains(together_others, full_name))
537 return hint_target;
538
539 if ((relative_name == hint_target) ||
540 util::contains(together_others, relative_name))
541 return hint_target;
542 }
543 }
544 }
545
546 return std::nullopt;
547}

◆ glob_translation_units()

std::vector< std::string > clanguml::config::diagram::glob_translation_units ( const std::vector< std::string > &  compilation_database_files,
bool  is_fixed = false 
) const

Filter translation units based on glob patterns.

Returns
List of translation unit paths

Definition at line 360 of file config.cc.

363{
364 // Make sure that the paths are in preferred format for a given platform
365 // before intersecting the matches with compliation database
366 std::vector<std::string> compilation_database_paths;
367 compilation_database_paths.reserve(compilation_database_files.size());
368 for (const auto &cdf : compilation_database_files) {
369 std::filesystem::path p{cdf};
370 p.make_preferred();
371 compilation_database_paths.emplace_back(p.string());
372 }
373
374 // If glob is not defined use all translation units from the
375 // compilation database
376 if (!glob.has_value || (glob().include.empty() && glob().exclude.empty())) {
377 return compilation_database_paths;
378 }
379
380 // Create also a canonical database paths set
381 std::vector<std::string> canonical_compilation_database_paths;
382 canonical_compilation_database_paths.reserve(
383 compilation_database_paths.size());
384 for (const auto &cdp : compilation_database_paths) {
385 auto canonical_p = weakly_canonical(std::filesystem::path{cdp});
386 canonical_compilation_database_paths.emplace_back(canonical_p.string());
387 }
388
389 // Otherwise, get all translation units matching the glob from diagram
390 // configuration
391 std::vector<std::string> glob_matches{};
392
393 LOG_DBG("Looking for translation units in {}", root_directory().string());
394
395 for (const auto &g : glob().include) {
396 if (g.is_regex()) {
397 LOG_DBG("Matching inclusive glob regex {}", g.to_string());
398
399 std::regex regex_pattern(
400 g.to_string(), std::regex_constants::optimize);
401
402 std::copy_if(compilation_database_paths.begin(),
403 compilation_database_paths.end(),
404 std::back_inserter(glob_matches),
405 [&regex_pattern](const auto &tu) {
406 std::smatch m;
407
408 return exists(std::filesystem::path{tu}) &&
409 std::regex_search(tu, m, regex_pattern);
410 });
411 }
412 else {
413 std::filesystem::path absolute_glob_path{g.to_string()};
414
415#ifdef _MSC_VER
416 if (!absolute_glob_path.has_root_name())
417#else
418 if (!absolute_glob_path.is_absolute())
419#endif
420 absolute_glob_path = root_directory() / absolute_glob_path;
421
422 LOG_DBG("Searching glob path {}", absolute_glob_path.string());
423
424 auto matches = glob::glob(absolute_glob_path.string(), true, false);
425
426 for (const auto &match : matches) {
427 const auto path =
428 std::filesystem::canonical(root_directory() / match);
429
430 glob_matches.emplace_back(path.string());
431 }
432 }
433 }
434
435 if (glob().include.empty())
436 glob_matches = compilation_database_paths;
437
438 for (const auto &g : glob().exclude) {
439 if (g.is_regex()) {
440 LOG_DBG("Matching exclusive glob regex {}", g.to_string());
441
442 std::regex regex_pattern(
443 g.to_string(), std::regex_constants::optimize);
444
445 for (const auto &cdf : compilation_database_paths) {
446 std::smatch m;
447 if (std::regex_search(cdf, m, regex_pattern)) {
448 glob_matches.erase(
449 remove(begin(glob_matches), end(glob_matches), cdf),
450 glob_matches.end());
451 }
452 }
453 }
454 else {
455 std::filesystem::path absolute_glob_path{g.to_string()};
456
457#ifdef _MSC_VER
458 if (!absolute_glob_path.has_root_name())
459#else
460 if (!absolute_glob_path.is_absolute())
461#endif
462 absolute_glob_path = root_directory() / absolute_glob_path;
463
464 LOG_DBG("Searching exclusive glob path {}",
465 absolute_glob_path.string());
466
467 auto matches = glob::glob(absolute_glob_path.string(), true, false);
468
469 for (const auto &match : matches) {
470 const auto path =
471 std::filesystem::canonical(root_directory() / match);
472
473 glob_matches.erase(remove(begin(glob_matches),
474 end(glob_matches), path.string()),
475 glob_matches.end());
476 }
477 }
478 }
479
480 // Calculate intersection between glob matches and compilation database
481 std::vector<std::string> result;
482 for (const auto &gm : glob_matches) {
483 std::filesystem::path gm_path{gm};
484 gm_path.make_preferred();
485 if (is_fixed || util::contains(compilation_database_paths, gm_path) ||
486 util::contains(canonical_compilation_database_paths, gm_path) ||
487 util::contains(compilation_database_files, gm)) {
488 result.emplace_back(gm_path.string());
489 }
490 }
491
492 return result;
493}

◆ initialize_type_aliases()

void clanguml::config::diagram::initialize_type_aliases ( )

Initialize predefined set of C++ type aliases.

This method is responsible for setting up a predefined set of C++ aliases to make the diagrams look nicer, for instance we want to have std::string instead of std::basic_string<char>.

Definition at line 549 of file config.cc.

550{
551 if (type_aliases().count("std::basic_string<char>") == 0U) {
552 type_aliases().insert({"std::basic_string<char>", "std::string"});
553 }
554 if (type_aliases().count("std::basic_string<char,std::char_traits<"
555 "char>,std::allocator<char>>") == 0U) {
556 type_aliases().insert({"std::basic_string<char,std::char_traits<"
557 "char>,std::allocator<char>>",
558 "std::string"});
559 }
560 if (type_aliases().count("std::basic_string<wchar_t>") == 0U) {
561 type_aliases().insert({"std::basic_string<wchar_t>", "std::wstring"});
562 }
563 if (type_aliases().count("std::basic_string<char16_t>") == 0U) {
564 type_aliases().insert(
565 {"std::basic_string<char16_t>", "std::u16string"});
566 }
567 if (type_aliases().count("std::basic_string<char32_t>") == 0U) {
568 type_aliases().insert(
569 {"std::basic_string<char32_t>", "std::u32string"});
570 }
571 if (type_aliases().count("std::integral_constant<bool,true>") == 0U) {
572 type_aliases().insert(
573 {"std::integral_constant<bool,true>", "std::true_type"});
574 }
575 if (type_aliases().count("std::integral_constant<bool,false>") == 0U) {
576 type_aliases().insert(
577 {"std::integral_constant<bool,false>", "std::false_type"});
578 }
579#if LLVM_VERSION_MAJOR >= 16
580 if (type_aliases().count("std::basic_string") == 0U) {
581 type_aliases().insert({"std::basic_string", "std::string"});
582 }
583#endif
584}

◆ make_module_relative()

std::vector< std::string > clanguml::config::diagram::make_module_relative ( const std::optional< std::string > &  maybe_module) const

Make module path relative to using_module configuration option.

Parameters
pInput path
Returns
Relative path

Definition at line 501 of file config.cc.

503{
504 if (!maybe_module)
505 return {};
506
507 auto module_path = common::model::path(
508 maybe_module.value(), common::model::path_type::kModule)
509 .tokens();
510
512 auto using_module_path = common::model::path(
514 .tokens();
515
516 if (util::starts_with(module_path, using_module_path)) {
517 util::remove_prefix(module_path, using_module_path);
518 }
519 }
520
521 return module_path;
522}

◆ make_path_relative()

std::filesystem::path clanguml::config::diagram::make_path_relative ( const std::filesystem::path &  p) const

Make path relative to the relative_to config option.

Parameters
pInput path
Returns
Relative path

Definition at line 495 of file config.cc.

497{
498 return relative(p, root_directory()).lexically_normal().string();
499}

◆ type()

virtual common::model::diagram_t clanguml::config::diagram::type ( ) const
pure virtual

Member Data Documentation

◆ name

std::string clanguml::config::diagram::name

Definition at line 758 of file config.h.

◆ title

option<std::string> clanguml::config::diagram::title {"title"}

Definition at line 760 of file config.h.


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