0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Member Functions | List of all members
clanguml::class_diagram::generators::mermaid::generator Class Reference

Class diagram MermaidJS generator. More...

Detailed Description

Class diagram MermaidJS generator.

Definition at line 66 of file class_diagram_generator.h.

#include <class_diagram_generator.h>

Public Member Functions

 generator (diagram_config &config, diagram_model &model)
 
void generate_diagram (std::ostream &ostr) const override
 Main generator method.
 
void generate_diagram_type (std::ostream &ostr) const override
 Generate the diagram type.
 
void generate_alias (const common::model::element &e, std::ostream &ostr) const
 Generate MermaidJS alias for a class element.
 
void generate (const class_ &c, std::ostream &ostr) const
 Render class element to MermaidJS.
 
void generate_methods (const std::vector< class_method > &methods, std::ostream &ostr) const
 Render class methods to MermaidJS.
 
void generate_methods (const std::vector< objc_method > &methods, std::ostream &ostr) const
 
void start_method_group (std::ostream &ostr) const
 
void generate_method (const class_method &m, std::ostream &ostr) const
 Render class method to MermaidJS.
 
void generate_method (const objc_method &m, std::ostream &ostr) const
 
void generate_member (const class_member &m, std::ostream &ostr) const
 Render class member to MermaidJS.
 
void generate_member (const objc_member &m, std::ostream &ostr) const
 
void generate_relationships (const class_ &c, std::ostream &ostr) const
 Render all relationships originating from class element.
 
void generate_relationship (const relationship &r, std::set< std::string > &rendered_relations) const
 Render a specific relationship to MermaidJS.
 
void generate (const enum_ &e, std::ostream &ostr) const
 Render enum element to MermaidJS.
 
void generate_relationships (const enum_ &c, std::ostream &ostr) const
 Render all relationships originating from enum element.
 
void generate (const concept_ &c, std::ostream &ostr) const
 Render concept element to MermaidJS.
 
void generate_relationships (const concept_ &c, std::ostream &ostr) const
 Render all relationships originating from ObjC class element.
 
void generate (const objc_interface &c, std::ostream &ostr) const
 
void generate_relationships (const objc_interface &c, std::ostream &ostr) const
 Render all relationships originating from ObjC class element.
 
void generate_member_notes (std::ostream &ostream, const class_element &member, const std::string &alias) const
 Generate any notes attached specifically to some class element.
 
void start_together_group (const std::string &group_name, std::ostream &ostr) const
 
void end_together_group (const std::string &group_name, std::ostream &ostr) const
 
void start_package (const package &p, std::ostream &ostr) const
 
void end_package (const package &p, std::ostream &ostr) const
 
- Public Member Functions inherited from clanguml::common::generators::mermaid::generator< ConfigType, DiagramType >
 generator (ConfigType &config, DiagramType &model)
 Constructor.
 
 ~generator () override=default
 
void generate (std::ostream &ostr) const override
 Generate diagram.
 
virtual void generate_diagram (std::ostream &ostr) const =0
 Generate diagram specific part.
 
void generate_mermaid_directives (std::ostream &ostr, const std::vector< std::string > &directives) const
 Generate MermaidJS directives from config file.
 
virtual void generate_diagram_type (std::ostream &ostr) const =0
 Generate the diagram type.
 
virtual void generate_notes (std::ostream &ostr, const model::diagram_element &element) const
 Generate diagram notes.
 
void generate_metadata (std::ostream &ostr) const
 Generate comment with diagram metadata.
 
void generate_title (std::ostream &ostr) const
 Generate diagram title.
 
template<typename E >
void generate_link (std::ostream &ostr, const E &e) const
 Generate hyper link to element.
 
void print_debug (const common::model::source_location &e, std::ostream &ostr) const
 Print debug information in diagram comments.
 
- Public Member Functions inherited from clanguml::common::generators::generator< ConfigType, DiagramType >
 generator (ConfigType &config, DiagramType &model)
 Constructor.
 
virtual ~generator ()=default
 
virtual void generate (std::ostream &ostr) const =0
 Generate diagram.
 
const ConfigType & config () const
 Get reference to diagram config.
 
const DiagramType & model () const
 Get reference to diagram model.
 
