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