0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
sequence_diagram
model
participant.h
Go to the documentation of this file.
1
/**
2
* @file src/sequence_diagram/model/participant.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/model/element.h
"
21
#include "
common/model/template_element.h
"
22
#include "
common/model/template_parameter.h
"
23
#include "
common/model/template_trait.h
"
24
25
#include <string>
26
#include <vector>
27
28
namespace
clanguml::sequence_diagram::model
{
29
30
using
clanguml::common::eid_t
;
31
using
clanguml::common::model::template_trait
;
32
33
/**
34
* @brief Base class for various types of sequence diagram participants
35
*/
36
struct
participant
:
public
common::model::template_element
,
37
public
common::model::stylable_element
{
38
using
common::model::template_element::template_element;
39
40
/**
41
* @brief Enum representing stereotype of a participant
42
*/
43
enum class
stereotype_t
{
44
participant
= 0,
45
actor
,
46
boundary
,
47
control
,
48
entity
,
49
database
,
50
collections
,
51
queue
52
};
53
54
participant
(
const
participant
&) =
delete
;
55
participant
(
participant
&&) noexcept = delete;
56
participant
&operator=(const
participant
&) = delete;
57
participant
&operator=(
participant
&&) = delete;
58
59
/**
60
* Get the type name of the diagram element.
61
*
62
* @return Type name of the diagram element.
63
*/
64
std
::
string
type_name
()
const override
{
return
"participant"
; }
65
66
/**
67
* @brief Create a string representation of the participant
68
*
69
* @return Participant representation as string
70
*/
71
virtual
std::string
to_string
()
const
;
72
73
stereotype_t
stereotype_
{
stereotype_t::participant
};
74
};
75
76
/**
77
* @brief Sequence diagram participant representing a class.
78
*/
79
struct
class_
:
public
participant
{
80
public
:
81
class_
(
const
common::model::namespace_
&
using_namespace
);
82
83
class_
(
const
class_
&) =
delete
;
84
class_
(
class_
&&) noexcept = delete;
85
class_
&operator=(const
class_
&) = delete;
86
class_
&operator=(
class_
&&) = delete;
87
88
/**
89
* Get the type name of the diagram element.
90
*
91
* @return Type name of the diagram element.
92
*/
93
std
::
string
type_name
()
const override
94
{
95
if
(
is_lambda
())
96
return
"lambda"
;
97
98
return
"class"
;
99
}
100
101
/**
102
* @brief Check if class is a struct.
103
*
104
* @return True, if the class is declared as struct.
105
*/
106
bool
is_struct
()
const
;
107
108
/**
109
* @brief Set whether the class is a struct.
110
*
111
* @param is_struct True, if the class is declared as struct
112
*/
113
void
is_struct
(
bool
is_struct
);
114
115
/**
116
* @brief Check if class is a template.
117
*
118
* @return True, if the class is a template.
119
*/
120
bool
is_template
()
const
;
121
122
/**
123
* @brief Set whether the class is a template instantiation.
124
*
125
* @param is_template True, if the class is a template
126
*/
127
void
is_template
(
bool
is_template
);
128
129
/**
130
* @brief Check if class is a template instantiation.
131
*
132
* @return True, if the class is a template instantiation.
133
*/
134
bool
is_template_instantiation
()
const
;
135
136
/**
137
* @brief Set whether the class is a template instantiation.
138
*
139
* @param is_template_instantiation True, if the class is a template
140
* instantiation.
141
*/
142
void
is_template_instantiation
(
bool
is_template_instantiation
);
143
144
friend
bool
operator==
(
const
class_
&l,
const
class_
&r);
145
146
/**
147
* Return elements full name.
148
*
149
* @return Fully qualified elements name.
150
*/
151
std::string
full_name
(
bool
relative =
true
)
const override
;
152
153
/**
154
* Return elements full name but without namespace.
155
*
156
* @return Elements full name without namespace.
157
*/
158
std::string
full_name_no_ns
()
const override
;
159
160
/**
161
* @brief Check if class is a abstract.
162
*
163
* @return True, if the class is abstract.
164
*/
165
bool
is_abstract
()
const
;
166
167
/**
168
* @brief Check if class is a typedef/using alias.
169
*
170
* @return True, if the class is a typedef/using alias.
171
*/
172
bool
is_alias
()
const
;
173
174
/**
175
* @brief Set whether the class is an alias
176
*
177
* @param alias True if the class is a typedef/using alias.
178
*/
179
void
is_alias
(
bool
alias
);
180
181
/**
182
* @brief Check if the class is lambda
183
* @return
184
*/
185
bool
is_lambda
()
const
;
186
187
/**
188
* @brief Set whether the class is a lambda.
189
*
190
* @param is_lambda True, if the class is a lambda
191
*/
192
void
is_lambda
(
bool
is_lambda
);
193
194
void
set_lambda_operator_id
(
eid_t
id
) {
lambda_operator_id_
=
id
; }
195
196
eid_t
lambda_operator_id
()
const
{
return
lambda_operator_id_
; }
197
198
private
:
199
bool
is_struct_
{
false
};
200
bool
is_template_
{
false
};
201
bool
is_template_instantiation_
{
false
};
202
bool
is_alias_
{
false
};
203
bool
is_lambda_
{
false
};
204
eid_t
lambda_operator_id_
{};
205
206
std::string
full_name_
;
207
};
208
209
/**
210
* @brief Participant mode representing a free function.
211
*/
212
struct
function
:
public
participant
{
213
enum class
message_render_mode
{
full
,
abbreviated
,
no_arguments
};
214
215
function
(
const
common::model::namespace_
&
using_namespace
);
216
217
function
(
const
function
&) =
delete
;
218
function
(
function
&&) noexcept = delete;
219
function
&operator=(const
function
&) = delete;
220
function
&operator=(
function
&&) = delete;
221
222
/**
223
* Get the type name of the diagram element.
224
*
225
* @return Type name of the diagram element.
226
*/
227
std
::
string
type_name
()
const override
{
return
"function"
; }
228
229
/**
230
* Return elements full name.
231
*
232
* @return Fully qualified elements name.
233
*/
234
std::string
full_name
(
bool
relative =
true
)
const override
;
235
236
/**
237
* Return elements full name but without namespace.
238
*
239
* @return Elements full name without namespace.
240
*/
241
std::string
full_name_no_ns
()
const override
;
242
243
/**
244
* @brief Render function name as message label
245
*
246
* @param mode Function argument render mode
247
* @return Message label
248
*/
249
virtual
std::string
message_name
(
message_render_mode
mode)
const
;
250
251
/**
252
* @brief Check if function is const
253
*
254
* @return True, if function is const
255
*/
256
bool
is_const
()
const
;
257
258
/**
259
* @brief Set whether the function is const
260
*
261
* @param c True, if function is const
262
*/
263
void
is_const
(
bool
c);
264
265
/**
266
* @brief Check, if the function has no return value
267
*
268
* @return True, if the function has no return value
269
*/
270
bool
is_void
()
const
;
271
272
/**
273
* @brief Set whether the function has a return value
274
*
275
* @param v True, if the function has no return value
276
*/
277
void
is_void
(
bool
v);
278
279
/**
280
* @brief Check, if the function is static
281
*
282
* @return True, if the function is static
283
*/
284
bool
is_static
()
const
;
285
286
/**
287
* @brief Set whether the function is static
288
*
289
* @param v True, if the function is static
290
*/
291
void
is_static
(
bool
s);
292
293
/**
294
* @brief Check, if the method is an operator
295
*
296
* @return True, if the method is an operator
297
*/
298
bool
is_operator
()
const
;
299
300
/**
301
* @brief Set whether the method is an operator
302
*
303
* @param v True, if the method is an operator
304
*/
305
void
is_operator
(
bool
o);
306
307
/**
308
* @brief Check, if a functions is a call to CUDA Kernel
309
*
310
* @return True, if the method is a CUDA kernel call
311
*/
312
bool
is_cuda_kernel
()
const
;
313
314
/**
315
* @brief Set whether the method is a CUDA kernel call
316
*
317
* @param v True, if the method is a CUDA kernel call
318
*/
319
void
is_cuda_kernel
(
bool
c);
320
321
/**
322
* @brief Check, if a functions is a call to CUDA device
323
*
324
* @return True, if the method is a CUDA device call
325
*/
326
bool
is_cuda_device
()
const
;
327
328
/**
329
* @brief Set whether the method is a CUDA device call
330
*
331
* @param v True, if the method is a CUDA device call
332
*/
333
void
is_cuda_device
(
bool
c);
334
335
/**
336
* @brief Set functions return type
337
*
338
* @param rt Return type
339
*/
340
void
return_type
(
const
std::string &rt);
341
342
/**
343
* @brief Get function return type
344
*
345
* @return Return type
346
*/
347
const
std::string &
return_type
()
const
;
348
349
/**
350
* @brief Add a function parameter
351
*
352
* @note In sequence diagrams we don't care about relationships from
353
* function or method parameters, so we don't need to model them in detail.
354
*
355
* @param a Function parameter label including name and type
356
*/
357
void
add_parameter
(
const
std::string &a);
358
359
/**
360
* @brief Get the list of function parameters
361
*
362
* @return List of function parameters
363
*/
364
const
std::vector<std::string> &
parameters
()
const
;
365
366
private
:
367
bool
is_const_
{
false
};
368
bool
is_void_
{
false
};
369
bool
is_static_
{
false
};
370
bool
is_operator_
{
false
};
371
bool
is_cuda_kernel_
{
false
};
372
bool
is_cuda_device_
{
false
};
373
std::string
return_type_
;
374
std::vector<std::string>
parameters_
;
375
};
376
377
/**
378
* @brief Participant model representing a method
379
*/
380
struct
method
:
public
function
{
381
method
(
const
common::model::namespace_
&
using_namespace
);
382
383
method
(
const
method
&) =
delete
;
384
method
(
method
&&) noexcept = delete;
385
method
&operator=(const
method
&) = delete;
386
method
&operator=(
method
&&) = delete;
387
388
/**
389
* Get the type name of the diagram element.
390
*
391
* @return Type name of the diagram element.
392
*/
393
std
::
string
type_name
()
const override
{
return
"method"
; }
394
395
/**
396
* @brief Get method name
397
* @return Method name
398
*/
399
std::string
method_name
()
const
;
400
401
/**
402
* @brief Set method name
403
*
404
* @param name Method name
405
*/
406
void
set_method_name
(
const
std::string &
name
);
407
408
/**
409
* @brief Get the participant PlantUML alias
410
*
411
* @todo This method does not belong here - refactor to PlantUML specific
412
* code.
413
*
414
* @return PlantUML alias for the participant to which this method belongs
415
* to.
416
*/
417
std::string
alias
()
const override
;
418
419
/**
420
* @brief Set the id of the participant to which this method belongs to.
421
*
422
* @param id Id of the class to which this method belongs to
423
*/
424
void
set_class_id
(
eid_t
id
);
425
426
/**
427
* @brief Set full qualified name of the class
428
*
429
* @param name Name of the class including namespace
430
*/
431
void
set_class_full_name
(
const
std::string &
name
);
432
433
/**
434
* @brief Get the class full name.
435
*
436
* @return Class full name
437
*/
438
const
auto
&
class_full_name
()
const
;
439
440
/**
441
* Return elements full name.
442
*
443
* @return Fully qualified elements name.
444
*/
445
std::string
full_name
(
bool
relative)
const override
;
446
447
std::string
message_name
(
message_render_mode
mode)
const override
;
448
449
/**
450
* @brief Get the class id
451
*
452
* @return Class id
453
*/
454
eid_t
class_id
()
const
;
455
456
/**
457
* @brief Create a string representation of the participant
458
*
459
* @return Participant representation as string
460
*/
461
std::string
to_string
()
const override
;
462
463
/**
464
* @brief Check, if the method is a constructor
465
*
466
* @return True, if the method is a constructor
467
*/
468
bool
is_constructor
()
const
;
469
470
/**
471
* @brief Set whether the method is a constructor
472
*
473
* @param v True, if the method is a constructor
474
*/
475
void
is_constructor
(
bool
c);
476
477
/**
478
* @brief Check, if the method is defaulted
479
*
480
* @return True, if the method is defaulted
481
*/
482
bool
is_defaulted
()
const
;
483
484
/**
485
* @brief Set whether the method is defaulted
486
*
487
* @param v True, if the method is defaulted
488
*/
489
void
is_defaulted
(
bool
c);
490
491
/**
492
* @brief Check, if the method is an assignment operator
493
*
494
* @return True, if the method is an assignment operator
495
*/
496
bool
is_assignment
()
const
;
497
498
/**
499
* @brief Set whether the method is an assignment operator
500
*
501
* @param v True, if the method is an assignment operator
502
*/
503
void
is_assignment
(
bool
a);
504
505
private
:
506
eid_t
class_id_
{};
507
std::string
method_name_
;
508
std::string
class_full_name_
;
509
bool
is_constructor_
{
false
};
510
bool
is_defaulted_
{
false
};
511
bool
is_assignment_
{
false
};
512
};
513
514
/**
515
* @brief Participant model representing a function template.
516
*/
517
struct
function_template
:
public
function
{
518
function_template
(
const
common::model::namespace_
&
using_namespace
);
519
520
function_template
(
const
function_template
&) =
delete
;
521
function_template
(
function_template
&&) noexcept = delete;
522
function_template
&operator=(const
function_template
&) = delete;
523
function_template
&operator=(
function_template
&&) = delete;
524
525
/**
526
* Get the type name of the diagram element.
527
*
528
* @return Type name of the diagram element.
529
*/
530
std
::
string
type_name
()
const override
{
return
"function_template"
; }
531
532
/**
533
* Return elements full name.
534
*
535
* @return Fully qualified elements name.
536
*/
537
std::string
full_name
(
bool
relative =
true
)
const override
;
538
539
/**
540
* Return elements full name but without namespace.
541
*
542
* @return Elements full name without namespace.
543
*/
544
std::string
full_name_no_ns
()
const override
;
545
546
/**
547
* @brief Render function name as message label
548
*
549
* @param mode Function argument render mode
550
* @return Message label
551
*/
552
std::string
message_name
(
message_render_mode
mode)
const override
;
553
};
554
}
// namespace clanguml::sequence_diagram::model
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7