std::optional< std::pair< std::string, std::string > > get_link_pattern (const common::model::source_location &sl) const
 
std::optional< std::pair< std::string, std::string > > get_tooltip_pattern (const common::model::source_location &sl) const
 
std::optional< std::string > render_link (const common::model::diagram_element &e) const
 
std::optional< std::string > render_link (const common::model::relationship &e) const
 
std::optional< std::string > render_tooltip (const common::model::diagram_element &e) const
 
std::optional< std::string > render_tooltip (const common::model::relationship &e) const
 
void init_context ()
 Initialize diagram Jinja context.
 
void update_context () const
 Update diagram Jinja context.
 
void init_env ()
 
const inja::json & context () const
 
inja::Environment & env () const
 
- Public Member Functions inherited from clanguml::class_diagram::generators::text_diagram_strategy< generator >
 text_diagram_strategy (generator &generator, bool generate_packages)
 
void generate (const package &p, std::ostream &ostr) const
 
void generate_top_level_elements (std::ostream &ostr) const
 
void generate_relationships (const package &p, std::ostream &ostr) const
 
void generate_relationships (std::ostream &ostr) const
 
void generate_groups (std::ostream &ostr) const
 
void sort_class_elements (std::vector< T > &elements) const
 
void generate_method_groups (const method_groups_t &methods, std::ostream &ostr) const
 
method_groups_t group_methods (const std::vector< model::class_method > &methods) const
 Group class methods based on method type.
 

Additional Inherited Members

- Public Types inherited from clanguml::class_diagram::generators::text_diagram_strategy< generator >
using method_groups_t = std::map< std::string, std::vector< model::class_method > >
 
- Protected Attributes inherited from clanguml::common::generators::mermaid::generator< ConfigType, DiagramType >
std::set< std::string > m_generated_aliases
 
- Protected Attributes inherited from clanguml::common::generators::generator< ConfigType, DiagramType >
inja::json m_context
 
inja::Environment m_env
 

Constructor & Destructor Documentation

◆ generator()

clanguml::class_diagram::generators::mermaid::generator::generator ( diagram_config config,
diagram_model model 
)

Definition at line 32 of file class_diagram_generator.cc.

33 : common_generator<diagram_config, diagram_model>{config, model}
34 , class_diagram::generators::text_diagram_strategy<generator>{*this, false}
35
36{
37}

Member Function Documentation

◆ end_package()

void clanguml::class_diagram::generators::mermaid::generator::end_package ( const package p,
std::ostream &  ostr 
) const

Definition at line 797 of file class_diagram_generator.cc.

797{ }

◆ end_together_group()

void clanguml::class_diagram::generators::mermaid::generator::end_together_group ( const std::string &  group_name,
std::ostream &  ostr 
) const

Definition at line 790 of file class_diagram_generator.cc.

792{
793}

◆ generate() [1/4]

void clanguml::class_diagram::generators::mermaid::generator::generate ( const class_ c,
std::ostream &  ostr 
) const

Render class element to MermaidJS.

Parameters
cClass element
ostrOutput stream

Definition at line 62 of file class_diagram_generator.cc.

63{
64 std::string class_type{"class"};
65
66 ostr << indent(1) << "class " << c.alias();
67
68 ostr << " {" << '\n';
69
70 if (c.is_union())
71 ostr << indent(2) << "<<union>>\n";
72 else if (c.is_abstract())
73 ostr << indent(2) << "<<abstract>>\n";
74
75 //
76 // Process methods
77 //
78 if (config().group_methods()) {
79 generate_method_groups(group_methods(c.methods()), ostr);
80 }
81 else {
82 generate_methods(c.methods(), ostr);
83 }
84
85 //
86 // Process relationships - here only generate the set of
87 // rendered_relationships we'll generate them in a seperate method
88 //
89 std::set<std::string> rendered_relations;
90
91 std::stringstream all_relations_str;
92 for (const auto &r : c.relationships()) {
93 try {
94 generate_relationship(r, rendered_relations);
95 }
96 catch (error::uml_alias_missing &e) {
97 LOG_DBG("Skipping {} relation from {} to {} due "
98 "to: {}",
99 to_string(r.type()), c.full_name(false), r.destination(),
100 e.what());
101 }
102 }
103
104 //
105 // Process members
106 //
107 std::vector<clanguml::class_diagram::model::class_member> members{
108 c.members()};
109
110 sort_class_elements(members);
111
112 for (const auto &m : members) {
113 if (!config().include_relations_also_as_members() &&
114 rendered_relations.find(m.name()) != rendered_relations.end())
115 continue;
116
117 generate_member(m, ostr);
118
119 ostr << '\n';
120 }
121
122 ostr << indent(1) << "}" << '\n';
123
124 if (config().generate_links) {
126 }
127
128 generate_notes(ostr, c);
129
130 for (const auto &member : c.members())
131 generate_member_notes(ostr, member, c.alias());
132
133 for (const auto &method : c.methods())
134 generate_member_notes(ostr, method, c.alias());
135}

