0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
class_diagram_generator.h
Go to the documentation of this file.
1/**
2 * @file src/class_diagram/generators/json/class_diagram_generator.h
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#pragma once
19
28#include "config/config.h"
29#include "util/util.h"
30
31#include <glob/glob.hpp>
32#include <nlohmann/json.hpp>
33
34#include <filesystem>
35#include <fstream>
36#include <iostream>
37#include <sstream>
38
39namespace clanguml {
40namespace class_diagram {
41namespace generators {
42namespace json {
43
46template <typename C, typename D>
48
56
57using namespace clanguml::util;
58
59/**
60 * @brief Class diagram JSON generator
61 */
62class generator : public common_generator<diagram_config, diagram_model> {
63public:
65
67
68 /**
69 * @brief Main generator method.
70 *
71 * This method is called first and coordinates the entire diagram
72 * generation.
73 *
74 * @param ostr Output stream.
75 */
76 void generate_diagram(nlohmann::json &parent) const override;
77
78 /**
79 * Render class element into a JSON node.
80 *
81 * @param c class diagram element
82 * @param parent JSON node
83 */
84 void generate(const class_ &c, nlohmann::json &parent) const;
85
86 /**
87 * Render enum element into a JSON node.
88 *
89 * @param c enum diagram element
90 * @param parent JSON node
91 */
92 void generate(const enum_ &c, nlohmann::json &parent) const;
93
94 /**
95 * Render concept element into a JSON node.
96 *
97 * @param c concept diagram element
98 * @param parent JSON node
99 */
100 void generate(const concept_ &c, nlohmann::json &parent) const;
101
102 /**
103 * Render package element into a JSON node.
104 *
105 * @param p package diagram element
106 * @param parent JSON node
107 */
108 void generate(const package &p, nlohmann::json &parent) const;
109
110 /**
111 * @brief In a nested diagram, generate the top level elements.
112 *
113 * This method iterates over the top level elements. In case the diagram
114 * is nested (i.e. includes packages), for each package it recursively
115 * call generation of elements contained in each package.
116 *
117 * @param parent JSON node
118 */
119 void generate_top_level_elements(nlohmann::json &parent) const;
120
121 /**
122 * @brief Generate all relationships in the diagram.
123 *
124 * @param parent JSON node
125 */
126 void generate_relationships(nlohmann::json &parent) const;
127
128 /**
129 * @brief Generate all relationships originating at a class element.
130 *
131 * @param c Class diagram element
132 * @param parent JSON node
133 */
134 void generate_relationships(const class_ &c, nlohmann::json &parent) const;
135
136 /**
137 * @brief Generate all relationships originating at an enum element.
138 *
139 * @param c Enum diagram element
140 * @param parent JSON node
141 */
142 void generate_relationships(const enum_ &c, nlohmann::json &parent) const;
143
144 /**
145 * @brief Generate all relationships originating at a concept element.
146 *
147 * @param c Concept diagram element
148 * @param parent JSON node
149 */
151 const concept_ &c, nlohmann::json &parent) const;
152
153 /**
154 * @brief Generate all relationships in a package.
155 *
156 * If the diagram is nested, it recursively calls relationship generation
157 * for all subelements.
158 *
159 * @param p Package diagram element
160 * @param parent JSON node
161 */
162 void generate_relationships(const package &p, nlohmann::json &parent) const;
163};
164
165} // namespace json
166} // namespace generators
167} // namespace class_diagram
168} // namespace clanguml