0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
clanguml::config Namespace Reference

Configuration file related classes. More...

Detailed Description

Configuration file related classes.

Classes

struct  class_diagram
 Class diagram configuration. More...
 
struct  config
 Represents entire configuration file. More...
 
struct  context_config
 
struct  diagram
 Common diagram configuration type. More...
 
struct  diagram_template
 Definition of diagram template. More...
 
struct  filter
 
struct  generate_links_config
 
struct  git_config
 
struct  include_diagram
 Include diagram configuration. More...
 
struct  inheritable_diagram_options
 Represents subset of inheritable configuration options. More...
 
struct  layout_hint
 
struct  mermaid
 MermaidJS diagram config section. More...
 
struct  option
 Generic configuration option type. More...
 
struct  option_with_alt_names_tag
 
struct  package_diagram
 Package diagram configuration. More...
 
struct  plantuml
 PlantUML diagram config section. More...
 
struct  plantuml_keyword_mapping_t
 
struct  relationship_hint_t
 
struct  sequence_diagram
 Sequence diagram configuration. More...
 
struct  source_location
 
struct  type_aliases_longer_first_comparator
 

Typedefs

using layout_hints = std::map< std::string, std::vector< layout_hint > >
 
using relationship_hints_t = std::map< std::string, relationship_hint_t >
 
using type_aliases_t = std::map< std::string, std::string >
 
using type_aliases_longer_first_t = std::map< std::string, std::string, type_aliases_longer_first_comparator >
 
using config_ptr = std::unique_ptr< config >
 

Enumerations

enum class  method_arguments { full , abbreviated , none }
 
enum class  method_type {
  constructor , destructor , assignment , operator_ ,
  defaulted , deleted , static_
}
 
enum class  callee_type {
  constructor , assignment , operator_ , defaulted ,
  static_ , method , function , function_template ,
  lambda , cuda_kernel , cuda_device
}
 
enum class  package_type_t { kNamespace , kDirectory , kModule }
 
enum class  member_order_t { lexical , as_is }
 
enum class  comment_parser_t { plain , clang }
 
enum class  filter_mode_t { basic , advanced }
 
enum class  context_direction_t { inward , outward , any }
 
enum class  hint_t {
  up , down , left , right ,
  together , row , column
}
 
enum class  location_t { marker , fileline , function }
 
enum class  option_inherit_mode { kOverride , kAppend }
 

Functions

std::string to_string (const hint_t t)
 
std::string to_string (const method_arguments ma)
 
std::string to_string (method_type mt)
 
std::string to_string (callee_type mt)
 
std::string to_string (const comment_parser_t cp)
 
std::string to_string (location_t cp)
 
std::string to_string (package_type_t pt)
 
std::string to_string (member_order_t mo)
 
std::string to_string (context_direction_t cd)
 
std::string to_string (filter_mode_t fm)
 
template<>
void append_value< plantuml > (plantuml &l, const plantuml &r)
 
config load (const std::string &config_file, bool inherit=true, std::optional< bool > paths_relative_to_pwd={}, std::optional< bool > no_metadata={}, bool validate=true)
 Load and parse .clang-uml configuration file.
 
YAML::Emitter & operator<< (YAML::Emitter &out, const config &c)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const inheritable_diagram_options &c)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const filter &f)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const plantuml &p)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const method_arguments &ma)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const generate_links_config &glc)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const git_config &gc)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const relationship_hint_t &rh)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const comment_parser_t &cp)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const hint_t &h)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const class_diagram &c)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const sequence_diagram &c)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const include_diagram &c)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const package_diagram &c)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const layout_hint &c)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const source_location &sc)
 
template<typename T >
YAML::Emitter & operator<< (YAML::Emitter &out, const option< T > &o)
 
const std::string & get_predefined_diagram_templates ()
 Return YAML with predefined diagram templates.
 
template<typename T >
void append_value (T &l, const T &r)
 
template<typename T >
void append_value (std::vector< T > &l, const std::vector< T > &r)
 
template<typename K , typename V >
void append_value (std::map< K, V > &l, const std::map< K, V > &r)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const method_type &m)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const callee_type &m)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const member_order_t &r)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const package_type_t &r)
 
YAML::Emitter & operator<< (YAML::Emitter &out, const context_config &c)
 

Variables

const std::string schema_str
 

Typedef Documentation

◆ config_ptr

