0.6.0
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 708 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) 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_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< 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 509 of file config.cc.

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

◆ glob_translation_units()

std::vector< std::string > clanguml::config::diagram::glob_translation_units ( const std::vector< std::string > &  compilation_database_files) const

Filter translation units based on glob patterns.

Returns
List of translation unit paths

Definition at line 355 of file config.cc.

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

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

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

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

488{
489 if (!maybe_module)
490 return {};
491
492 auto module_path = common::model::path(
493 maybe_module.value(), common::model::path_type::kModule)
494 .tokens();
495
497 auto using_module_path = common::model::path(
499 .tokens();
500
501 if (util::starts_with(module_path, using_module_path)) {
502 util::remove_prefix(module_path, using_module_path);
503 }
504 }
505
506 return module_path;
507}

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

482{
483 return relative(p, root_directory()).lexically_normal().string();
484}

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

◆ title

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

Definition at line 753 of file config.h.


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