0.6.0
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/json/generator.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
19#include "generator.h"
20
22
23std::string to_string(const property_type t)
24{
25 switch (t) {
27 return "boolean";
29 return "int";
31 return "long";
33 return "float";
35 return "double";
37 return "string";
38 default:
39 assert(false);
40 return "";
41 }
42}
43
45 : prefix_{std::move(prefix)}
46{
47}
48
49[[maybe_unused]] std::pair<std::string, property_type> property_keymap_t::add(
50 const std::string &name, const property_type pt)
51{
52 map_[name] = {fmt::format("{}{}", prefix_, next_data_key_id_++), pt};
53 return map_[name];
54}
55
56auto property_keymap_t::get(const std::string &name) const
57 -> std::optional<std::pair<std::string, property_type>>
58{
59 if (map_.count(name) == 0)
60 return {};
61
62 return map_.at(name);
63}
64
66 : prefix_{std::move(prefix)}
67{
68}
69
70[[maybe_unused]] std::string graphml_node_map_t::add(const std::string &name)
71{
72 map_[name] = fmt::format("{}{}", prefix_, next_node_id_++);
73 return map_[name];
74}
75
76std::optional<std::string> graphml_node_map_t::get(
77 const std::string &name) const
78{
79 if (map_.count(name) == 0)
80 return {};
81
82 return map_.at(name);
83}
84
85} // namespace clanguml::common::generators::graphml