using clanguml::config::config_ptr = typedef std::unique_ptr<config>

Definition at line 790 of file config.h.

◆ layout_hints

using clanguml::config::layout_hints = typedef std::map<std::string, std::vector<layout_hint> >

Definition at line 455 of file config.h.

◆ relationship_hints_t

using clanguml::config::relationship_hints_t = typedef std::map<std::string, relationship_hint_t>

Definition at line 500 of file config.h.

◆ type_aliases_longer_first_t

using clanguml::config::type_aliases_longer_first_t = typedef std::map<std::string, std::string, type_aliases_longer_first_comparator>

Definition at line 513 of file config.h.

◆ type_aliases_t

using clanguml::config::type_aliases_t = typedef std::map<std::string, std::string>

Definition at line 502 of file config.h.

Enumeration Type Documentation

◆ callee_type

enum class clanguml::config::callee_type
strong

Types of call expressions, which can be used in sequence diagram filters

Enumerator
constructor 
assignment 
operator_ 
defaulted 
static_ 
method 
function 
function_template 
lambda 
cuda_kernel 
cuda_device 

Definition at line 72 of file config.h.

◆ comment_parser_t

Which comment parser should be used

Enumerator
plain 

Basic string parser

clang 

Clang's internal comment parser with structured output

Definition at line 107 of file config.h.

107 {
108 plain, /*!< Basic string parser */
109 clang /*!< Clang's internal comment parser with structured output */
110};

◆ context_direction_t

Enumerator
inward 
outward 
any 

Definition at line 169 of file config.h.

169{ inward, outward, any };

◆ filter_mode_t

Enumerator
basic 

Default filter structure without logical operators

advanced 

Advanced filter config with logical operators

Definition at line 119 of file config.h.

119 {
120 basic, /*!< Default filter structure without logical operators */
121 advanced /*!< Advanced filter config with logical operators */
122};

◆ hint_t

enum class clanguml::config::hint_t
strong
Enumerator
up 
down 
left 
right 
together 
row 
column 

Definition at line 446 of file config.h.

◆ location_t

enum class clanguml::config::location_t
strong
Enumerator
marker 
fileline 
function 

Definition at line 516 of file config.h.

◆ member_order_t

How class methods and members should be ordered in diagrams

Enumerator
lexical 
as_is 

Lexical order based on entire method or member signature without type

As written in source code

Definition at line 98 of file config.h.

98 {
99 lexical, /*! Lexical order based on entire method or member signature
100 without type */
101 as_is /*! As written in source code */
102};

◆ method_arguments

Select how the method arguments should be rendered

Enumerator
full 
abbreviated 

Full

none 

Abrreviate, string between '(' and ')' is cropped

Empty string between '(' and ')'

Definition at line 50 of file config.h.

50 {
51 full, /*! Full */
52 abbreviated, /*! Abrreviate, string between '(' and ')' is cropped */
53 none /*! Empty string between '(' and ')' */
54};

◆ method_type

enum class clanguml::config::method_type
strong

Types of methods, which can be used in diagram filters

Enumerator
constructor 
destructor 
assignment 
operator_ 
defaulted 
deleted 
static_ 

Definition at line 59 of file config.h.

59 {
65 deleted,
67};

◆ option_inherit_mode

Possible option inheritance methods from top level to diagram level.

Enumerator
kOverride 

Override entire options

kAppend 

Append to list options

Definition at line 45 of file option.h.

45 {
46 kOverride, /*!< Override entire options */
47 kAppend /*!< Append to list options */
48};

◆ package_type_t

How packages in diagrams should be generated

Enumerator
kNamespace 

From namespaces

kDirectory 

From directories

kModule 

From modules

Definition at line 89 of file config.h.

89 {
90 kNamespace, /*!< From namespaces */
91 kDirectory, /*!< From directories */
92 kModule /*!< From modules */
93};

Function Documentation

◆ append_value() [1/3]

template<typename K , typename V >
void clanguml::config::append_value ( std::map< K, V > &  l,
const std::map< K, V > &  r 
)

Definition at line 37 of file option.h.

38{
39 l.insert(r.begin(), r.end());
40}

◆ append_value() [2/3]

template<typename T >
void clanguml::config::append_value ( std::vector< T > &  l,
const std::vector< T > &  r 
)

Definition at line 31 of file option.h.

