0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
generator.cc
Go to the documentation of this file.
1/**
2 * @file src/common/generators/plantuml/generator.h
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#include "generator.h"
19
21
22std::string to_plantuml(const relationship &r, const config::diagram &cfg)
23{
25
26 std::string style;
27
28 const auto &inline_style = r.style();
29
30 if (inline_style && !inline_style.value().empty()) {
31 if (inline_style && inline_style.value().back() == ']')
32 style = *inline_style;
33 else
34 style = fmt::format("[{}]", inline_style.value());
35 }
36
37 if (style.empty() && cfg.puml) {
38 if (auto config_style = cfg.puml().get_style(r.type());
39 config_style.has_value()) {
40 style = config_style.value();
41 }
42 }
43
44 switch (r.type()) {
45 case relationship_t::kOwnership:
46 case relationship_t::kComposition:
47 return style.empty() ? "*--" : fmt::format("*-{}-", style);
48 case relationship_t::kAggregation:
49 return style.empty() ? "o--" : fmt::format("o-{}-", style);
50 case relationship_t::kContainment:
51 return style.empty() ? "--+" : fmt::format("-{}-+", style);
52 case relationship_t::kAssociation:
53 return style.empty() ? "-->" : fmt::format("-{}->", style);
54 case relationship_t::kInstantiation:
55 return style.empty() ? "..|>" : fmt::format(".{}.|>", style);
56 case relationship_t::kFriendship:
57 return style.empty() ? "<.." : fmt::format("<.{}.", style);
58 case relationship_t::kDependency:
59 return style.empty() ? "..>" : fmt::format(".{}.>", style);
60 case relationship_t::kConstraint:
61 return style.empty() ? "..>" : fmt::format(".{}.>", style);
62 case relationship_t::kAlias:
63 return style.empty() ? ".." : fmt::format(".{}.", style);
64 default:
65 return "";
66 }
67}
68
69std::string to_plantuml(access_t scope)
70{
71 switch (scope) {
72 case access_t::kPublic:
73 return "+";
74 case access_t::kProtected:
75 return "#";
76 case access_t::kPrivate:
77 return "-";
78 default:
79 return "";
80 }
81}
82
83std::string to_plantuml(message_t r)
84{
85 switch (r) {
86 case message_t::kCall:
87 return "->";
88 case message_t::kReturn:
89 return "-->";
90 default:
91 return "";
92 }
93}
94
95} // namespace clanguml::common::generators::plantuml