0.6.0
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 switch (r) {
29 return "none";
31 return "extension";
33 return "composition";
35 return "aggregation";
37 return "containment";
39 return "ownership";
41 return "association";
43 return "instantiation";
45 return "friendship";
47 return "dependency";
49 return "alias";
51 return "constraint";
52 default:
53 assert(false);
54 return "";
55 }
56}
57
58std::string to_string(access_t a)
59{
60 switch (a) {
62 return "public";
64 return "protected";
66 return "private";
67 case access_t::kNone:
68 return "none";
69 default:
70 assert(false);
71 return "";
72 }
73}
74
76{
77 switch (a) {
79 return "public";
81 return "private";
82 default:
83 assert(false);
84 return "";
85 }
86}
87
88std::string to_string(message_t r)
89{
90 switch (r) {
92 return "call";
94 return "return";
95 case message_t::kIf:
96 return "if";
98 return "else";
100 return "else if";
102 return "end if";
104 return "while";
106 return "end while";
107 case message_t::kDo:
108 return "do";
110 return "end do";
111 case message_t::kFor:
112 return "for";
114 return "end for";
115 case message_t::kTry:
116 return "try";
118 return "catch";
120 return "end try";
122 return "switch";
123 case message_t::kCase:
124 return "case";
126 return "end switch";
128 return "conditional";
130 return "conditional else";
132 return "end conditional";
133 default:
134 assert(false);
135 return "";
136 }
137}
138
139std::string to_string(const diagram_t t)
140{
141 switch (t) {
143 return "class";
145 return "sequence";
147 return "package";
149 return "include";
150 default:
151 assert(false);
152 return "";
153 }
154}
155
156std::string to_string(const message_scope_t t)
157{
158 switch (t) {
160 return "normal";
162 return "condition";
163 default:
164 assert(false);
165 return "";
166 }
167}
168
169diagram_t from_string(const std::string &s)
170{
171 if (s == "class")
172 return diagram_t::kClass;
173 if (s == "sequence")
175 if (s == "include")
176 return diagram_t::kInclude;
177 if (s == "package")
178 return diagram_t::kPackage;
179
180 throw std::runtime_error{"Invalid diagram type: " + s};
181}
182
183} // namespace clanguml::common::model