0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
sequence_diagram
generators
json
sequence_diagram_generator.h
Go to the documentation of this file.
1
/**
2
* @file src/sequence_diagram/generators/json/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/json/generator.h
"
21
#include "
config/config.h
"
22
#include "
sequence_diagram/model/diagram.h
"
23
#include "
util/util.h
"
24
25
#include <glob/glob.hpp>
26
27
#include <filesystem>
28
#include <fstream>
29
#include <iostream>
30
#include <optional>
31
#include <sstream>
32
33
namespace
clanguml::sequence_diagram::generators::json
{
34
35
using
clanguml::common::eid_t
;
36
37
std::string
render_name
(std::string name);
38
39
using
diagram_config
=
clanguml::config::sequence_diagram
;
40
using
diagram_model
=
clanguml::sequence_diagram::model::diagram
;
41
42
template
<
typename
C,
typename
D>
43
using
common_generator
=
clanguml::common::generators::json::generator<C, D>
;
44
45
/**
46
* @brief Sequence diagram JSON generator
47
*/
48
class
generator
:
public
common_generator
<diagram_config, diagram_model> {
49
public
:
50
generator
(
diagram_config
&
config
,
diagram_model
&
model
);
51
52
using
common_generator
<
diagram_config
,
diagram_model
>
::generate
;
53
54
/**
55
* @brief Main generator method.
56
*
57
* This method is called first and coordinates the entire diagram
58
* generation.
59
*
60
* @param ostr Output stream.
61
*/
62
void
generate_diagram
(nlohmann::json &parent)
const override
;
63
64
/**
65
* @brief Generate sequence diagram message.
66
*
67
* @param m Message model
68
* @param parent JSON node
69
*/
70
void
generate_call
(
const
sequence_diagram::model::message
&m,
71
nlohmann::json &parent)
const
;
72
73
/**
74
* @brief Generate sequence diagram participant
75
*
76
* @param parent JSON node
77
* @param id Participant id
78
* @param force If true, generate the participant even if its not in
79
* the set of active participants
80
* @return Id of the generated participant
81
*/
82
std::optional<eid_t>
generate_participant
(
83
nlohmann::json &parent,
eid_t
id
,
bool
force =
false
)
const
;
84
85
/**
86
* @brief Generate sequence diagram participant by name
87
*
88
* This is convienience wrapper over `generate_participant()` by id.
89
*
90
* @param parent JSON node
91
* @param name Full participant name
92
*/
93
void
generate_participant
(
94
nlohmann::json &parent,
const
std::string &name)
const
;
95
96
/**
97
* @brief Generate sequence diagram activity.
98
*
99
* @param a Activity model
100
* @param visited List of already visited participants, this is necessary
101
* for breaking infinite recursion on recursive calls
102
*/
103
void
generate_activity
(
const
sequence_diagram::model::activity
&a,
104
std::vector<eid_t> &visited)
const
;
105
106
/**
107
* @brief Get reference to the current block statement.
108
*
109
* This method returns a reference to the last block statement (e.g if
110
* statement or for loop) in the call stack.
111
*
112
* @return Reference to the current block statement.
113
*/
114
nlohmann::json &
current_block_statement
()
const
;
115
116
std::string
make_display_name
(
const
std::string &full_name)
const
;
117
118
private
:
119
/**
120
* @brief Check if specified participant has already been generated.
121
*
122
* @param id Participant id.
123
* @return True, if participant has already been generated.
124
*/
125
bool
is_participant_generated
(
eid_t
id
)
const
;
126
127
/**
128
* @brief Process call message
129
*
130
* @param m Message model
131
* @param visited List of already visited participants
132
*/
133
void
process_call_message
(
134
const
model::message
&m, std::vector<eid_t> &visited)
const
;
135
136
/**
137
* @brief Process `if` statement message
138
*
139
* @param m Message model
140
*/
141
void
process_if_message
(
const
model::message
&m)
const
;
142
143
/**
144
* @brief Process `else if` statement message
145
*/
146
void
process_else_if_message
()
const
;
147
148
/**
149
* @brief Process `end if` statement message
150
*/
151
void
process_end_if_message
()
const
;
152
153
/**
154
* @brief Process `:?` statement message
155
*
156
* @param m Message model
157
*/
158
void
process_conditional_message
(
const
model::message
&m)
const
;
159
160
/**
161
* @brief Process end of conditional statement message
162
*/
163
void
process_end_conditional_message
()
const
;
164
165
/**
166
* @brief Process conditional else statement message
167
*
168
* @param m Message model
169
*/
170
void
process_conditional_else_message
(
const
model::message
&m)
const
;
171
172
/**
173
* @brief Process `switch` statement message
174
*
175
* @param m Message model
176
*/
177
void
process_switch_message
(
const
model::message
&m)
const
;
178
179
/**
180
* @brief Process switch end statement message
181
*/
182
void
process_end_switch_message
()
const
;
183
184
/**
185
* @brief Process `switch` `case` statement message
186
*
187
* @param m Message model
188
*/
189
void
process_case_message
(
const
model::message
&m)
const
;
190
191
/**
192
* @brief Process `try` statement message
193
*
194
* @param m Message model
195
*/
196
void
process_try_message
(
const
model::message
&m)
const
;
197
198
/**
199
* @brief Process `try` end statement message
200
*/
201
void
process_end_try_message
()
const
;
202
203
/**
204
* @brief Process `catch` statement message
205
*/
206
void
process_catch_message
()
const
;
207
208
/**
209
* @brief Process `do` loop statement message
210
*
211
* @param m Message model
212
*/
213
void
process_do_message
(
const
model::message
&m)
const
;
214
215
/**
216
* @brief Process `do` end statement message
217
*/
218
void
process_end_do_message
()
const
;
219
220
/**
221
* @brief Process `for` loop statement message
222
*
223
* @param m Message model
224
*/
225
void
process_for_message
(
const
model::message
&m)
const
;
226
227
/**
228
* @brief Process `for` end statement message
229
*/
230
void
process_end_for_message
()
const
;
231
232
/**
233
* @brief Process `while` loop message
234
*
235
* @param m Message model
236
*/
237
void
process_while_message
(
const
model::message
&m)
const
;
238
239
/**
240
* @brief Process `while` end loop message
241
*/
242
void
process_end_while_message
()
const
;
243
244
mutable
std::set<eid_t>
generated_participants_
;
245
246
// Needed to add "participants" array in a temporary object accessible from
247
// all methods of the generator
248
mutable
nlohmann::json
json_
;
249
250
mutable
std::vector<std::reference_wrapper<nlohmann::json>>
251
block_statements_stack_
;
252
253
mutable
std::vector<model::message>
already_generated_in_static_context_
;
254
};
255
256
}
// namespace clanguml::sequence_diagram::generators::json
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7