0.6.1
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
participant.cc
Go to the documentation of this file.
1/**
2 * @file src/sequence_diagram/model/participant.cc
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
19#include "participant.h"
20
22
23std::string participant::to_string() const
24{
25 return fmt::format(
26 "Participant '{}': id={} name={}", type_name(), id(), full_name(false));
27}
28
30 : participant{using_namespace}
31{
32}
33
34bool class_::is_struct() const { return is_struct_; }
35
36void class_::is_struct(bool is_struct) { is_struct_ = is_struct; }
37
38bool class_::is_template() const { return is_template_; }
39
40void class_::is_template(bool is_template) { is_template_ = is_template; }
41
43{
45}
46
47void class_::is_template_instantiation(bool is_template_instantiation)
48{
50}
51
52std::string class_::full_name_no_ns() const
53{
54 using namespace clanguml::util;
55
56 std::ostringstream ostr;
57
58 ostr << name();
59
61
62 return ostr.str();
63}
64
65std::string class_::full_name_impl(bool relative) const
66{
67 using namespace clanguml::util;
69
70 std::ostringstream ostr;
71
72 if (relative)
73 ostr << name();
74 else
75 ostr << name_and_ns();
76 render_template_params(ostr, using_namespace(), relative);
77
78 std::string res;
79
80 if (relative)
81 res = using_namespace().relative(ostr.str());
82 else
83 res = ostr.str();
84
85 if (res.empty())
86 return "<<anonymous>>";
87
88 return res;
89}
90
91bool class_::is_alias() const { return is_alias_; }
92
93void class_::is_alias(bool alias) { is_alias_ = alias; }
94
95bool class_::is_lambda() const { return is_lambda_; }
96
97void class_::is_lambda(bool is_lambda) { is_lambda_ = is_lambda; }
98
100
101void class_::is_objc_interface(bool is_objc_interface)
102{
104}
105
107
108void class_::is_objc_protocol(bool is_objc_protocol)
109{
111}
112
113bool operator==(const class_ &l, const class_ &r) { return l.id() == r.id(); }
114
116 : participant{using_namespace}
117{
118}
119
120std::string function::full_name_impl(bool relative) const
121{
122 return fmt::format("{}({}){}", participant::full_name_impl(relative),
123 fmt::join(parameters_, ","), is_const() ? " const" : "");
124}
125
126std::string function::full_name_no_ns() const
127{
128 return fmt::format("{}({}){}", element::full_name_no_ns(),
129 fmt::join(parameters_, ","), is_const() ? " const" : "");
130}
131
133{
134 constexpr auto kAbbreviatedMethodArgumentsLength{15};
135
137 return fmt::format("{}(){}", name(), is_const() ? " const" : "");
138 }
140 return fmt::format("{}({}){}", name(),
142 fmt::format("{}", fmt::join(parameters_, ",")),
143 kAbbreviatedMethodArgumentsLength),
144 is_const() ? " const" : "");
145 }
146
147 return fmt::format("{}({}){}", name(), fmt::join(parameters_, ","),
148 is_const() ? " const" : "");
149}
150
151bool function::is_const() const { return is_const_; }
152
153void function::is_const(bool c) { is_const_ = c; }
154
155bool function::is_void() const { return is_void_; }
156
157void function::is_void(bool v) { is_void_ = v; }
158
159bool function::is_static() const { return is_static_; }
160
161void function::is_static(bool s) { is_static_ = s; }
162
163bool function::is_operator() const { return is_operator_; }
164
166
168
170
172
174
175bool function::is_coroutine() const { return is_coroutine_; }
176
178
179void function::return_type(const std::string &rt) { return_type_ = rt; }
180
181const std::string &function::return_type() const { return return_type_; }
182
183void function::add_parameter(const std::string &a) { parameters_.push_back(a); }
184
185const std::vector<std::string> &function::parameters() const
186{
187 return parameters_;
188}
189
191 : function{using_namespace}
192{
193}
194
195std::string objc_method::method_name() const { return method_name_; }
196
197std::string objc_method::alias() const
198{
199 assert(class_id_.is_global());
200
201 return fmt::format("C_{:022}", class_id_.value());
202}
203
204void objc_method::set_method_name(const std::string &name)
205{
207}
208
210
211void objc_method::set_class_full_name(const std::string &name)
212{
214}
215
216const auto &objc_method::class_full_name() const { return class_full_name_; }
217
218std::string objc_method::full_name_impl(bool relative) const
219{
220 if (relative)
221 return fmt::format("{}({}){}", method_name(),
222 fmt::join(parameters(), ","), is_const() ? " const" : "");
223
224 return fmt::format("{}::{}({}){}", class_full_name(), method_name(),
225 fmt::join(parameters(), ","), is_const() ? " const" : "");
226}
227
229{
230 constexpr auto kAbbreviatedMethodArgumentsLength{15};
231
232 const std::string style{};
233
235 return fmt::format("{}{}(){}{}", style, method_name(),
236 is_const() ? " const" : "", style);
237 }
239 return fmt::format("{}({}){}", name(),
241 fmt::format("{}", fmt::join(parameters(), ",")),
242 kAbbreviatedMethodArgumentsLength),
243 is_const() ? " const" : "");
244 }
245
246 return fmt::format("{}{}({}){}{}", style, method_name(),
247 fmt::join(parameters(), ","), is_const() ? " const" : "", style);
248}
249
251
252std::string objc_method::to_string() const
253{
254 return fmt::format("Participant '{}': id={}, name={}, class_id={}",
255 type_name(), id(), full_name(false), class_id());
256}
257
259 : function{using_namespace}
260{
261}
262
263std::string method::method_name() const { return method_name_; }
264
265std::string method::alias() const
266{
267 assert(class_id_.is_global());
268
269 return fmt::format("C_{:022}", class_id_.value());
270}
271
273
275
276bool method::is_defaulted() const { return is_defaulted_; }
277
279
280bool method::is_assignment() const { return is_assignment_; }
281
283
284void method::set_method_name(const std::string &name) { method_name_ = name; }
285
287
288void method::set_class_full_name(const std::string &name)
289{
291}
292
293const auto &method::class_full_name() const { return class_full_name_; }
294
295std::string method::full_name_impl(bool relative) const
296{
297 if (relative)
298 return fmt::format("{}({}){}", method_name(),
299 fmt::join(parameters(), ","), is_const() ? " const" : "");
300
301 return fmt::format("{}::{}({}){}", class_full_name(), method_name(),
302 fmt::join(parameters(), ","), is_const() ? " const" : "");
303}
304
306{
307 constexpr auto kAbbreviatedMethodArgumentsLength{15};
308
309 const std::string style{};
310
312 return fmt::format("{}{}(){}{}", style, method_name(),
313 is_const() ? " const" : "", style);
314 }
316 return fmt::format("{}({}){}", name(),
318 fmt::format("{}", fmt::join(parameters(), ",")),
319 kAbbreviatedMethodArgumentsLength),
320 is_const() ? " const" : "");
321 }
322
323 return fmt::format("{}{}({}){}{}", style, method_name(),
324 fmt::join(parameters(), ","), is_const() ? " const" : "", style);
325}
326
328
329std::string method::to_string() const
330{
331 return fmt::format("Participant '{}': id={}, name={}, class_id={}",
332 type_name(), id(), full_name(false), class_id());
333}
334
336 const common::model::namespace_ &using_namespace)
337 : function{using_namespace}
338{
339}
340
341std::string function_template::full_name_impl(bool relative) const
342{
343 using namespace clanguml::util;
345
346 std::ostringstream ostr;
347
348 ostr << name_and_ns();
349 render_template_params(ostr, using_namespace(), relative);
350
351 ostr << fmt::format(
352 "({}){}", fmt::join(parameters(), ","), is_const() ? " const" : "");
353
354 std::string res;
355
356 if (relative)
357 res = using_namespace().relative(ostr.str());
358 else
359 res = ostr.str();
360
361 if (res.empty())
362 return "<<anonymous>>";
363
364 return res;
365}
366
368{
369 using namespace clanguml::util;
370
371 std::ostringstream ostr;
372
373 ostr << name();
374
376
377 ostr << fmt::format(
378 "({}){}", fmt::join(parameters(), ","), is_const() ? " const" : "");
379
380 return ostr.str();
381}
382
384{
385 constexpr auto kAbbreviatedMethodArgumentsLength{15};
386
387 std::ostringstream s;
389 const std::string template_params = s.str();
390
392 return fmt::format(
393 "{}{}(){}", name(), template_params, is_const() ? " const" : "");
394 }
396 return fmt::format("{}({}){}", name(),
398 fmt::format("{}", fmt::join(parameters(), ",")),
399 kAbbreviatedMethodArgumentsLength),
400 is_const() ? " const" : "");
401 }
402
403 return fmt::format("{}{}({}){}", name(), template_params,
404 fmt::join(parameters(), ","), is_const() ? " const" : "");
405}
406
407} // namespace clanguml::sequence_diagram::model