0.6.0
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/mermaid/class_diagram_generator.h
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#pragma once
19
30#include "config/config.h"
31#include "util/util.h"
32
33#include <glob/glob.hpp>
34
35#include <filesystem>
36#include <fstream>
37#include <iostream>
38#include <sstream>
39
41
44template <typename C, typename D>
46
60
61using namespace clanguml::util;
62
63/**
64 * @brief Class diagram MermaidJS generator
65 */
67 : public common_generator<diagram_config, diagram_model>,
69
70public:
72
74
75 /**
76 * @brief Main generator method.
77 *
78 * This method is called first and coordinates the entire diagram
79 * generation.
80 *
81 * @param ostr Output stream.
82 */
83 void generate_diagram(std::ostream &ostr) const override;
84
85 /**
86 * @brief Generate the diagram type
87 *
88 * @param ostr Output stream
89 */
90 void generate_diagram_type(std::ostream &ostr) const override;
91
92 /**
93 * @brief Generate MermaidJS alias for a class element.
94 *
95 * @param c Class element
96 * @param ostr Output stream
97 */
98 void generate_alias(
99 const common::model::element &e, std::ostream &ostr) const;
100
101 /**
102 * @brief Render class element to MermaidJS
103 *
104 * @param c Class element
105 * @param ostr Output stream
106 */
107 void generate(const class_ &c, std::ostream &ostr) const;
108
109 /**
110 * @brief Render class methods to MermaidJS
111 *
112 * @param methods List of class methods
113 * @param ostr Output stream
114 */
115 void generate_methods(
116 const std::vector<class_method> &methods, std::ostream &ostr) const;
117
118 void generate_methods(
119 const std::vector<objc_method> &methods, std::ostream &ostr) const;
120
121 void start_method_group(std::ostream &ostr) const;
122
123 /**
124 * @brief Render class method to MermaidJS
125 *
126 * @param m Class method
127 * @param ostr Output stream
128 */
129 void generate_method(const class_method &m, std::ostream &ostr) const;
130
131 void generate_method(const objc_method &m, std::ostream &ostr) const;
132
133 /**
134 * @brief Render class member to MermaidJS
135 *
136 * @param m Class member
137 * @param ostr Output stream
138 */
139 void generate_member(const class_member &m, std::ostream &ostr) const;
140
141 void generate_member(const objc_member &m, std::ostream &ostr) const;
142
143 /**
144 * @brief Render all relationships originating from class element.
145 *
146 * @param c Class element
147 * @param ostr Output stream
148 */
149 void generate_relationships(const class_ &c, std::ostream &ostr) const;
150
151 /**
152 * @brief Render a specific relationship to MermaidJS.
153 *
154 * @param r Relationship model
155 * @param rendered_relations Set of already rendered relationships, to
156 * ensure that there are no duplicate
157 * relationships
158 */
160 const relationship &r, std::set<std::string> &rendered_relations) const;
161
162 /**
163 * @brief Render enum element to MermaidJS
164 *
165 * @param e Enum element
166 * @param ostr Output stream
167 */
168 void generate(const enum_ &e, std::ostream &ostr) const;
169
170 /**
171 * @brief Render all relationships originating from enum element.
172 *
173 * @param c Enum element
174 * @param ostr Output stream
175 */
176 void generate_relationships(const enum_ &c, std::ostream &ostr) const;
177
178 /**
179 * @brief Render concept element to MermaidJS
180 *
181 * @param c Concept element
182 * @param ostr Output stream
183 */
184 void generate(const concept_ &c, std::ostream &ostr) const;
185
186 /**
187 * @brief Render all relationships originating from ObjC class element.
188 *
189 * @param c Concept element
190 * @param ostr Output stream
191 */
192 void generate_relationships(const concept_ &c, std::ostream &ostr) const;
193
194 void generate(const objc_interface &c, std::ostream &ostr) const;
195
196 /**
197 * @brief Render all relationships originating from ObjC class element.
198 *
199 * @param c Concept element
200 * @param ostr Output stream
201 */
203 const objc_interface &c, std::ostream &ostr) const;
204
207
208 /**
209 * @brief Generate any notes attached specifically to some class element.
210 *
211 * @param ostream Output stream
212 * @param member Class element (member or method)
213 * @param alias MermaidJS class alias
214 */
215 void generate_member_notes(std::ostream &ostream,
216 const class_element &member, const std::string &alias) const;
217
219 const std::string &group_name, std::ostream &ostr) const;
220
222 const std::string &group_name, std::ostream &ostr) const;
223
224 void start_package(const package &p, std::ostream &ostr) const;
225
226 void end_package(const package &p, std::ostream &ostr) const;
227};
228
229} // namespace clanguml::class_diagram::generators::mermaid