0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
include_diagram_generator.cc
Go to the documentation of this file.
1/**
2 * @file src/include_diagram/generators/graphml/include_diagram_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
20
21#include "util/error.h"
22
24
27{
28}
29
30std::vector<std::pair<std::string, common::generators::graphml::property_type>>
32{
33 auto defaults =
35 defaults.emplace_back(
37 return defaults;
38}
39
40void generator::generate(const source_file &f, graphml_node_t &parent) const
41{
42 if (config().generate_packages && !config().generate_packages()) {
44 }
45 else {
46 generate_with_packages(f, parent);
47 }
48}
49
51 const source_file &f, graphml_node_t &parent) const
52{
53 auto display_name = f.full_name(false);
54#if defined(_MSC_VER)
55 util::replace_all(display_name, "\\", "/");
56#endif
57
59 LOG_DBG("Generating directory {}", f.name());
60
61 auto package_node =
62 make_subgraph(parent, f.alias(), f.name(), "folder");
63
64 generate_link(package_node, f);
65
66 auto graph_node = make_graph(package_node, f.alias());
67
68 util::for_each(f, [&, this](const auto &file) {
69 generate(dynamic_cast<const source_file &>(*file), graph_node);
70 });
71 }
72 else {
73 LOG_DBG("Generating file {}", f.name());
74
75 auto file_node = make_node(parent, node_ids_.add(f.alias()));
76 add_data(file_node, "type", "file");
77 add_cdata(file_node, "name", f.name());
78
80 add_data(file_node, "stereotype", "header");
81 if (f.is_system_header())
82 add_data(file_node, "is_system", "true");
83 }
84 else {
85 add_data(file_node, "stereotype", "source");
86 }
87
88 generate_link(file_node, f);
89 }
90}
91
93 const source_file &f, graphml_node_t &parent) const
94{
95 auto display_name = f.full_name(false);
96#if defined(_MSC_VER)
97 util::replace_all(display_name, "\\", "/");
98#endif
99
101 util::for_each(f, [&, this](const auto &file) {
102 generate(dynamic_cast<const source_file &>(*file), parent);
103 });
104 }
105 else {
106 LOG_DBG("Generating file {}", f.file_relative());
107
108 auto file_node = make_node(parent, node_ids_.add(f.alias()));
109 add_data(file_node, "type", "file");
110 add_cdata(file_node, "name", f.file_relative());
111
113 add_data(file_node, "stereotype", "header");
114 if (f.is_system_header())
115 add_data(file_node, "is_system", "true");
116 }
117 else {
118 add_data(file_node, "stereotype", "source");
119 }
120
121 generate_link(file_node, f);
122 }
123}
124
125void generator::generate_top_level_elements(graphml_node_t &parent) const
126{
127 // Generate files and folders
128 util::for_each(model(), [this, &parent](const auto &f) {
129 generate(dynamic_cast<source_file &>(*f), parent);
130 });
131}
132} // namespace clanguml::include_diagram::generators::graphml