0.6.0
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
175void function::return_type(const std::string &rt) { return_type_ = rt; }
176
177const std::string &function::return_type() const { return return_type_; }
178
179void function::add_parameter(const std::string &a) { parameters_.push_back(a); }
180
181const std::vector<std::string> &function::parameters() const
182{
183 return parameters_;
184}
185
187 : function{using_namespace}
188{
189}
190
191std::string objc_method::method_name() const { return method_name_; }
192
193std::string objc_method::alias() const
194{
195 assert(class_id_.is_global());
196
197 return fmt::format("C_{:022}", class_id_.value());
198}
199
200void objc_method::set_method_name(const std::string &name)
201{
203}
204
206
207void objc_method::set_class_full_name(const std::string &name)
208{
210}
211
212const auto &objc_method::class_full_name() const { return class_full_name_; }
213
214std::string objc_method::full_name_impl(bool relative) const
215{
216 if (relative)
217 return fmt::format("{}({}){}", method_name(),
218 fmt::join(parameters(), ","), is_const() ? " const" : "");
219
220 return fmt::format("{}::{}({}){}", class_full_name(), method_name(),
221 fmt::join(parameters(), ","), is_const() ? " const" : "");
222}
223
225{
226 constexpr auto kAbbreviatedMethodArgumentsLength{15};
227
228 const std::string style{};
229
231 return fmt::format("{}{}(){}{}", style, method_name(),
232 is_const() ? " const" : "", style);
233 }
235 return fmt::format("{}({}){}", name(),
237 fmt::format("{}", fmt::join(parameters(), ",")),
238 kAbbreviatedMethodArgumentsLength),
239 is_const() ? " const" : "");
240 }
241
242 return fmt::format("{}{}({}){}{}", style, method_name(),
243 fmt::join(parameters(), ","), is_const() ? " const" : "", style);
244}
245
247
248std::string objc_method::to_string() const
249{
250 return fmt::format("Participant '{}': id={}, name={}, class_id={}",
251 type_name(), id(), full_name(false), class_id());
252}
253
255 : function{using_namespace}
256{
257}
258
259std::string method::method_name() const { return method_name_; }
260
261std::string method::alias() const
262{
263 assert(class_id_.is_global());
264
265 return fmt::format("C_{:022}", class_id_.value());
266}
267
269
271
272bool method::is_defaulted() const { return is_defaulted_; }
273
275
276bool method::is_assignment() const { return is_assignment_; }
277
279
280void method::set_method_name(const std::string &name) { method_name_ = name; }
281
283
284void method::set_class_full_name(const std::string &name)
285{
287}
288
289const auto &method::class_full_name() const { return class_full_name_; }
290
291std::string method::full_name_impl(bool relative) const
292{
293 if (relative)
294 return fmt::format("{}({}){}", method_name(),
295 fmt::join(parameters(), ","), is_const() ? " const" : "");
296
297 return fmt::format("{}::{}({}){}", class_full_name(), method_name(),
298 fmt::join(parameters(), ","), is_const() ? " const" : "");
299}
300
302{
303 constexpr auto kAbbreviatedMethodArgumentsLength{15};
304
305 const std::string style{};
306
308 return fmt::format("{}{}(){}{}", style, method_name(),
309 is_const() ? " const" : "", style);
310 }
312 return fmt::format("{}({}){}", name(),
314 fmt::format("{}", fmt::join(parameters(), ",")),
315 kAbbreviatedMethodArgumentsLength),
316 is_const() ? " const" : "");
317 }
318
319 return fmt::format("{}{}({}){}{}", style, method_name(),
320 fmt::join(parameters(), ","), is_const() ? " const" : "", style);
321}
322
324
325std::string method::to_string() const
326{
327 return fmt::format("Participant '{}': id={}, name={}, class_id={}",
328 type_name(), id(), full_name(false), class_id());
329}
330
332 const common::model::namespace_ &using_namespace)
333 : function{using_namespace}
334{
335}
336
337std::string function_template::full_name_impl(bool relative) const
338{
339 using namespace clanguml::util;
341
342 std::ostringstream ostr;
343
344 ostr << name_and_ns();
345 render_template_params(ostr, using_namespace(), relative);
346
347 ostr << fmt::format(
348 "({}){}", fmt::join(parameters(), ","), is_const() ? " const" : "");
349
350 std::string res;
351
352 if (relative)
353 res = using_namespace().relative(ostr.str());
354 else
355 res = ostr.str();
356
357 if (res.empty())
358 return "<<anonymous>>";
359
360 return res;
361}
362
364{
365 using namespace clanguml::util;
366
367 std::ostringstream ostr;
368
369 ostr << name();
370
372
373 ostr << fmt::format(
374 "({}){}", fmt::join(parameters(), ","), is_const() ? " const" : "");
375
376 return ostr.str();
377}
378
380{
381 constexpr auto kAbbreviatedMethodArgumentsLength{15};
382
383 std::ostringstream s;
385 const std::string template_params = s.str();
386
388 return fmt::format(
389 "{}{}(){}", name(), template_params, is_const() ? " const" : "");
390 }
392 return fmt::format("{}({}){}", name(),
394 fmt::format("{}", fmt::join(parameters(), ",")),
395 kAbbreviatedMethodArgumentsLength),
396 is_const() ? " const" : "");
397 }
398
399 return fmt::format("{}{}({}){}", name(), template_params,
400 fmt::join(parameters(), ","), is_const() ? " const" : "");
401}
402
403} // namespace clanguml::sequence_diagram::model