32{
33 l.insert(std::end(l), r.begin(), r.end());
34}

◆ append_value() [3/3]

template<typename T >
void clanguml::config::append_value ( T &  l,
const T &  r 
)

Definition at line 28 of file option.h.

28{ l = r; }

◆ append_value< plantuml >()

template<>
void clanguml::config::append_value< plantuml > ( plantuml l,
const plantuml r 
)

Definition at line 503 of file config.cc.

504{
505 l.append(r);
506}

◆ get_predefined_diagram_templates()

const std::string & clanguml::config::get_predefined_diagram_templates ( )

Return YAML with predefined diagram templates.

Returns
YAML definition of predefined diagram templates

Definition at line 24 of file diagram_templates.cc.

25{
26 static const std::string predefined_diagram_templates =
27 R"(# Predefined diagram templates
28parents_hierarchy_tmpl:
29 description: Generate class parents inheritance diagram
30 type: class

◆ load()

config clanguml::config::load ( const std::string &  config_file,
bool  inherit = true,
std::optional< bool >  paths_relative_to_pwd = {},
std::optional< bool >  no_metadata = {},
bool  validate = true 
)

Load and parse .clang-uml configuration file.

This function takes the path to the configuration file and some options, parses the YAML file and creates a

See also
clanguml::config::config instance.

Parameters
config_filePath to the configuration file
inheritIf true, common options will be propagated to diagram configs
paths_relative_to_pwdWhether the paths in the configuration file should be relative to the parent directory of the configuration file or to the current directory ($PWD)
no_metadataWhether the diagram should skip metadata at the end
validateIf true, perform schema validation
Returns
Configuration instance

Definition at line 989 of file yaml_decoders.cc.

992{
993 try {
994 auto schema = YAML::Load(clanguml::config::schema_str);
995 auto schema_validator = miroir::Validator<YAML::Node>(schema);
996
997 YAML::Node doc;
998 std::filesystem::path config_file_path{};
999
1000 if (config_file == "-") {
1001 std::istreambuf_iterator<char> stdin_stream_begin{std::cin};
1002 std::istreambuf_iterator<char> stdin_stream_end{};
1003 std::string stdin_stream_str{stdin_stream_begin, stdin_stream_end};
1004
1005 doc = YAML::Load(stdin_stream_str);
1006 }
1007 else {
1008 doc = YAML::LoadFile(config_file);
1009 }
1010
1011 // Store the parent path of the config_file to properly resolve
1012 // relative paths in config file
1013 if (has_key(doc, "__parent_path"))
1014 doc.remove("__parent_path");
1015 if (config_file == "-") {
1016 config_file_path = std::filesystem::current_path();
1017 doc.force_insert("__parent_path", config_file_path.string());
1018 }
1019 else {
1020 config_file_path =
1021 canonical(absolute(std::filesystem::path{config_file}));
1022 doc.force_insert(
1023 "__parent_path", config_file_path.parent_path().string());
1024 }
1025
1026 LOG_DBG("Effective config file path is {}", config_file_path.string());
1027
1028 //
1029 // If no relative_to path is specified in the config, make all paths
1030 // resolvable against the parent directory of the .clang-uml config
1031 // file, or against the $PWD if it was specified so in the command
1032 // line
1033 //
1034 if (!doc["relative_to"]) {
1035 bool paths_relative_to_config_file = true;
1036
1037 if (doc["paths_relative_to_config_file"] &&
1038 !doc["paths_relative_to_config_file"].as<bool>())
1039 paths_relative_to_config_file = false;
1040
1041 if (paths_relative_to_pwd && *paths_relative_to_pwd)
1042 paths_relative_to_config_file = false;
1043
1044 if (paths_relative_to_config_file)
1045 doc["relative_to"] = config_file_path.parent_path().string();
1046 else
1047 doc["relative_to"] = std::filesystem::current_path().string();
1048 }
1049
1050 if (no_metadata.has_value()) {
1051 doc["generate_metadata"] = !no_metadata.value();
1052 }
1053
1054 //
1055 // Resolve common path-like config options relative to `relative_to`
1056 //
1057 if (!doc["output_directory"]) {
1058 doc["output_directory"] = ".";
1059 }
1060 resolve_option_path(doc, "output_directory");
1061
1062 if (!doc["compilation_database_dir"]) {
1063 doc["compilation_database_dir"] = ".";
1064 }
1065 resolve_option_path(doc, "compilation_database_dir");
1066
1067 // If the current directory is also a git repository,
1068 // load some config values, which can be included in the
1069 // generated diagrams
1070 if (util::is_git_repository() && !doc["git"]) {
1071 YAML::Node git_config{YAML::NodeType::Map};
1072 git_config["branch"] = util::get_git_branch();
1073 git_config["revision"] = util::get_git_revision();
1074 git_config["commit"] = util::get_git_commit();
1075 git_config["toplevel"] = util::get_git_toplevel_dir();
1076
1077 doc["git"] = git_config;
1078 }
1079
1080 // Resolve diagram includes
1081 auto diagrams = doc["diagrams"];
1082
1083 assert(diagrams.Type() == YAML::NodeType::Map);
1084
1085 for (auto d : diagrams) {
1086 auto name = d.first.as<std::string>();
1087 std::shared_ptr<clanguml::config::diagram> diagram_config{};
1088 auto parent_path = doc["__parent_path"].as<std::string>();
1089
1090 if (has_key(d.second, "include!")) {
1091 auto include_path = std::filesystem::path{parent_path};
1092 include_path /= d.second["include!"].as<std::string>();
1093
1094 YAML::Node included_node =
1095 YAML::LoadFile(include_path.string());
1096
1097 diagrams[name] = included_node;
1098 }
1099 }
1100
1101 if (validate) {
1102 auto schema_errors = schema_validator.validate(doc);
1103
1104 if (!schema_errors.empty()) {
1105 // print validation errors
1106 for (const auto &err : schema_errors) {
1107 LOG_ERROR("Schema error: {}", err.description());
1108 }
1109
1110 throw YAML::Exception({}, "Invalid configuration schema");
1111 }
1112 }
1113
1114 auto d = doc.as<config>();
1115
1116 if (inherit)
1117 d.inherit();
1118
1119 d.initialize_diagram_templates();
1120
1121 return d;
1122 }
1123 catch (YAML::BadFile &e) {
1124 throw std::runtime_error(fmt::format(
1125 "Could not open config file {}: {}", config_file, e.what()));
1126 }
1127 catch (YAML::Exception &e) {
1128 throw std::runtime_error(fmt::format(
1129 "Cannot parse YAML file {}: {}", config_file, e.what()));
1130 }
1131}

◆ operator<<() [1/5]

YAML::Emitter & clanguml::config::operator<< ( YAML::Emitter &  out,
const callee_type m 
)

Definition at line 95 of file yaml_emitters.cc.

96{
97 out << to_string(m);
98 return out;
99}

◆ operator<<() [2/5]

YAML::Emitter & clanguml::config::operator<< ( YAML::Emitter &  out,
const context_config c 
)

Definition at line 113 of file yaml_emitters.cc.

114{
115 out << YAML::BeginMap;
116 out << YAML::Key << "match";
117 out << YAML::BeginMap;
118 out << YAML::Key << "radius" << YAML::Value << c.radius;
119 out << YAML::Key << "pattern" << YAML::Value << c.pattern;
120 out << YAML::EndMap;
121 out << YAML::EndMap;
122
123 return out;
124}

◆ operator<<() [3/5]

YAML::Emitter & clanguml::config::operator<< ( YAML::Emitter &  out,
const member_order_t r 
)

Definition at line 101 of file yaml_emitters.cc.

102{
103 out << to_string(r);
104 return out;
105}

◆ operator<<() [4/5]

YAML::Emitter & clanguml::config::operator<< ( YAML::Emitter &  out,
const method_type m 
)

Definition at line 89 of file yaml_emitters.cc.

90{
91 out << to_string(m);
92 return out;
93}

◆ operator<<() [5/5]

YAML::Emitter & clanguml::config::operator<< ( YAML::Emitter &  out,
const package_type_t r 
)

Definition at line 107 of file yaml_emitters.cc.

108{
109 out << to_string(r);
110 return out;
111}

◆ to_string() [1/10]

std::string clanguml::config::to_string ( callee_type  mt)

Definition at line 88 of file config.cc.

89{
90 switch (mt) {
91 case callee_type::constructor:
92 return "constructor";
93 case callee_type::assignment:
94 return "assignment";
95 case callee_type::operator_:
96 return "operator";
97 case callee_type::defaulted:
98 return "defaulted";
99 case callee_type::static_:
100 return "static";
101 case callee_type::method:
102 return "method";
103 case callee_type::function:
104 return "function";
105 case callee_type::function_template:
106 return "function_template";
107 case callee_type::lambda:
108 return "lambda";
109 case callee_type::cuda_kernel:
110 return "cuda_kernel";
111 case callee_type::cuda_device:
112 return "cuda_device";
113 }
114
115 assert(false);
116 return "";
117}

◆ to_string() [2/10]

std::string clanguml::config::to_string ( const comment_parser_t  cp)

Definition at line 119 of file config.cc.

120{
121 switch (cp) {
122 case comment_parser_t::clang:
123 return "clang";
124 case comment_parser_t::plain:
125 return "plain";
126 default:
127 assert(false);
128 return "";
129 }
130}

◆ to_string() [3/10]

std::string clanguml::config::to_string ( const hint_t  t)

Definition at line 27 of file config.cc.

28{
29 switch (t) {
30 case hint_t::up:
31 return "up";
32 case hint_t::down:
33 return "down";
34 case hint_t::left:
35 return "left";
36 case hint_t::right:
37 return "right";
38 case hint_t::together:
39 return "together";
40 case hint_t::row:
41 return "row";
42 case hint_t::column:
43 return "column";
44 default:
45 assert(false);
46 return "";
47 }
48}

◆ to_string() [4/10]

std::string clanguml::config::to_string ( const method_arguments  ma)

Definition at line 50 of file config.cc.

51{
52 switch (ma) {
53 case method_arguments::full:
54 return "full";
55 case method_arguments::abbreviated:
56 return "abbreviated";
57 case method_arguments::none:
58 return "none";
59 default:
60 assert(false);
61 return "";
62 }
63}

◆ to_string() [5/10]

std::string clanguml::config::to_string ( context_direction_t  cd)

Definition at line 174 of file config.cc.

175{
176 switch (cd) {
177 case context_direction_t::inward:
178 return "inward";
179 case context_direction_t::outward:
180 return "outward";
181 case context_direction_t::any:
182 return "any";
183 default:
184 assert(false);
185 return "";
186 }
187}

◆ to_string() [6/10]

std::string clanguml::config::to_string ( filter_mode_t  fm)

Definition at line 189 of file config.cc.

190{
191 switch (fm) {
192 case filter_mode_t::basic:
193 return "basic";
194 case filter_mode_t::advanced:
195 return "advanced";
196 default:
197 assert(false);
198 return "";
199 }
200}

◆ to_string() [7/10]

std::string clanguml::config::to_string ( location_t  cp)

Definition at line 132 of file config.cc.

133{
134 switch (cp) {
135 case location_t::fileline:
136 return "fileline";
137 case location_t::function:
138 return "function";
139 case location_t::marker:
140 return "marker";
141 default:
142 assert(false);
143 return "";
144 }
145}

◆ to_string() [8/10]

std::string clanguml::config::to_string ( member_order_t  mo)

Definition at line 162 of file config.cc.

163{
164 switch (mo) {
165 case member_order_t::lexical:
166 return "lexical";
167 case member_order_t::as_is:
168 return "as_is";
169 default:
170 assert(false);
171 return "";
172 }
173}

◆ to_string() [9/10]

std::string clanguml::config::to_string ( method_type  mt)

Definition at line 65 of file config.cc.

66{
67 switch (mt) {
68 case method_type::constructor:
69 return "constructor";
70 case method_type::destructor:
71 return "destructor";
72 case method_type::assignment:
73 return "assignment";
74 case method_type::operator_:
75 return "operator";
76 case method_type::defaulted:
77 return "defaulted";
78 case method_type::deleted:
79 return "deleted";
80 case method_type::static_:
81 return "static";
82 }
83
84 assert(false);
85 return "";
86}

◆ to_string() [10/10]

std::string clanguml::config::to_string ( package_type_t  pt)

Definition at line 147 of file config.cc.

148{
149 switch (pt) {
150 case package_type_t::kNamespace:
151 return "namespace";
152 case package_type_t::kDirectory:
153 return "directory";
154 case package_type_t::kModule:
155 return "module";
156 default:
157 assert(false);
158 return "";
159 }
160}

Variable Documentation

◆ schema_str

const std::string clanguml::config::schema_str

Definition at line 24 of file schema.h.