◆ generate() [2/4]

void clanguml::class_diagram::generators::mermaid::generator::generate ( const concept_ c,
std::ostream &  ostr 
) const

Render concept element to MermaidJS.

Parameters
cConcept element
ostrOutput stream

Definition at line 312 of file class_diagram_generator.cc.

313{
314 ostr << indent(1) << "class" << " " << c.alias();
315
316 ostr << " {" << '\n';
317 ostr << indent(2) << "<<concept>>\n";
318
319 if (config().generate_concept_requirements() &&
320 (c.requires_parameters().size() + c.requires_statements().size() > 0)) {
321 std::vector<std::string> parameters;
322 parameters.reserve(c.requires_parameters().size());
323 for (const auto &p : c.requires_parameters()) {
324 parameters.emplace_back(
325 escape_name(p.to_string(config().using_namespace())));
326 }
327
328 ostr << indent(2)
329 << fmt::format("\"({})\"\n", fmt::join(parameters, ","));
330
331 for (const auto &req : c.requires_statements()) {
332 ostr << indent(2)
333 << fmt::format("\"{}\"\n", escape_name(req, false));
334 }
335 }
336
337 ostr << indent(1) << "}" << '\n';
338
339 if (config().generate_links) {
341 }
342}

◆ generate() [3/4]

void clanguml::class_diagram::generators::mermaid::generator::generate ( const enum_ e,
std::ostream &  ostr 
) const

Render enum element to MermaidJS.

Parameters
eEnum element
ostrOutput stream

Definition at line 603 of file class_diagram_generator.cc.

604{
605 ostr << indent(1) << "class " << e.alias();
606
607 ostr << " {" << '\n';
608
609 ostr << indent(2) << "<<enumeration>>\n";
610
611 for (const auto &enum_constant : e.constants()) {
612 ostr << indent(2) << enum_constant << '\n';
613 }
614
615 ostr << indent(1) << "}" << '\n';
616
617 if (config().generate_links) {
619 }
620
621 generate_notes(ostr, e);
622}

◆ generate() [4/4]

void clanguml::class_diagram::generators::mermaid::generator::generate ( const objc_interface c,
std::ostream &  ostr 
) const

Definition at line 624 of file class_diagram_generator.cc.

625{
626 std::string class_type{"class"};
627
628 ostr << indent(1) << "class " << c.alias();
629
630 ostr << " {" << '\n';
631
632 if (c.is_protocol())
633 ostr << indent(2) << "<< ObjC Protocol >>\n";
634 else if (c.is_protocol())
635 ostr << indent(2) << "<< ObjC Category >>\n";
636 else
637 ostr << indent(2) << "<< ObjC Interface >>\n";
638
639 //
640 // Process methods
641 //
642 generate_methods(c.methods(), ostr);
643
644 //
645 // Process relationships - here only generate the set of
646 // rendered_relationships we'll generate them in a seperate method
647 //
648 std::set<std::string> rendered_relations;
649
650 std::stringstream all_relations_str;
651 for (const auto &r : c.relationships()) {
652 try {
653 generate_relationship(r, rendered_relations);
654 }
655 catch (error::uml_alias_missing &e) {
656 LOG_DBG("Skipping {} relation from {} to {} due "
657 "to: {}",
658 to_string(r.type()), c.full_name(true), r.destination(),
659 e.what());
660 }
661 }
662
663 //
664 // Process members
665 //
666 std::vector<clanguml::class_diagram::model::objc_member> members{
667 c.members()};
668
669 sort_class_elements(members);
670
671 for (const auto &m : members) {
672 if (!config().include_relations_also_as_members() &&
673 rendered_relations.find(m.name()) != rendered_relations.end())
674 continue;
675
676 generate_member(m, ostr);
677
678 ostr << '\n';
679 }
680
681 ostr << indent(1) << "}" << '\n';
682
683 if (config().generate_links) {
685 }
686
687 generate_notes(ostr, c);
688
689 for (const auto &member : c.members())
690 generate_member_notes(ostr, member, c.alias());
691
692 for (const auto &method : c.methods())
693 generate_member_notes(ostr, method, c.alias());
694}

