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/mermaid/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_mermaid(relationship_t r)
23{
24 switch (r) {
25 case relationship_t::kOwnership:
26 case relationship_t::kComposition:
27 return "*--";
28 case relationship_t::kAggregation:
29 return "o--";
30 case relationship_t::kContainment:
31 return "()--";
32 case relationship_t::kAssociation:
33 return "-->";
34 case relationship_t::kInstantiation:
35 return "..|>";
36 case relationship_t::kFriendship:
37 return "<..";
38 case relationship_t::kDependency:
39 return "..>";
40 case relationship_t::kConstraint:
41 return "..>";
42 case relationship_t::kAlias:
43 return "..";
44 default:
45 return "";
46 }
47}
48
49std::string to_mermaid(access_t scope)
50{
51 switch (scope) {
52 case access_t::kPublic:
53 return "+";
54 case access_t::kProtected:
55 return "#";
56 case access_t::kPrivate:
57 return "-";
58 default:
59 return "";
60 }
61}
62
63std::string to_mermaid(message_t r)
64{
65 switch (r) {
66 case message_t::kCall:
67 return "->>";
68 case message_t::kReturn:
69 return "-->>";
70 default:
71 return "";
72 }
73}
74
75std::string indent(const unsigned level)
76{
77 const auto kIndentWidth = 4UL;
78 return std::string(level * kIndentWidth, ' '); // NOLINT
79}
80
81std::string render_name(std::string name)
82{
83 util::replace_all(name, "##", "::");
84
85 return name;
86}
87
88std::string escape_name(std::string name, bool round_brackets)
89{
90 util::replace_all(name, "<", "&lt;");
91 util::replace_all(name, ">", "&gt;");
92 if (round_brackets) {
93 util::replace_all(name, "(", "&lpar;");
94 util::replace_all(name, ")", "&rpar;");
95 }
96 util::replace_all(name, "{", "&lbrace;");
97 util::replace_all(name, "}", "&rbrace;");
98
99 return name;
100}
101} // namespace clanguml::common::generators::mermaid