0.6.1
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 712 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_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 512 of file config.cc.

514{
515 const auto relative_name = using_namespace().relative(full_name);
516
517 for (const auto &[hint_target, hints] : layout()) {
518 for (const auto &hint : hints) {
519 if (hint.hint == hint_t::together) {
520 const auto &together_others =
521 std::get<std::vector<std::string>>(hint.entity);
522
523 if ((full_name == hint_target) ||
524 util::contains(together_others, full_name))
525 return hint_target;
526
527 if ((relative_name == hint_target) ||
528 util::contains(together_others, relative_name))
529 return hint_target;
530 }
531 }
532 }
533
534 return std::nullopt;
535}

◆ 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 358 of file config.cc.

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

◆ 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 537 of file config.cc.

538{
539 if (type_aliases().count("std::basic_string<char>") == 0U) {
540 type_aliases().insert({"std::basic_string<char>", "std::string"});
541 }
542 if (type_aliases().count("std::basic_string<char,std::char_traits<"
543 "char>,std::allocator<char>>") == 0U) {
544 type_aliases().insert({"std::basic_string<char,std::char_traits<"
545 "char>,std::allocator<char>>",
546 "std::string"});
547 }
548 if (type_aliases().count("std::basic_string<wchar_t>") == 0U) {
549 type_aliases().insert({"std::basic_string<wchar_t>", "std::wstring"});
550 }
551 if (type_aliases().count("std::basic_string<char16_t>") == 0U) {
552 type_aliases().insert(
553 {"std::basic_string<char16_t>", "std::u16string"});
554 }
555 if (type_aliases().count("std::basic_string<char32_t>") == 0U) {
556 type_aliases().insert(
557 {"std::basic_string<char32_t>", "std::u32string"});
558 }
559 if (type_aliases().count("std::integral_constant<bool,true>") == 0U) {
560 type_aliases().insert(
561 {"std::integral_constant<bool,true>", "std::true_type"});
562 }
563 if (type_aliases().count("std::integral_constant<bool,false>") == 0U) {
564 type_aliases().insert(
565 {"std::integral_constant<bool,false>", "std::false_type"});
566 }
567#if LLVM_VERSION_MAJOR >= 16
568 if (type_aliases().count("std::basic_string") == 0U) {
569 type_aliases().insert({"std::basic_string", "std::string"});
570 }
571#endif
572}

◆ 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 489 of file config.cc.

491{
492 if (!maybe_module)
493 return {};
494
495 auto module_path = common::model::path(
496 maybe_module.value(), common::model::path_type::kModule)
497 .tokens();
498
500 auto using_module_path = common::model::path(
502 .tokens();
503
504 if (util::starts_with(module_path, using_module_path)) {
505 util::remove_prefix(module_path, using_module_path);
506 }
507 }
508
509 return module_path;
510}

◆ 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 483 of file config.cc.

485{
486 return relative(p, root_directory()).lexically_normal().string();
487}

◆ 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 756 of file config.h.

◆ title

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

Definition at line 758 of file config.h.


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