◆ generate_alias()

void clanguml::class_diagram::generators::mermaid::generator::generate_alias ( const common::model::element e,
std::ostream &  ostr 
) const

Generate MermaidJS alias for a class element.

Parameters
cClass element
ostrOutput stream

Definition at line 44 of file class_diagram_generator.cc.

46{
47 const auto full_name = display_name_adapter(c).full_name(true);
48
49 assert(!full_name.empty());
50
51 print_debug(c, ostr);
52
53 auto class_label = config().simplify_template_type(full_name);
54
55 ostr << indent(1) << "class " << c.alias() << "[\""
56 << escape_name(class_label) << "\"]\n";
57
58 // Register the added alias
59 m_generated_aliases.emplace(c.alias());
60}

◆ generate_diagram()

void clanguml::class_diagram::generators::mermaid::generator::generate_diagram ( std::ostream &  ostr) const
overridevirtual

Main generator method.

This method is called first and coordinates the entire diagram generation.

Parameters
ostrOutput stream.

Implements clanguml::common::generators::mermaid::generator< ConfigType, DiagramType >.

Definition at line 776 of file class_diagram_generator.cc.

777{
779
780 generate_groups(ostr);
781
783}

◆ generate_diagram_type()

void clanguml::class_diagram::generators::mermaid::generator::generate_diagram_type ( std::ostream &  ostr) const
overridevirtual

Generate the diagram type.

Parameters
ostrOutput stream

Implements clanguml::common::generators::mermaid::generator< ConfigType, DiagramType >.

Definition at line 39 of file class_diagram_generator.cc.

40{
41 ostr << "classDiagram\n";
42}

◆ generate_member() [1/2]

void clanguml::class_diagram::generators::mermaid::generator::generate_member ( const class_member m,
std::ostream &  ostr 
) const

Render class member to MermaidJS.

Parameters
mClass member
ostrOutput stream

Definition at line 284 of file class_diagram_generator.cc.

286{
287 namespace mermaid_common = clanguml::common::generators::mermaid;
288 const auto &uns = config().using_namespace();
289
290 print_debug(m, ostr);
291
292 ostr << indent(2) << mermaid_common::to_mermaid(m.access()) << m.name()
293 << " : "
294 << escape_name(uns.relative(config().simplify_template_type(
295 display_name_adapter(m).type())));
296}

◆ generate_member() [2/2]

void clanguml::class_diagram::generators::mermaid::generator::generate_member ( const objc_member m,
std::ostream &  ostr 
) const

Definition at line 298 of file class_diagram_generator.cc.

300{
301 namespace mermaid_common = clanguml::common::generators::mermaid;
302 const auto &uns = config().using_namespace();
303
304 print_debug(m, ostr);
305
306 ostr << indent(2) << mermaid_common::to_mermaid(m.access()) << m.name()
307 << " : "
308 << escape_name(uns.relative(config().simplify_template_type(
309 display_name_adapter(m).type())));
310}

◆ generate_member_notes()

void clanguml::class_diagram::generators::mermaid::generator::generate_member_notes ( std::ostream &  ostream,
const class_element member,
const std::string &  alias 
) const

Generate any notes attached specifically to some class element.

Parameters
ostreamOutput stream
memberClass element (member or method)
aliasMermaidJS class alias

Definition at line 344 of file class_diagram_generator.cc.

346{
347 for (const auto &decorator : member.decorators()) {
348 auto note = std::dynamic_pointer_cast<decorators::note>(decorator);
349 if (note && note->applies_to_diagram(config().name)) {
350 ostr << indent(1) << "note for " << alias << " \"" << note->text
351 << "\"" << '\n';
352 }
353 }
354}

