0.5.4
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 636 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::filesystem::path root_directory () const
 Returns absolute path of the relative_to 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.
 
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< std::vector< common::string_or_regex > > glob {"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< 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< 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}
 

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

395{
396 const auto relative_name = using_namespace().relative(full_name);
397
398 for (const auto &[hint_target, hints] : layout()) {
399 for (const auto &hint : hints) {
400 if (hint.hint == hint_t::together) {
401 const auto &together_others =
402 std::get<std::vector<std::string>>(hint.entity);
403
404 if ((full_name == hint_target) ||
405 util::contains(together_others, full_name))
406 return hint_target;
407
408 if ((relative_name == hint_target) ||
409 util::contains(together_others, relative_name))
410 return hint_target;
411 }
412 }
413 }
414
415 return std::nullopt;
416}

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

306{
307 // If glob is not defined use all translation units from the
308 // compilation database
309 if (!glob.has_value) {
310 return compilation_database_files;
311 }
312
313 // Otherwise, get all translation units matching the glob from diagram
314 // configuration
315 std::vector<std::string> result{};
316
317 LOG_DBG("Looking for translation units in {}", root_directory().string());
318
319 for (const auto &g : glob()) {
320 if (g.is_regex()) {
321 LOG_DBG("Searching glob regex {}", g.to_string());
322
323 std::regex regex_pattern(
324 g.to_string(), std::regex_constants::optimize);
325
326 std::copy_if(compilation_database_files.begin(),
327 compilation_database_files.end(), std::back_inserter(result),
328 [&regex_pattern](const auto &tu) {
329 std::smatch m;
330 return std::regex_search(tu, m, regex_pattern);
331 });
332 }
333 else {
334 std::filesystem::path absolute_glob_path{g.to_string()};
335
336#ifdef _MSC_VER
337 if (!absolute_glob_path.has_root_name())
338#else
339 if (!absolute_glob_path.is_absolute())
340#endif
341 absolute_glob_path = root_directory() / absolute_glob_path;
342
343 LOG_DBG("Searching glob path {}", absolute_glob_path.string());
344
345 auto matches = glob::glob(absolute_glob_path.string(), true, false);
346
347 for (const auto &match : matches) {
348 const auto path =
349 std::filesystem::canonical(root_directory() / match);
350
351 result.emplace_back(path.string());
352 }
353 }
354 }
355
356 return result;
357}

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

419{
420 if (type_aliases().count("std::basic_string<char>") == 0U) {
421 type_aliases().insert({"std::basic_string<char>", "std::string"});
422 }
423 if (type_aliases().count("std::basic_string<char,std::char_traits<"
424 "char>,std::allocator<char>>") == 0U) {
425 type_aliases().insert({"std::basic_string<char,std::char_traits<"
426 "char>,std::allocator<char>>",
427 "std::string"});
428 }
429 if (type_aliases().count("std::basic_string<wchar_t>") == 0U) {
430 type_aliases().insert({"std::basic_string<wchar_t>", "std::wstring"});
431 }
432 if (type_aliases().count("std::basic_string<char16_t>") == 0U) {
433 type_aliases().insert(
434 {"std::basic_string<char16_t>", "std::u16string"});
435 }
436 if (type_aliases().count("std::basic_string<char32_t>") == 0U) {
437 type_aliases().insert(
438 {"std::basic_string<char32_t>", "std::u32string"});
439 }
440 if (type_aliases().count("std::integral_constant<bool,true>") == 0U) {
441 type_aliases().insert(
442 {"std::integral_constant<bool,true>", "std::true_type"});
443 }
444 if (type_aliases().count("std::integral_constant<bool,false>") == 0U) {
445 type_aliases().insert(
446 {"std::integral_constant<bool,false>", "std::false_type"});
447 }
448#if LLVM_VERSION_MAJOR >= 16
449 if (type_aliases().count("std::basic_string") == 0U) {
450 type_aliases().insert({"std::basic_string", "std::string"});
451 }
452#endif
453}

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

372{
373 if (!maybe_module)
374 return {};
375
376 auto module_path = common::model::path(
377 maybe_module.value(), common::model::path_type::kModule)
378 .tokens();
379
381 auto using_module_path = common::model::path(
383 .tokens();
384
385 if (util::starts_with(module_path, using_module_path)) {
386 util::remove_prefix(module_path, using_module_path);
387 }
388 }
389
390 return module_path;
391}

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

366{
367 return relative(p, root_directory()).lexically_normal().string();
368}

◆ root_directory()

std::filesystem::path clanguml::config::diagram::root_directory ( ) const

Returns absolute path of the relative_to option.

Returns
Absolute path of relative_to

Definition at line 359 of file config.cc.

360{
361 return weakly_canonical(absolute(base_directory() / relative_to()));
362}

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

◆ title

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

Definition at line 688 of file config.h.


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