0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
sequence_diagram
generators
mermaid
sequence_diagram_generator.h
Go to the documentation of this file.
1
/**
2
* @file src/sequence_diagram/generators/mermaid/sequence_diagram_generator.h
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
#pragma once
19
20
#include "
common/generators/mermaid/generator.h
"
21
#include "
config/config.h
"
22
#include "
sequence_diagram/model/diagram.h
"
23
#include "
sequence_diagram/visitor/translation_unit_visitor.h
"
24
#include "
util/util.h
"
25
26
#include <glob/glob.hpp>
27
28
#include <filesystem>
29
#include <fstream>
30
#include <iostream>
31
#include <sstream>
32
33
namespace
clanguml
{
34
namespace
sequence_diagram {
35
namespace
generators {
36
namespace
mermaid
{
37
38
using
clanguml::common::eid_t
;
39
40
using
diagram_config
=
clanguml::config::sequence_diagram
;
41
using
diagram_model
=
clanguml::sequence_diagram::model::diagram
;
42
43
template
<
typename
C,
typename
D>
44
using
common_generator
=
clanguml::common::generators::mermaid::generator<C, D>
;
45
46
/**
47
* @brief Sequence diagram MermaidJS generator
48
*/
49
class
generator
:
public
common_generator
<diagram_config, diagram_model> {
50
public
:
51
generator
(
diagram_config
&
config
,
diagram_model
&
model
);
52
53
using
common_generator
<
diagram_config
,
diagram_model
>
::generate
;
54
55
/**
56
* @brief Main generator method.
57
*
58
* This method is called first and coordinates the entire diagram
59
* generation.
60
*
61
* @param ostr Output stream.
62
*/
63
void
generate_diagram
(std::ostream &ostr)
const override
;
64
65
/**
66
* @brief Generate the diagram type
67
*
68
* @param ostr Output stream
69
*/
70
void
generate_diagram_type
(std::ostream &ostr)
const override
;
71
72
/**
73
* @brief Generate sequence diagram message.
74
*
75
* @param m Message model
76
* @param ostr Output stream
77
*/
78
void
generate_call
(
const
clanguml::sequence_diagram::model::message
&m,
79
std::ostream &ostr)
const
;
80
81
/**
82
* @brief Generate sequence diagram return message
83
*
84
* @param m Message model
85
* @param ostr Output stream
86
*/
87
void
generate_return
(
const
clanguml::sequence_diagram::model::message
&m,
88
std::ostream &ostr)
const
;
89
90
/**
91
* @brief Generate sequence diagram participant
92
*
93
* @param ostr Output stream
94
* @param id Participant id
95
* @param force If true, generate the participant even if its not in
96
* the set of active participants
97
* @return Id of the generated participant
98
*/
99
void
generate_participant
(
100
std::ostream &ostr,
eid_t
id
,
bool
force =
false
)
const
;
101
102
/**
103
* @brief Generate sequence diagram participant by name
104
*
105
* This is convenience wrapper over `generate_participant()` by id.
106
*
107
* @param ostr Output stream
108
* @param name Full participant name
109
*/
110
void
generate_participant
(
111
std::ostream &ostr,
const
std::string &name)
const
;
112
113
/**
114
* @brief Generate sequence diagram activity.
115
*
116
* @param a Activity model
117
* @param ostr Output stream
118
* @param visited List of already visited participants, this is necessary
119
* for breaking infinite recursion on recursive calls
120
*/
121
void
generate_activity
(
const
clanguml::sequence_diagram::model::activity
&a,
122
std::ostream &ostr, std::vector<eid_t> &visited)
const
;
123
124
private
:
125
/**
126
* @brief Check if specified participant has already been generated.
127
*
128
* @param id Participant id.
129
* @return True, if participant has already been generated.
130
*/
131
bool
is_participant_generated
(
eid_t
id
)
const
;
132
133
/**
134
* @brief Generate MermaidJS alias for participant
135
*
136
* @param participant Sequence diagram participant model
137
* @return Particpant alias
138
*/
139
std::string
generate_alias
(
const
model::participant
&participant)
const
;
140
141
/**
142
* @brief Generate message call note
143
*
144
* @param ostr Output stream
145
* @param m Message
146
*/
147
void
generate_message_comment
(
148
std::ostream &ostr,
const
model::message
&m)
const
;
149
150
/**
151
* @brief Convert config to model message render mode.
152
*
153
* @return Method render mode.
154
*/
155
model::function::message_render_mode
156
select_method_arguments_render_mode
()
const
;
157
158
mutable
std::set<eid_t>
generated_participants_
;
159
mutable
std::set<unsigned int>
generated_comment_ids_
;
160
mutable
std::vector<model::message>
already_generated_in_static_context_
;
161
};
162
163
}
// namespace mermaid
164
}
// namespace generators
165
}
// namespace sequence_diagram
166
}
// namespace clanguml
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7