0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
include_diagram
generators
mermaid
include_diagram_generator.cc
Go to the documentation of this file.
1
/**
2
* @file src/include_diagram/generators/mermaid/include_diagram_generator.cc
3
*
4
* Copyright (c) 2021-2025 Bartek Kryza <bkryza@gmail.com>
5
*
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
17
*/
18
19
#include "
include_diagram_generator.h
"
20
21
#include "
util/error.h
"
22
23
namespace
clanguml::include_diagram::generators::mermaid
{
24
25
using
clanguml::common::generators::mermaid::indent
;
26
27
generator::generator
(
diagram_config
&config,
diagram_model
&model)
28
:
common_generator
<
diagram_config
,
diagram_model
>{
config
,
model
}
29
{
30
}
31
32
void
generator::generate_diagram_type
(std::ostream &ostr)
const
33
{
34
ostr <<
"flowchart\n"
;
35
}
36
37
void
generator::generate_relationships
(
38
const
source_file
&f, std::ostream &ostr)
const
39
{
40
if
(!
util::contains
(
m_generated_aliases
, f.
alias
()))
41
return
;
42
43
LOG_DBG
(
"Generating relationships for file {}"
, f.
full_name
(
true
));
44
45
if
(f.
type
() ==
common::model::source_file_t::kDirectory
) {
46
util::for_each
(f, [
this
, &ostr](
const
auto
&file) {
47
generate_relationships
(
48
dynamic_cast<
const
source_file
&
>
(*file), ostr);
49
});
50
}
51
else
{
52
for
(
const
auto
&r : f.
relationships
()) {
53
ostr << indent(1) << f.
alias
() <<
" "
54
<< (r.type() ==
common::model::relationship_t::kDependency
55
?
"-.->"
56
:
"-->"
)
57
<<
" "
<<
model
().get(r.destination()).value().alias() <<
'\n'
;
58
}
59
}
60
}
61
62
void
generator::generate
(
const
source_file
&f, std::ostream &ostr)
const
63
{
64
if
(
config
().generate_packages && !
config
().generate_packages()) {
65
generate_without_packages
(f, ostr);
66
}
67
else
{
68
generate_with_packages
(f, ostr);
69
}
70
}
71
72
void
generator::generate_with_packages
(
73
const
source_file
&f, std::ostream &ostr)
const
74
{
75
if
(f.
type
() ==
common::model::source_file_t::kDirectory
) {
76
LOG_DBG
(
"Generating directory {}"
, f.
name
());
77
78
ostr << indent(1) <<
"subgraph "
<< f.
alias
() <<
"["
<< f.
name
()
79
<<
"]\n"
;
80
81
util::for_each
(f, [
this
, &ostr](
const
auto
&file) {
82
generate
(
dynamic_cast<
const
source_file
&
>
(*file), ostr);
83
});
84
85
ostr << indent(1) <<
"end"
<<
'\n'
;
86
87
m_generated_aliases
.emplace(f.
alias
());
88
}
89
else
{
90
LOG_DBG
(
"Generating file {}"
, f.
name
());
91
92
ostr << indent(1) << f.
alias
() <<
"["
<< f.
name
() <<
"]\n"
;
93
94
m_generated_aliases
.emplace(f.
alias
());
95
}
96
97
if
(
config
().generate_links) {
98
common_generator<diagram_config, diagram_model>::generate_link
(ostr, f);
99
}
100
}
101
102
void
generator::generate_without_packages
(
103
const
source_file
&f, std::ostream &ostr)
const
104
{
105
if
(f.
type
() ==
common::model::source_file_t::kDirectory
) {
106
util::for_each
(f, [
this
, &ostr](
const
auto
&file) {
107
generate
(
dynamic_cast<
const
source_file
&
>
(*file), ostr);
108
});
109
110
m_generated_aliases
.emplace(f.
alias
());
111
}
112
else
{
113
LOG_DBG
(
"Generating file {}"
, f.
file_relative
());
114
115
ostr << indent(1) << f.
alias
() <<
"["
<< f.
file_relative
() <<
"]\n"
;
116
117
m_generated_aliases
.emplace(f.
alias
());
118
}
119
120
if
(
config
().generate_links) {
121
common_generator<diagram_config, diagram_model>::generate_link
(ostr, f);
122
}
123
}
124
125
void
generator::generate_diagram
(std::ostream &ostr)
const
126
{
127
// Generate files and folders
128
util::for_each
(
model
(), [
this
, &ostr](
const
auto
&f) {
129
generate
(
dynamic_cast<
source_file
&
>
(*f), ostr);
130
});
131
132
// Process file include relationships
133
util::for_each
(
model
(), [
this
, &ostr](
const
auto
&f) {
134
generate_relationships
(
dynamic_cast<
source_file
&
>
(*f), ostr);
135
});
136
137
// Process file notes
138
util::for_each
(
model
(), [
this
, &ostr](
const
auto
&f) {
139
generate_notes
(ostr,
dynamic_cast<
source_file
&
>
(*f));
140
});
141
}
142
}
// namespace clanguml::include_diagram::generators::mermaid
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7