0.6.1
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-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
#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
~
participant
() override = default;
60
61
/**
62
* Get the type name of the diagram element.
63
*
64
* @return Type name of the diagram element.
65
*/
66
std
::
string
type_name
()
const override
{
return
"participant"
; }
67
68
/**
69
* @brief Create a string representation of the participant
70
*
71
* @return Participant representation as string
72
*/
73
virtual
std::string
to_string
()
const
;
74
75
stereotype_t
stereotype_
{
stereotype_t::participant
};
76
};
77
78
/**
79
* @brief Sequence diagram participant representing a class.
80
*/
81
struct
class_
:
public
participant
{
82
public
:
83
class_
(
const
common::model::namespace_
&
using_namespace
);
84
85
class_
(
const
class_
&) =
delete
;
86
class_
(
class_
&&) noexcept = delete;
87
class_
&operator=(const
class_
&) = delete;
88
class_
&operator=(
class_
&&) = delete;
89
90
~
class_
() override = default;
91
92
/**
93
* Get the type name of the diagram element.
94
*
95
* @return Type name of the diagram element.
96
*/
97
std
::
string
type_name
()
const override
98
{
99
if
(
is_lambda
())
100
return
"lambda"
;
101
102
if
(
is_objc_interface
())
103
return
"objc_interface"
;
104
105
return
"class"
;
106
}
107
108
/**
109
* @brief Check if class is a struct.
110
*
111
* @return True, if the class is declared as struct.
112
*/
113
bool
is_struct
()
const
;
114
115
/**
116
* @brief Set whether the class is a struct.
117
*
118
* @param is_struct True, if the class is declared as struct
119
*/
120
void
is_struct
(
bool
is_struct
);
121
122
/**
123
* @brief Check if class is a template.
124
*
125
* @return True, if the class is a template.
126
*/
127
bool
is_template
()
const
;
128
129
/**
130
* @brief Set whether the class is a template instantiation.
131
*
132
* @param is_template True, if the class is a template
133
*/
134
void
is_template
(
bool
is_template
);
135
136
/**
137
* @brief Check if class is a template instantiation.
138
*
139
* @return True, if the class is a template instantiation.
140
*/
141
bool
is_template_instantiation
()
const
;
142
143
/**
144
* @brief Set whether the class is a template instantiation.
145
*
146
* @param is_template_instantiation True, if the class is a template
147
* instantiation.
148
*/
149
void
is_template_instantiation
(
bool
is_template_instantiation
);
150
151
friend
bool
operator==
(
const
class_
&l,
const
class_
&r);
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
bool
is_objc_interface
()
const
;
195
196
void
is_objc_interface
(
bool
is_objc_interface
);
197
198
bool
is_objc_protocol
()
const
;
199
200
void
is_objc_protocol
(
bool
is_objc_protocol
);
201
202
void
set_lambda_operator_id
(
eid_t
id
) {
lambda_operator_id_
=
id
; }
203
204
eid_t
lambda_operator_id
()
const
{
return
lambda_operator_id_
; }
205
206
protected
:
207
/**
208
* Return elements full name.
209
*
210
* @return Fully qualified elements name.
211
*/
212
std::string
full_name_impl
(
bool
relative =
true
)
const override
;
213
214
private
:
215
bool
is_struct_
{
false
};
216
bool
is_template_
{
false
};
217
bool
is_template_instantiation_
{
false
};
218
bool
is_alias_
{
false
};
219
bool
is_lambda_
{
false
};
220
bool
is_objc_interface_
{
false
};
221
bool
is_objc_protocol_
{
false
};
222
eid_t
lambda_operator_id_
{};
223
224
std::string
full_name_
;
225
};
226
227
/**
228
* @brief Participant mode representing a free function.
229
*/
230
struct
function
:
public
participant
{
231
enum class
message_render_mode
{
full
,
abbreviated
,
no_arguments
};
232
233
function
(
const
common::model::namespace_
&
using_namespace
);
234
235
function
(
const
function
&) =
delete
;
236
function
(
function
&&) noexcept = delete;
237
function
&operator=(const
function
&) = delete;
238
function
&operator=(
function
&&) = delete;
239
240
~
function
() override = default;
241
242
/**
243
* Get the type name of the diagram element.
244
*
245
* @return Type name of the diagram element.
246
*/
247
std
::
string
type_name
()
const override
{
return
"function"
; }
248
249
/**
250
* Return elements full name but without namespace.
251
*
252
* @return Elements full name without namespace.
253
*/
254
std::string
full_name_no_ns
()
const override
;
255
256
/**
257
* @brief Render function name as message label
258
*
259
* @param mode Function argument render mode
260
* @return Message label
261
*/
262
virtual
std::string
message_name
(
message_render_mode
mode)
const
;
263
264
/**
265
* @brief Check if function is const
266
*
267
* @return True, if function is const
268
*/
269
bool
is_const
()
const
;
270
271
/**
272
* @brief Set whether the function is const
273
*
274
* @param c True, if function is const
275
*/
276
void
is_const
(
bool
c);
277
278
/**
279
* @brief Check, if the function has no return value
280
*
281
* @return True, if the function has no return value
282
*/
283
bool
is_void
()
const
;
284
285
/**
286
* @brief Set whether the function has a return value
287
*
288
* @param v True, if the function has no return value
289
*/
290
void
is_void
(
bool
v);
291
292
/**
293
* @brief Check, if the function is static
294
*
295
* @return True, if the function is static
296
*/
297
bool
is_static
()
const
;
298
299
/**
300
* @brief Set whether the function is static
301
*
302
* @param v True, if the function is static
303
*/
304
void
is_static
(
bool
s);
305
306
/**
307
* @brief Check, if the method is an operator
308
*
309
* @return True, if the method is an operator
310
*/
311
bool
is_operator
()
const
;
312
313
/**
314
* @brief Set whether the method is an operator
315
*
316
* @param v True, if the method is an operator
317
*/
318
void
is_operator
(
bool
o);
319
320
/**
321
* @brief Check, if a functions is a call to CUDA Kernel
322
*
323
* @return True, if the method is a CUDA kernel call
324
*/
325
bool
is_cuda_kernel
()
const
;
326
327
/**
328
* @brief Set whether the method is a CUDA kernel call
329
*
330
* @param v True, if the method is a CUDA kernel call
331
*/
332
void
is_cuda_kernel
(
bool
c);
333
334
/**
335
* @brief Check, if a functions is a call to CUDA device
336
*
337
* @return True, if the method is a CUDA device call
338
*/
339
bool
is_cuda_device
()
const
;
340
341
/**
342
* @brief Set whether the method is a CUDA device call
343
*
344
* @param v True, if the method is a CUDA device call
345
*/
346
void
is_cuda_device
(
bool
c);
347
348
/**
349
* @brief Check, if a function is a coroutine
350
*
351
* @return True, if the function is a coroutine
352
*/
353
bool
is_coroutine
()
const
;
354
355
/**
356
* @brief Set whether the function is a coroutine
357
*
358
* @param v True, if the function is a coroutine
359
*/
360
void
is_coroutine
(
bool
c);
361
362
/**
363
* @brief Set functions return type
364
*
365
* @param rt Return type
366
*/
367
void
return_type
(
const
std::string &rt);
368
369
/**
370
* @brief Get function return type
371
*
372
* @return Return type
373
*/
374
const
std::string &
return_type
()
const
;
375
376
/**
377
* @brief Add a function parameter
378
*
379
* @note In sequence diagrams we don't care about relationships from
380
* function or method parameters, so we don't need to model them in detail.
381
*
382
* @param a Function parameter label including name and type
383
*/
384
void
add_parameter
(
const
std::string &a);
385
386
/**
387
* @brief Get the list of function parameters
388
*
389
* @return List of function parameters
390
*/
391
const
std::vector<std::string> &
parameters
()
const
;
392
393
protected
:
394
/**
395
* Return elements full name.
396
*
397
* @return Fully qualified elements name.
398
*/
399
std::string
full_name_impl
(
bool
relative =
true
)
const override
;
400
401
private
:
402
bool
is_const_
{
false
};
403
bool
is_void_
{
false
};
404
bool
is_static_
{
false
};
405
bool
is_operator_
{
false
};
406
bool
is_cuda_kernel_
{
false
};
407
bool
is_cuda_device_
{
false
};
408
bool
is_coroutine_
{
false
};
409
std::string
return_type_
;
410
std::vector<std::string>
parameters_
;
411
};
412
413
/**
414
* @brief Participant model representing a method
415
*/
416
struct
method
:
public
function
{
417
method
(
const
common::model::namespace_
&
using_namespace
);
418
419
method
(
const
method
&) =
delete
;
420
method
(
method
&&) noexcept = delete;
421
method
&operator=(const
method
&) = delete;
422
method
&operator=(
method
&&) = delete;
423
424
~
method
() override = default;
425
426
/**
427
* Get the type name of the diagram element.
428
*
429
* @return Type name of the diagram element.
430
*/
431
std
::
string
type_name
()
const override
{
return
"method"
; }
432
433
/**
434
* @brief Get method name
435
* @return Method name
436
*/
437
std::string
method_name
()
const
;
438
439
/**
440
* @brief Set method name
441
*
442
* @param name Method name
443
*/
444
void
set_method_name
(
const
std::string &
name
);
445
446
/**
447
* @brief Get the participant PlantUML alias
448
*
449
* @todo This method does not belong here - refactor to PlantUML specific
450
* code.
451
*
452
* @return PlantUML alias for the participant to which this method belongs
453
* to.
454
*/
455
std::string
alias
()
const override
;
456
457
/**
458
* @brief Set the id of the participant to which this method belongs to.
459
*
460
* @param id Id of the class to which this method belongs to
461
*/
462
void
set_class_id
(
eid_t
id
);
463
464
/**
465
* @brief Set full qualified name of the class
466
*
467
* @param name Name of the class including namespace
468
*/
469
void
set_class_full_name
(
const
std::string &
name
);
470
471
/**
472
* @brief Get the class full name.
473
*
474
* @return Class full name
475
*/
476
const
auto
&
class_full_name
()
const
;
477
478
std::string
message_name
(
message_render_mode
mode)
const override
;
479
480
/**
481
* @brief Get the class id
482
*
483
* @return Class id
484
*/
485
eid_t
class_id
()
const
;
486
487
/**
488
* @brief Create a string representation of the participant
489
*
490
* @return Participant representation as string
491
*/
492
std::string
to_string
()
const override
;
493
494
/**
495
* @brief Check, if the method is a constructor
496
*
497
* @return True, if the method is a constructor
498
*/
499
bool
is_constructor
()
const
;
500
501
/**
502
* @brief Set whether the method is a constructor
503
*
504
* @param v True, if the method is a constructor
505
*/
506
void
is_constructor
(
bool
c);
507
508
/**
509
* @brief Check, if the method is defaulted
510
*
511
* @return True, if the method is defaulted
512
*/
513
bool
is_defaulted
()
const
;
514
515
/**
516
* @brief Set whether the method is defaulted
517
*
518
* @param v True, if the method is defaulted
519
*/
520
void
is_defaulted
(
bool
c);
521
522
/**
523
* @brief Check, if the method is an assignment operator
524
*
525
* @return True, if the method is an assignment operator
526
*/
527
bool
is_assignment
()
const
;
528
529
/**
530
* @brief Set whether the method is an assignment operator
531
*
532
* @param v True, if the method is an assignment operator
533
*/
534
void
is_assignment
(
bool
a);
535
536
protected
:
537
/**
538
* Return elements full name.
539
*
540
* @return Fully qualified elements name.
541
*/
542
std::string
full_name_impl
(
bool
relative)
const override
;
543
544
private
:
545
eid_t
class_id_
{};
546
std::string
method_name_
;
547
std::string
class_full_name_
;
548
bool
is_constructor_
{
false
};
549
bool
is_defaulted_
{
false
};
550
bool
is_assignment_
{
false
};
551
};
552
553
struct
objc_method
:
public
function
{
554
objc_method
(
const
common::model::namespace_
&
using_namespace
);
555
556
objc_method
(
const
objc_method
&) =
delete
;
557
objc_method
(
objc_method
&&) noexcept = delete;
558
objc_method
&operator=(const
objc_method
&) = delete;
559
objc_method
&operator=(
objc_method
&&) = delete;
560
561
~
objc_method
() override = default;
562
563
/**
564
* Get the type name of the diagram element.
565
*
566
* @return Type name of the diagram element.
567
*/
568
std
::
string
type_name
()
const override
{
return
"objc_method"
; }
569
570
/**
571
* @brief Get method name
572
* @return Method name
573
*/
574
std::string
method_name
()
const
;
575
576
/**
577
* @brief Set method name
578
*
579
* @param name Method name
580
*/
581
void
set_method_name
(
const
std::string &
name
);
582
583
/**
584
* @brief Get the participant PlantUML alias
585
*
586
* @todo This method does not belong here - refactor to PlantUML specific
587
* code.
588
*
589
* @return PlantUML alias for the participant to which this method belongs
590
* to.
591
*/
592
std::string
alias
()
const override
;
593
594
/**
595
* @brief Set the id of the participant to which this method belongs to.
596
*
597
* @param id Id of the class to which this method belongs to
598
*/
599
void
set_class_id
(
eid_t
id
);
600
601
/**
602
* @brief Set full qualified name of the class
603
*
604
* @param name Name of the class including namespace
605
*/
606
void
set_class_full_name
(
const
std::string &
name
);
607
608
/**
609
* @brief Get the class full name.
610
*
611
* @return Class full name
612
*/
613
const
auto
&
class_full_name
()
const
;
614
615
std::string
message_name
(
message_render_mode
mode)
const override
;
616
617
/**
618
* @brief Get the class id
619
*
620
* @return Class id
621
*/
622
eid_t
class_id
()
const
;
623
624
/**
625
* @brief Create a string representation of the participant
626
*
627
* @return Participant representation as string
628
*/
629
std::string
to_string
()
const override
;
630
631
protected
:
632
/**
633
* Return elements full name.
634
*
635
* @return Fully qualified elements name.
636
*/
637
std::string
full_name_impl
(
bool
relative)
const override
;
638
639
private
:
640
eid_t
class_id_
{};
641
std::string
method_name_
;
642
std::string
class_full_name_
;
643
};
644
645
/**
646
* @brief Participant model representing a function template.
647
*/
648
struct
function_template
:
public
function
{
649
function_template
(
const
common::model::namespace_
&
using_namespace
);
650
651
function_template
(
const
function_template
&) =
delete
;
652
function_template
(
function_template
&&) noexcept = delete;
653
function_template
&operator=(const
function_template
&) = delete;
654
function_template
&operator=(
function_template
&&) = delete;
655
656
~
function_template
() override = default;
657
658
/**
659
* Get the type name of the diagram element.
660
*
661
* @return Type name of the diagram element.
662
*/
663
std
::
string
type_name
()
const override
{
return
"function_template"
; }
664
665
/**
666
* Return elements full name but without namespace.
667
*
668
* @return Elements full name without namespace.
669
*/
670
std::string
full_name_no_ns
()
const override
;
671
672
/**
673
* @brief Render function name as message label
674
*
675
* @param mode Function argument render mode
676
* @return Message label
677
*/
678
std::string
message_name
(
message_render_mode
mode)
const override
;
679
680
protected
:
681
/**
682
* Return elements full name.
683
*
684
* @return Fully qualified elements name.
685
*/
686
std::string
full_name_impl
(
bool
relative =
true
)
const override
;
687
};
688
}
// namespace clanguml::sequence_diagram::model
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7