◆ generate_method() [1/2]

void clanguml::class_diagram::generators::mermaid::generator::generate_method ( const class_method m,
std::ostream &  ostr 
) const

Render class method to MermaidJS.

Parameters
mClass method
ostrOutput stream

Definition at line 163 of file class_diagram_generator.cc.

165{
166 namespace mermaid_common = clanguml::common::generators::mermaid;
167 const auto &uns = config().using_namespace();
168
169 constexpr auto kAbbreviatedMethodArgumentsLength{15};
170
171 print_debug(m, ostr);
172
173 std::string type{uns.relative(
174 config().simplify_template_type(display_name_adapter(m).type()))};
175
176 ostr << indent(2) << mermaid_common::to_mermaid(m.access()) << m.name();
177
178 if (!m.template_params().empty()) {
179 m.render_template_params(ostr, config().using_namespace(), false);
180 }
181
182 ostr << "(";
183 if (config().generate_method_arguments() !=
185 std::vector<std::string> params;
186 std::transform(m.parameters().cbegin(), m.parameters().cend(),
187 std::back_inserter(params), [this](const auto &mp) {
188 return config().simplify_template_type(
189 mp.to_string(config().using_namespace()));
190 });
191 auto args_string = fmt::format("{}", fmt::join(params, ", "));
192 if (config().generate_method_arguments() ==
194 args_string = clanguml::util::abbreviate(
195 args_string, kAbbreviatedMethodArgumentsLength);
196 }
197 ostr << escape_name(args_string);
198 }
199 ostr << ")";
200
201 ostr << " : ";
202
203 std::vector<std::string> method_mods;
204 if (m.is_defaulted()) {
205 method_mods.emplace_back("default");
206 }
207 if (m.is_const()) {
208 method_mods.emplace_back("const");
209 }
210 if (m.is_constexpr()) {
211 method_mods.emplace_back("constexpr");
212 }
213 if (m.is_consteval()) {
214 method_mods.emplace_back("consteval");
215 }
216 if (m.is_coroutine()) {
217 method_mods.emplace_back("coroutine");
218 }
219
220 if (!method_mods.empty()) {
221 ostr << fmt::format("[{}] ", fmt::join(method_mods, ","));
222 }
223
224 ostr << escape_name(type);
225
226 if (m.is_pure_virtual())
227 ostr << "*";
228
229 if (m.is_static())
230 ostr << "$";
231}

◆ generate_method() [2/2]

void clanguml::class_diagram::generators::mermaid::generator::generate_method ( const objc_method m,
std::ostream &  ostr 
) const

Definition at line 233 of file class_diagram_generator.cc.

235{
236 namespace mermaid_common = clanguml::common::generators::mermaid;
237 const auto &uns = config().using_namespace();
238
239 constexpr auto kAbbreviatedMethodArgumentsLength{15};
240
241 print_debug(m, ostr);
242
243 std::string type{uns.relative(
244 config().simplify_template_type(display_name_adapter(m).type()))};
245
246 ostr << indent(2) << mermaid_common::to_mermaid(m.access()) << m.name();
247
248 ostr << "(";
249 if (config().generate_method_arguments() !=
251 std::vector<std::string> params;
252 std::transform(m.parameters().cbegin(), m.parameters().cend(),
253 std::back_inserter(params), [this](const auto &mp) {
254 return config().simplify_template_type(
255 mp.to_string(config().using_namespace()));
256 });
257 auto args_string = fmt::format("{}", fmt::join(params, ", "));
258 if (config().generate_method_arguments() ==
260 args_string = clanguml::util::abbreviate(
261 args_string, kAbbreviatedMethodArgumentsLength);
262 }
263 ostr << escape_name(args_string);
264 }
265 ostr << ")";
266
267 ostr << " : ";
268
269 std::vector<std::string> method_mods;
270 if (m.is_optional()) {
271 method_mods.emplace_back("default");
272 }
273
274 if (!method_mods.empty()) {
275 ostr << fmt::format("[{}] ", fmt::join(method_mods, ","));
276 }
277
278 ostr << escape_name(type);
279
280 if (m.is_static())
281 ostr << "$";
282}

