0.5.4
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-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 "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 default:
68 assert(false);
69 return "";
70 }
71}
72
74{
75 switch (a) {
77 return "public";
79 return "private";
80 default:
81 assert(false);
82 return "";
83 }
84}
85
86std::string to_string(message_t r)
87{
88 switch (r) {
90 return "call";
92 return "return";
93 case message_t::kIf:
94 return "if";
96 return "else";
98 return "else if";
100 return "end if";
102 return "while";
104 return "end while";
105 case message_t::kDo:
106 return "do";
108 return "end do";
109 case message_t::kFor:
110 return "for";
112 return "end for";
113 case message_t::kTry:
114 return "try";
116 return "catch";
118 return "end try";
120 return "switch";
121 case message_t::kCase:
122 return "case";
124 return "end switch";
126 return "conditional";
128 return "conditional else";
130 return "end conditional";
131 default:
132 assert(false);
133 return "";
134 }
135}
136
137std::string to_string(const diagram_t t)
138{
139 switch (t) {
141 return "class";
143 return "sequence";
145 return "package";
147 return "include";
148 default:
149 assert(false);
150 return "";
151 }
152}
153
154std::string to_string(const message_scope_t t)
155{
156 switch (t) {
158 return "normal";
160 return "condition";
161 default:
162 assert(false);
163 return "";
164 }
165}
166
167diagram_t from_string(const std::string &s)
168{
169 if (s == "class")
170 return diagram_t::kClass;
171 if (s == "sequence")
173 if (s == "include")
174 return diagram_t::kInclude;
175 if (s == "package")
176 return diagram_t::kPackage;
177
178 throw std::runtime_error{"Invalid diagram type: " + s};
179}
180
181} // namespace clanguml::common::model