0.5.4
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-2024 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
(f.
type
() ==
common::model::source_file_t::kDirectory
) {
65
LOG_DBG
(
"Generating directory {}"
, f.
name
());
66
67
ostr << indent(1) <<
"subgraph "
<< f.
alias
() <<
"["
<< f.
name
()
68
<<
"]\n"
;
69
70
util::for_each
(f, [
this
, &ostr](
const
auto
&file) {
71
generate
(
dynamic_cast<
const
source_file
&
>
(*file), ostr);
72
});
73
74
ostr << indent(1) <<
"end"
<<
'\n'
;
75
76
m_generated_aliases
.emplace(f.
alias
());
77
}
78
else
{
79
LOG_DBG
(
"Generating file {}"
, f.
name
());
80
81
ostr << indent(1) << f.
alias
() <<
"["
<< f.
name
() <<
"]\n"
;
82
83
m_generated_aliases
.emplace(f.
alias
());
84
}
85
86
if
(
config
().generate_links) {
87
common_generator<diagram_config, diagram_model>::generate_link
(ostr, f);
88
}
89
}
90
91
void
generator::generate_diagram
(std::ostream &ostr)
const
92
{
93
// Generate files and folders
94
util::for_each
(
model
(), [
this
, &ostr](
const
auto
&f) {
95
generate
(
dynamic_cast<
source_file
&
>
(*f), ostr);
96
});
97
98
// Process file include relationships
99
util::for_each
(
model
(), [
this
, &ostr](
const
auto
&f) {
100
generate_relationships
(
dynamic_cast<
source_file
&
>
(*f), ostr);
101
});
102
103
// Process file notes
104
util::for_each
(
model
(), [
this
, &ostr](
const
auto
&f) {
105
generate_notes
(ostr,
dynamic_cast<
source_file
&
>
(*f));
106
});
107
}
108
}
// namespace clanguml::include_diagram::generators::mermaid
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7