◆ generate_methods() [1/2]

void clanguml::class_diagram::generators::mermaid::generator::generate_methods ( const std::vector< class_method > &  methods,
std::ostream &  ostr 
) const

Render class methods to MermaidJS.

Parameters
methodsList of class methods
ostrOutput stream

Definition at line 139 of file class_diagram_generator.cc.

141{
142 auto sorted_methods = methods;
143 sort_class_elements(sorted_methods);
144
145 for (const auto &m : sorted_methods) {
146 generate_method(m, ostr);
147 ostr << '\n';
148 }
149}

◆ generate_methods() [2/2]

void clanguml::class_diagram::generators::mermaid::generator::generate_methods ( const std::vector< objc_method > &  methods,
std::ostream &  ostr 
) const

Definition at line 151 of file class_diagram_generator.cc.

153{
154 auto sorted_methods = methods;
155 sort_class_elements(sorted_methods);
156
157 for (const auto &m : sorted_methods) {
158 generate_method(m, ostr);
159 ostr << '\n';
160 }
161}

◆ generate_relationship()

void clanguml::class_diagram::generators::mermaid::generator::generate_relationship ( const relationship r,
std::set< std::string > &  rendered_relations 
) const

Render a specific relationship to MermaidJS.

Parameters
rRelationship model
rendered_relationsSet of already rendered relationships, to ensure that there are no duplicate relationships

Definition at line 356 of file class_diagram_generator.cc.

358{
359 namespace mermaid_common = clanguml::common::generators::mermaid;
360
361 LOG_DBG("Processing relationship {}", to_string(r.type()));
362
363 std::string destination;
364
365 auto target_element = model().get(r.destination());
366 if (!target_element.has_value())
367 throw error::uml_alias_missing{fmt::format(
368 "Missing element in the model for ID: {}", r.destination())};
369
370 destination = target_element.value().full_name(false);
371
372 if (util::starts_with(destination, std::string{"::"}))
373 destination = destination.substr(2, destination.size());
374
375 std::string mmd_relation;
376 if (!r.multiplicity_source().empty())
377 mmd_relation += "\"" + r.multiplicity_source() + "\" ";
378
379 mmd_relation += mermaid_common::to_mermaid(r.type());
380
381 if (!r.multiplicity_destination().empty())
382 mmd_relation += " \"" + r.multiplicity_destination() + "\"";
383
384 if (!r.label().empty()) {
385 if (r.type() == relationship_t::kFriendship)
386 rendered_relations.emplace(fmt::format(
387 "{}[friend]", mermaid_common::to_mermaid(r.access())));
388 else
389 rendered_relations.emplace(r.label());
390 }
391}

◆ generate_relationships() [1/4]

void clanguml::class_diagram::generators::mermaid::generator::generate_relationships ( const class_ c,
std::ostream &  ostr 
) const

Render all relationships originating from class element.

Parameters
cClass element
ostrOutput stream

Definition at line 393 of file class_diagram_generator.cc.

