0.5.4
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-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
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(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
99bool operator==(const class_ &l, const class_ &r) { return l.id() == r.id(); }
100
102 : participant{using_namespace}
103{
104}
105
106std::string function::full_name(bool relative) const
107{
108 return fmt::format("{}({}){}", participant::full_name(relative),
109 fmt::join(parameters_, ","), is_const() ? " const" : "");
110}
111
112std::string function::full_name_no_ns() const
113{
114 return fmt::format("{}({}){}", element::full_name_no_ns(),
115 fmt::join(parameters_, ","), is_const() ? " const" : "");
116}
117
119{
120 constexpr auto kAbbreviatedMethodArgumentsLength{15};
121
123 return fmt::format("{}(){}", name(), is_const() ? " const" : "");
124 }
126 return fmt::format("{}({}){}", name(),
128 fmt::format("{}", fmt::join(parameters_, ",")),
129 kAbbreviatedMethodArgumentsLength),
130 is_const() ? " const" : "");
131 }
132
133 return fmt::format("{}({}){}", name(), fmt::join(parameters_, ","),
134 is_const() ? " const" : "");
135}
136
137bool function::is_const() const { return is_const_; }
138
139void function::is_const(bool c) { is_const_ = c; }
140
141bool function::is_void() const { return is_void_; }
142
143void function::is_void(bool v) { is_void_ = v; }
144
145bool function::is_static() const { return is_static_; }
146
147void function::is_static(bool s) { is_static_ = s; }
148
149bool function::is_operator() const { return is_operator_; }
150
152
154
156
158
160
161void function::return_type(const std::string &rt) { return_type_ = rt; }
162
163const std::string &function::return_type() const { return return_type_; }
164
165void function::add_parameter(const std::string &a) { parameters_.push_back(a); }
166
167const std::vector<std::string> &function::parameters() const
168{
169 return parameters_;
170}
171
173 : function{using_namespace}
174{
175}
176
177std::string method::method_name() const { return method_name_; }
178
179std::string method::alias() const
180{
181 assert(class_id_.is_global());
182
183 return fmt::format("C_{:022}", class_id_.value());
184}
185
187
189
190bool method::is_defaulted() const { return is_defaulted_; }
191
193
194bool method::is_assignment() const { return is_assignment_; }
195
197
198void method::set_method_name(const std::string &name) { method_name_ = name; }
199
201
202void method::set_class_full_name(const std::string &name)
203{
205}
206
207const auto &method::class_full_name() const { return class_full_name_; }
208
209std::string method::full_name(bool relative) const
210{
211 if (relative)
212 return fmt::format("{}({}){}", method_name(),
213 fmt::join(parameters(), ","), is_const() ? " const" : "");
214
215 return fmt::format("{}::{}({}){}", class_full_name(), method_name(),
216 fmt::join(parameters(), ","), is_const() ? " const" : "");
217}
218
220{
221 constexpr auto kAbbreviatedMethodArgumentsLength{15};
222
223 const std::string style{};
224
226 return fmt::format("{}{}(){}{}", style, method_name(),
227 is_const() ? " const" : "", style);
228 }
230 return fmt::format("{}({}){}", name(),
232 fmt::format("{}", fmt::join(parameters(), ",")),
233 kAbbreviatedMethodArgumentsLength),
234 is_const() ? " const" : "");
235 }
236
237 return fmt::format("{}{}({}){}{}", style, method_name(),
238 fmt::join(parameters(), ","), is_const() ? " const" : "", style);
239}
240
242
243std::string method::to_string() const
244{
245 return fmt::format("Participant '{}': id={}, name={}, class_id={}",
246 type_name(), id(), full_name(false), class_id());
247}
248
250 const common::model::namespace_ &using_namespace)
251 : function{using_namespace}
252{
253}
254
255std::string function_template::full_name(bool relative) const
256{
257 using namespace clanguml::util;
259
260 std::ostringstream ostr;
261
262 ostr << name_and_ns();
263 render_template_params(ostr, using_namespace(), relative);
264
265 ostr << fmt::format(
266 "({}){}", fmt::join(parameters(), ","), is_const() ? " const" : "");
267
268 std::string res;
269
270 if (relative)
271 res = using_namespace().relative(ostr.str());
272 else
273 res = ostr.str();
274
275 if (res.empty())
276 return "<<anonymous>>";
277
278 return res;
279}
280
282{
283 using namespace clanguml::util;
284
285 std::ostringstream ostr;
286
287 ostr << name();
288
290
291 ostr << fmt::format(
292 "({}){}", fmt::join(parameters(), ","), is_const() ? " const" : "");
293
294 return ostr.str();
295}
296
298{
299 constexpr auto kAbbreviatedMethodArgumentsLength{15};
300
301 std::ostringstream s;
303 const std::string template_params = s.str();
304
306 return fmt::format(
307 "{}{}(){}", name(), template_params, is_const() ? " const" : "");
308 }
310 return fmt::format("{}({}){}", name(),
312 fmt::format("{}", fmt::join(parameters(), ",")),
313 kAbbreviatedMethodArgumentsLength),
314 is_const() ? " const" : "");
315 }
316
317 return fmt::format("{}{}({}){}", name(), template_params,
318 fmt::join(parameters(), ","), is_const() ? " const" : "");
319}
320
321} // namespace clanguml::sequence_diagram::model