0.6.1
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
enums.cc
Go to the documentation of this file.
1/**
2 * @file src/common/model/enums.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#include "enums.h"
19
20#include <cassert>
21#include <stdexcept>
22
24
26{
27 return t == message_t::kReturn || t == message_t::kCoReturn ||
29}
30
32{
33 switch (r) {
35 return "none";
37 return "extension";
39 return "composition";
41 return "aggregation";
43 return "containment";
45 return "ownership";
47 return "association";
49 return "instantiation";
51 return "friendship";
53 return "dependency";
55 return "alias";
57 return "constraint";
58 default:
59 assert(false);
60 return "";
61 }
62}
63
64std::string to_string(access_t a)
65{
66 switch (a) {
68 return "public";
70 return "protected";
72 return "private";
73 case access_t::kNone:
74 return "none";
75 default:
76 assert(false);
77 return "";
78 }
79}
80
82{
83 switch (a) {
85 return "public";
87 return "private";
88 default:
89 assert(false);
90 return "";
91 }
92}
93
94std::string to_string(message_t r)
95{
96 switch (r) {
98 return "call";
100 return "return";
101 case message_t::kIf:
102 return "if";
103 case message_t::kElse:
104 return "else";
106 return "else if";
108 return "end if";
110 return "while";
112 return "end while";
113 case message_t::kDo:
114 return "do";
116 return "end do";
117 case message_t::kFor:
118 return "for";
120 return "end for";
121 case message_t::kTry:
122 return "try";
124 return "catch";
126 return "end try";
128 return "switch";
129 case message_t::kCase:
130 return "case";
132 return "end switch";
134 return "conditional";
136 return "conditional else";
138 return "end conditional";
140 return "co_return";
142 return "co_yield";
144 return "co_await";
145 default:
146 assert(false);
147 return "";
148 }
149}
150
151std::string to_string(const diagram_t t)
152{
153 switch (t) {
155 return "class";
157 return "sequence";
159 return "package";
161 return "include";
162 default:
163 assert(false);
164 return "";
165 }
166}
167
168std::string to_string(const message_scope_t t)
169{
170 switch (t) {
172 return "normal";
174 return "condition";
175 default:
176 assert(false);
177 return "";
178 }
179}
180
181diagram_t from_string(const std::string &s)
182{
183 if (s == "class")
184 return diagram_t::kClass;
185 if (s == "sequence")
187 if (s == "include")
188 return diagram_t::kInclude;
189 if (s == "package")
190 return diagram_t::kPackage;
191
192 throw std::runtime_error{"Invalid diagram type: " + s};
193}
194
195} // namespace clanguml::common::model