0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
yaml_emitters.cc
Go to the documentation of this file.
1/**
2 * @file src/config/yaml_emitters.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 "config.h"
20
21namespace clanguml::common {
22
23YAML::Emitter &operator<<(YAML::Emitter &out, const string_or_regex &m)
24{
25 if (std::holds_alternative<std::string>(m.value())) {
26 out << std::get<std::string>(m.value());
27 }
28 else {
29 out << YAML::BeginMap;
30 out << YAML::Key << "r" << YAML::Value
31 << std::get<regex>(m.value()).pattern;
32 out << YAML::EndMap;
33 }
34
35 return out;
36}
37
38YAML::Emitter &operator<<(YAML::Emitter &out, const namespace_or_regex &m)
39{
40 if (std::holds_alternative<common::model::namespace_>(m.value())) {
41 out << std::get<common::model::namespace_>(m.value());
42 }
43 else {
44 out << YAML::BeginMap;
45 out << YAML::Key << "r" << YAML::Value
46 << std::get<regex>(m.value()).pattern;
47 out << YAML::EndMap;
48 }
49
50 return out;
51}
52
53namespace model {
54YAML::Emitter &operator<<(YAML::Emitter &out, const namespace_ &n)
55{
56 out << n.to_string();
57 return out;
58}
59
60YAML::Emitter &operator<<(YAML::Emitter &out, const relationship_t &r)
61{
62 out << to_string(r);
63 return out;
64}
65
66YAML::Emitter &operator<<(YAML::Emitter &out, const access_t &a)
67{
68 out << to_string(a);
69 return out;
70}
71
72YAML::Emitter &operator<<(YAML::Emitter &out, const module_access_t &a)
73{
74 out << to_string(a);
75 return out;
76}
77
78YAML::Emitter &operator<<(YAML::Emitter &out, const diagram_t &d)
79{
80 out << to_string(d);
81 return out;
82}
83
84} // namespace model
85} // namespace clanguml::common
86
87namespace clanguml::config {
88
89YAML::Emitter &operator<<(YAML::Emitter &out, const method_type &m)
90{
91 out << to_string(m);
92 return out;
93}
94
95YAML::Emitter &operator<<(YAML::Emitter &out, const callee_type &m)
96{
97 out << to_string(m);
98 return out;
99}
100
101YAML::Emitter &operator<<(YAML::Emitter &out, const member_order_t &r)
102{
103 out << to_string(r);
104 return out;
105}
106
107YAML::Emitter &operator<<(YAML::Emitter &out, const package_type_t &r)
108{
109 out << to_string(r);
110 return out;
111}
112
113YAML::Emitter &operator<<(YAML::Emitter &out, const context_config &c)
114{
115 out << YAML::BeginMap;
116 out << YAML::Key << "match";
117 out << YAML::BeginMap;
118 out << YAML::Key << "radius" << YAML::Value << c.radius;
119 out << YAML::Key << "pattern" << YAML::Value << c.pattern;
120 out << YAML::EndMap;
121 out << YAML::EndMap;
122
123 return out;
124}
125
126YAML::Emitter &operator<<(YAML::Emitter &out, const filter &f)
127{
128 out << YAML::BeginMap;
129 if (!f.namespaces.empty())
130 out << YAML::Key << "namespaces" << YAML::Value << f.namespaces;
131 if (!f.modules.empty())
132 out << YAML::Key << "modules" << YAML::Value << f.modules;
133 if (!f.module_access.empty())
134 out << YAML::Key << "module_access" << YAML::Value << f.module_access;
135 if (!f.access.empty())
136 out << YAML::Key << "access" << YAML::Value << f.access;
137 if (!f.context.empty())
138 out << YAML::Key << "context" << YAML::Value << f.context;
139 if (!f.dependants.empty())
140 out << YAML::Key << "dependants" << YAML::Value << f.dependants;
141 if (!f.dependencies.empty())
142 out << YAML::Key << "dependencies" << YAML::Value << f.dependencies;
143 if (!f.elements.empty())
144 out << YAML::Key << "elements" << YAML::Value << f.elements;
145 if (!f.element_types.empty())
146 out << YAML::Key << "element_types" << YAML::Value << f.element_types;
147 if (!f.method_types.empty())
148 out << YAML::Key << "method_types" << YAML::Value << f.method_types;
149 if (!f.paths.empty())
150 out << YAML::Key << "paths" << YAML::Value << f.paths;
151 if (!f.relationships.empty())
152 out << YAML::Key << "relationships" << YAML::Value << f.relationships;
153 if (!f.specializations.empty())
154 out << YAML::Key << "specializations" << YAML::Value
155 << f.specializations;
156 if (!f.subclasses.empty())
157 out << YAML::Key << "subclasses" << YAML::Value << f.subclasses;
158 if (!f.parents.empty())
159 out << YAML::Key << "parents" << YAML::Value << f.parents;
160 if (!f.method_types.empty())
161 out << YAML::Key << "callee_types" << YAML::Value << f.callee_types;
162 out << YAML::EndMap;
163 return out;
164}
165
166YAML::Emitter &operator<<(YAML::Emitter &out, const plantuml &p)
167{
168 if (p.before.empty() && p.after.empty())
169 return out;
170
171 out << YAML::BeginMap;
172 if (!p.before.empty())
173 out << YAML::Key << "before" << YAML::Value << p.before;
174 if (!p.after.empty())
175 out << YAML::Key << "after" << YAML::Value << p.after;
176 out << YAML::EndMap;
177
178 return out;
179}
180
181YAML::Emitter &operator<<(YAML::Emitter &out, const method_arguments &ma)
182{
183 out << to_string(ma);
184 return out;
185}
186
187YAML::Emitter &operator<<(YAML::Emitter &out, const generate_links_config &glc)
188{
189 out << YAML::BeginMap;
190 out << YAML::Key << "link" << YAML::Value << glc.link;
191 out << YAML::Key << "tooltip" << YAML::Value << glc.tooltip;
192 out << YAML::EndMap;
193 return out;
194}
195
196YAML::Emitter &operator<<(YAML::Emitter &out, const git_config &gc)
197{
198 out << YAML::BeginMap;
199 out << YAML::Key << "branch" << YAML::Value << gc.branch;
200 out << YAML::Key << "revision" << YAML::Value << gc.revision;
201 out << YAML::Key << "commit" << YAML::Value << gc.commit;
202 out << YAML::Key << "toplevel" << YAML::Value << gc.toplevel;
203 out << YAML::EndMap;
204
205 return out;
206}
207
208YAML::Emitter &operator<<(YAML::Emitter &out, const relationship_hint_t &rh)
209{
210 out << YAML::BeginMap;
211 out << YAML::Key << "default" << YAML::Value << rh.default_hint;
212 for (const auto &[k, v] : rh.argument_hints)
213 out << YAML::Key << k << YAML::Value << v;
214 out << YAML::EndMap;
215 return out;
216}
217
218YAML::Emitter &operator<<(YAML::Emitter &out, const hint_t &h)
219{
220 out << to_string(h);
221 return out;
222}
223
224YAML::Emitter &operator<<(YAML::Emitter &out, const comment_parser_t &cp)
225{
226 out << to_string(cp);
227 return out;
228}
229
230#ifdef _MSC_VER
231YAML::Emitter &operator<<(YAML::Emitter &out, const std::filesystem::path &p)
232{
233 out << p.string();
234 return out;
235}
236
237YAML::Emitter &operator<<(
238 YAML::Emitter &out, const std::vector<std::filesystem::path> &paths)
239{
240 out << YAML::BeginSeq;
241 for (const auto &p : paths)
242 out << p;
243 out << YAML::EndSeq;
244 return out;
245}
246#endif
247
248YAML::Emitter &operator<<(YAML::Emitter &out, const layout_hint &c)
249{
250 out << YAML::BeginMap;
251
252 out << YAML::Key << c.hint << YAML::Value;
253 if (std::holds_alternative<std::string>(c.entity))
254 out << std::get<std::string>(c.entity);
255 else if (std::holds_alternative<std::vector<std::string>>(c.entity))
256 out << std::get<std::vector<std::string>>(c.entity);
257
258 out << YAML::EndMap;
259 return out;
260}
261
262YAML::Emitter &operator<<(YAML::Emitter &out, const source_location &sc)
263{
264 out << YAML::BeginMap;
265 out << YAML::Key << to_string(sc.location_type) << YAML::Value
266 << sc.location;
267 out << YAML::EndMap;
268 return out;
269}
270
271YAML::Emitter &operator<<(YAML::Emitter &out, const config &c)
272{
273 out << YAML::BeginMap;
274
276 out << c.output_directory;
277 out << c.query_driver;
278 out << c.add_compile_flags;
279 out << c.remove_compile_flags;
280
281 out << dynamic_cast<const inheritable_diagram_options &>(c);
282
283 out << YAML::Key << "diagrams";
284 out << YAML::BeginMap;
285
286 for (const auto &[k, v] : c.diagrams) {
287 out << YAML::Key << k;
288 if (v->type() == common::model::diagram_t::kClass) {
289 out << YAML::Value << dynamic_cast<class_diagram &>(*v);
290 }
291 else if (v->type() == common::model::diagram_t::kSequence) {
292 out << YAML::Value << dynamic_cast<sequence_diagram &>(*v);
293 }
294 else if (v->type() == common::model::diagram_t::kInclude) {
295 out << YAML::Value << dynamic_cast<include_diagram &>(*v);
296 }
297 else if (v->type() == common::model::diagram_t::kPackage) {
298 out << YAML::Value << dynamic_cast<package_diagram &>(*v);
299 }
300 }
301
302 out << YAML::EndMap;
303 out << YAML::EndMap;
304 return out;
305}
306
307YAML::Emitter &operator<<(
308 YAML::Emitter &out, const inheritable_diagram_options &c)
309{
310 // Common options
311 out << c.base_directory;
312 out << c.comment_parser;
313 out << c.debug_mode;
314 out << c.exclude;
315 out << c.generate_links;
316 out << c.git;
317 out << c.glob;
318 out << c.include;
319 out << c.puml;
320 out << c.relative_to;
321 out << c.using_namespace;
322 out << c.using_module;
323 out << c.generate_metadata;
324
325 if (const auto *cd = dynamic_cast<const class_diagram *>(&c);
326 cd != nullptr) {
327 out << cd->title;
330 out << c.generate_packages;
332 if (c.relationship_hints) {
333 out << YAML::Key << "relationship_hints" << YAML::Value
334 << c.relationship_hints();
335 }
336
337 if (c.type_aliases) {
338 out << YAML::Key << "type_aliases" << YAML::Value
339 << c.type_aliases();
340 }
341 out << c.member_order;
342 out << c.package_type;
345 }
346 else if (const auto *sd = dynamic_cast<const sequence_diagram *>(&c);
347 sd != nullptr) {
348 out << sd->title;
350 out << c.inline_lambda_messages;
353 out << c.generate_return_types;
354 out << c.participants_order;
356 out << c.message_comment_width;
357 }
358 else if (const auto *pd = dynamic_cast<const package_diagram *>(&c);
359 pd != nullptr) {
360 out << pd->title;
361 out << c.generate_packages;
362 out << c.package_type;
363 }
364 else if (const auto *id = dynamic_cast<const include_diagram *>(&c);
365 id != nullptr) {
366 out << id->title;
368 }
369
370 return out;
371}
372
373YAML::Emitter &operator<<(YAML::Emitter &out, const class_diagram &c)
374{
375 out << YAML::BeginMap;
376 out << YAML::Key << "type" << YAML::Value << c.type();
377 out << c.layout;
378 out << dynamic_cast<const inheritable_diagram_options &>(c);
379 out << YAML::EndMap;
380 return out;
381}
382
383YAML::Emitter &operator<<(YAML::Emitter &out, const sequence_diagram &c)
384{
385 out << YAML::BeginMap;
386 out << YAML::Key << "type" << YAML::Value << c.type();
387 out << c.from;
388 out << c.from_to;
389 out << c.to;
390 out << dynamic_cast<const inheritable_diagram_options &>(c);
391 out << YAML::EndMap;
392 return out;
393}
394
395YAML::Emitter &operator<<(YAML::Emitter &out, const include_diagram &c)
396{
397 out << YAML::BeginMap;
398 out << YAML::Key << "type" << YAML::Value << c.type();
399 out << c.layout;
400 out << dynamic_cast<const inheritable_diagram_options &>(c);
401 out << YAML::EndMap;
402 return out;
403}
404
405YAML::Emitter &operator<<(YAML::Emitter &out, const package_diagram &c)
406{
407 out << YAML::BeginMap;
408 out << YAML::Key << "type" << YAML::Value << c.type();
409 out << c.layout;
410 out << dynamic_cast<const inheritable_diagram_options &>(c);
411 out << YAML::EndMap;
412 return out;
413}
414
415} // namespace clanguml::config