395{
396 namespace mermaid_common = clanguml::common::generators::mermaid;
397
398 //
399 // Process relationships
400 //
401 std::set<std::string> rendered_relations;
402
403 std::stringstream all_relations_str;
404 std::set<std::string> unique_relations;
405
406 for (const auto &r : c.relationships()) {
407 LOG_DBG("== Processing relationship {}", to_string(r.type()));
408
409 std::stringstream relstr;
410 eid_t destination{};
411 try {
412 destination = r.destination();
413
414 std::string relation_str;
415
416 if (!r.multiplicity_source().empty())
417 relation_str += "\"" + r.multiplicity_source() + "\" ";
418
419 relation_str += mermaid_common::to_mermaid(r.type());
420
421 if (!r.multiplicity_destination().empty())
422 relation_str += " \"" + r.multiplicity_destination() + "\"";
423
424 std::string target_alias;
425 try {
426 target_alias = model().to_alias(destination);
427 }
428 catch (...) {
429 LOG_DBG("Failed to find alias to {}", destination);
430 continue;
431 }
432
433 if (m_generated_aliases.find(target_alias) ==
435 continue;
436
437 if (r.type() == relationship_t::kContainment) {
438 relstr << indent(1) << target_alias << " " << relation_str
439 << " " << c.alias();
440 }
441 else if (r.type() == relationship_t::kExtension) {
442 relstr << indent(1) << target_alias << " <|-- " << c.alias();
443 }
444 else {
445 relstr << indent(1) << c.alias() << " " << relation_str << " "
446 << target_alias;
447 }
448
449 relstr << " : ";
450
451 if (!r.label().empty()) {
452 auto lbl = r.label();
453 if (r.type() == relationship_t::kFriendship)
454 lbl = "[friend]";
455 relstr << mermaid_common::to_mermaid(r.access()) << lbl;
456 rendered_relations.emplace(r.label());
457 }
458
459 if (unique_relations.count(relstr.str()) == 0) {
460 unique_relations.emplace(relstr.str());
461
462 LOG_DBG("=== Adding relation {}", relstr.str());
463
464 all_relations_str << relstr.str() << '\n';
465 }
466 }
467 catch (error::uml_alias_missing &e) {
468 LOG_DBG("=== Skipping {} relation from {} to {} due "
469 "to: {}",
470 to_string(r.type()), c.full_name(true), destination, e.what());
471 }
472 }
473
474 ostr << all_relations_str.str();
475}

◆ generate_relationships() [2/4]

void clanguml::class_diagram::generators::mermaid::generator::generate_relationships ( const concept_ c,
std::ostream &  ostr 
) const

Render all relationships originating from ObjC class element.

Parameters
cConcept element
ostrOutput stream

Definition at line 477 of file class_diagram_generator.cc.

479{
480 namespace mermaid_common = clanguml::common::generators::mermaid;
481
482 //
483 // Process relationships
484 //
485 std::set<std::string> rendered_relations;
486
487 std::stringstream all_relations_str;
488 std::set<std::string> unique_relations;
489
490 for (const auto &r : c.relationships()) {
491 LOG_DBG("== Processing relationship {}", to_string(r.type()));
492
493 std::stringstream relstr;
494 eid_t destination{};
495 try {
496 destination = r.destination();
497
498 std::string mmd_relation;
499 if (!r.multiplicity_source().empty())
500 mmd_relation += "\"" + r.multiplicity_source() + "\" ";
501
502 mmd_relation += mermaid_common::to_mermaid(r.type());
503
504 if (!r.multiplicity_destination().empty())
505 mmd_relation += " \"" + r.multiplicity_destination() + "\"";
506
507 std::string target_alias;
508 try {
509 target_alias = model().to_alias(destination);
510 }
511 catch (...) {
512 LOG_DBG("Failed to find alias to {}", destination);
513 continue;
514 }
515
516 if (m_generated_aliases.find(target_alias) ==
518 continue;
519
520 if (r.type() == relationship_t::kContainment) {
521 relstr << indent(1) << target_alias << " " << mmd_relation
522 << " " << c.alias();
523 }
524 else {
525 relstr << indent(1) << c.alias() << " " << mmd_relation << " "
526 << target_alias;
527 }
528
529 relstr << " : ";
530
531 if (!r.label().empty()) {
532 auto lbl = r.label();
533 if (r.type() == relationship_t::kFriendship)
534 lbl = "[friend]";
535 relstr << mermaid_common::to_mermaid(r.access()) << lbl;
536 rendered_relations.emplace(r.label());
537 }
538
539 if (unique_relations.count(relstr.str()) == 0) {
540 unique_relations.emplace(relstr.str());
541
542 LOG_TRACE("=== Adding relation {}", relstr.str());
543
544 all_relations_str << relstr.str() << '\n';
545 }
546 }
547 catch (error::uml_alias_missing &e) {
548 LOG_DBG("=== Skipping {} relation from {} to {} due "
549 "to: {}",
550 to_string(r.type()), c.full_name(true), destination, e.what());
551 }
552 }
553
554 ostr << all_relations_str.str();
555}

◆ generate_relationships() [3/4]

void clanguml::class_diagram::generators::mermaid::generator::generate_relationships ( const enum_ c,
std::ostream &  ostr 
) const

Render all relationships originating from enum element.

Parameters
cEnum element
ostrOutput stream

Definition at line 557 of file class_diagram_generator.cc.

558{
559 for (const auto &r : e.relationships()) {
560 eid_t destination{};
561 std::stringstream relstr;
562 try {
563 destination = r.destination();
564
565 auto target_alias = model().to_alias(destination);
566
567 if (m_generated_aliases.find(target_alias) ==
569 continue;
570
571 if (r.type() == relationship_t::kContainment) {
572 relstr << indent(1) << target_alias << " "
574 r.type())
575 << " " << e.alias();
576 }
577 else {
578 relstr << indent(1) << e.alias() << " "
580 r.type())
581 << " " << target_alias;
582 }
583
584 auto lbl = r.label();
585 if (r.type() == relationship_t::kFriendship)
586 lbl = "[friend]";
587
588 relstr << " : " << r.label();
589
590 relstr << '\n';
591
592 ostr << relstr.str();
593 }
594 catch (error::uml_alias_missing &ex) {
595 LOG_DBG("Skipping {} relation from {} to {} due "
596 "to: {}",
598 e.full_name(true), destination, ex.what());
599 }
600 }
601}

◆ generate_relationships() [4/4]

void clanguml::class_diagram::generators::mermaid::generator::generate_relationships ( const objc_interface c,
std::ostream &  ostr 
) const

Render all relationships originating from ObjC class element.

Parameters
cConcept element
ostrOutput stream

Definition at line 696 of file class_diagram_generator.cc.

698{
699 namespace mermaid_common = clanguml::common::generators::mermaid;
700
701 //
702 // Process relationships
703 //
704 std::set<std::string> rendered_relations;
705
706 std::stringstream all_relations_str;
707 std::set<std::string> unique_relations;
708
709 for (const auto &r : c.relationships()) {
710 LOG_DBG("== Processing relationship {}", to_string(r.type()));
711
712 std::stringstream relstr;
713 eid_t destination{};
714 try {
715 destination = r.destination();
716
717 std::string relation_str;
718
719 if (!r.multiplicity_source().empty())
720 relation_str += "\"" + r.multiplicity_source() + "\" ";
721
722 relation_str += mermaid_common::to_mermaid(r.type());
723
724 if (!r.multiplicity_destination().empty())
725 relation_str += " \"" + r.multiplicity_destination() + "\"";
726
727 std::string target_alias;
728 try {
729 target_alias = model().to_alias(destination);
730 }
731 catch (...) {
732 LOG_DBG("Failed to find alias to {}", destination);
733 continue;
734 }
735
736 if (m_generated_aliases.find(target_alias) ==
738 continue;
739
740 if (r.type() == relationship_t::kExtension) {
741 relstr << indent(1) << target_alias << " <|-- " << c.alias();
742 }
743 else {
744 relstr << indent(1) << c.alias() << " " << relation_str << " "
745 << target_alias;
746 }
747
748 relstr << " : ";
749
750 if (!r.label().empty()) {
751 auto lbl = r.label();
752 if (r.type() == relationship_t::kFriendship)
753 lbl = "[friend]";
754 relstr << mermaid_common::to_mermaid(r.access()) << lbl;
755 rendered_relations.emplace(r.label());
756 }
757
758 if (unique_relations.count(relstr.str()) == 0) {
759 unique_relations.emplace(relstr.str());
760
761 LOG_TRACE("=== Adding relation {}", relstr.str());
762
763 all_relations_str << relstr.str() << '\n';
764 }
765 }
766 catch (error::uml_alias_missing &e) {
767 LOG_DBG("=== Skipping {} relation from {} to {} due "
768 "to: {}",
769 to_string(r.type()), c.full_name(true), destination, e.what());
770 }
771 }
772
773 ostr << all_relations_str.str();
774}

◆ start_method_group()

void clanguml::class_diagram::generators::mermaid::generator::start_method_group ( std::ostream &  ostr) const

Definition at line 137 of file class_diagram_generator.cc.

137{ }

◆ start_package()

void clanguml::class_diagram::generators::mermaid::generator::start_package ( const package p,
std::ostream &  ostr 
) const

Definition at line 795 of file class_diagram_generator.cc.

795{ }

◆ start_together_group()

void clanguml::class_diagram::generators::mermaid::generator::start_together_group ( const std::string &  group_name,
std::ostream &  ostr 
) const

Definition at line 785 of file class_diagram_generator.cc.

787{
788}

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