0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
clanguml::class_diagram::generators::text_diagram_strategy< G > Class Template Reference

Common methods for PlantUML and MermaidJS class diagrams. More...

Detailed Description

template<typename G>
class clanguml::class_diagram::generators::text_diagram_strategy< G >

Common methods for PlantUML and MermaidJS class diagrams.

Definition at line 43 of file text_diagram_strategy.h.

#include <text_diagram_strategy.h>

Public Types

using method_groups_t = std::map< std::string, std::vector< model::class_method > >
 

Public Member Functions

 text_diagram_strategy (G &generator, bool generate_packages)
 
void generate (const package &p, std::ostream &ostr) const
 
void generate_top_level_elements (std::ostream &ostr) const
 
void generate_relationships (const package &p, std::ostream &ostr) const
 
void generate_relationships (std::ostream &ostr) const
 
void generate_groups (std::ostream &ostr) const
 
template<typename T >
void sort_class_elements (std::vector< T > &elements) const
 
void generate_method_groups (const method_groups_t &methods, std::ostream &ostr) const
 
method_groups_t group_methods (const std::vector< model::class_method > &methods) const
 Group class methods based on method type.
 

Private Attributes

const std::vector< std::string > method_groups_
 
G & generator_
 
common::generators::nested_element_stack< common::model::elementtogether_group_stack_
 

Member Typedef Documentation

◆ method_groups_t

template<typename G >
using clanguml::class_diagram::generators::text_diagram_strategy< G >::method_groups_t = std::map<std::string, std::vector<model::class_method> >

Definition at line 45 of file text_diagram_strategy.h.

Constructor & Destructor Documentation

◆ text_diagram_strategy()

template<typename G >
clanguml::class_diagram::generators::text_diagram_strategy< G >::text_diagram_strategy ( G &  generator,
bool  generate_packages 
)
inline

Definition at line 48 of file text_diagram_strategy.h.

49 : generator_{generator}
50 , together_group_stack_{generate_packages}
51 {
52 }

Member Function Documentation

◆ generate()

template<typename G >
void clanguml::class_diagram::generators::text_diagram_strategy< G >::generate ( const package p,
std::ostream &  ostr 
) const
inline

Definition at line 54 of file text_diagram_strategy.h.

55 {
56 generator_.start_package(p, ostr);
57
58 for (const auto &subpackage : p) {
59 if (dynamic_cast<package *>(subpackage.get()) != nullptr) {
60 // TODO: add option - generate_empty_packages
61 const auto &sp = dynamic_cast<package &>(*subpackage);
62 if (!sp.is_empty()) {
64
65 generate(sp, ostr);
66
68 }
69 }
70 else {
71 generator_.model().dynamic_apply(
72 subpackage.get(), [&](auto *el) {
73 auto together_group =
74 generator_.config().get_together_group(
75 el->full_name(false));
76 if (together_group) {
77 together_group_stack_.group_together(
78 together_group.value(), el);
79 }
80 else {
81 generator_.generate_alias(*el, ostr);
82 generator_.generate(*el, ostr);
83 }
84 });
85 }
86
87 if (!together_group_stack_.is_flat()) {
88 generate_groups(ostr);
89 }
90 }
91
92 generator_.end_package(p, ostr);
93 }

◆ generate_groups()

template<typename G >
void clanguml::class_diagram::generators::text_diagram_strategy< G >::generate_groups ( std::ostream &  ostr) const
inline

Definition at line 156 of file text_diagram_strategy.h.

157 {
158 for (const auto &[group_name, group_elements] :
159 together_group_stack_.get_current_groups()) {
160
161 generator_.start_together_group(group_name, ostr);
162
163 for (auto *e : group_elements) {
164 generator_.model().dynamic_apply(e, [&](auto *el) {
165 generator_.generate_alias(*el, ostr);
166 generator_.generate(*el, ostr);
167 });
168 }
169
170 generator_.end_together_group(group_name, ostr);
171 }
172 }

◆ generate_method_groups()

template<typename G >
void clanguml::class_diagram::generators::text_diagram_strategy< G >::generate_method_groups ( const method_groups_t methods,
std::ostream &  ostr 
) const
inline

Definition at line 186 of file text_diagram_strategy.h.

188 {
189 bool is_first_non_empty_group{true};
190
191 for (const auto &group : method_groups_) {
192 const auto &group_methods = methods.at(group);
193 if (!group_methods.empty()) {
194 if (!is_first_non_empty_group)
195 generator_.start_method_group(ostr);
196 is_first_non_empty_group = false;
197 generator_.generate_methods(group_methods, ostr);
198 }
199 }
200 }

◆ generate_relationships() [1/2]

template<typename G >
void clanguml::class_diagram::generators::text_diagram_strategy< G >::generate_relationships ( const package p,
std::ostream &  ostr 
) const
inline

Definition at line 120 of file text_diagram_strategy.h.

121 {
122 for (const auto &subpackage : p) {
123 if (dynamic_cast<package *>(subpackage.get()) != nullptr) {
124 // TODO: add option - generate_empty_packages, currently
125 // packages which do not contain anything but other
126 // packages are skipped
127 const auto &sp = dynamic_cast<package &>(*subpackage);
128 if (!sp.is_empty())
129 generate_relationships(sp, ostr);
130 }
131 else {
132 generator_.model().dynamic_apply(
133 subpackage.get(), [&](auto *el) {
134 if (generator_.model().should_include(*el)) {
135 generator_.generate_relationships(*el, ostr);
136 }
137 });
138 }
139 }
140 }

◆ generate_relationships() [2/2]

template<typename G >
void clanguml::class_diagram::generators::text_diagram_strategy< G >::generate_relationships ( std::ostream &  ostr) const
inline

Definition at line 142 of file text_diagram_strategy.h.

143 {
144 for (const auto &p : generator_.model()) {
145 if (auto *pkg = dynamic_cast<package *>(p.get()); pkg) {
146 generate_relationships(*pkg, ostr);
147 }
148 else {
149 generator_.model().dynamic_apply(p.get(), [&](auto *el) {
150 generator_.generate_relationships(*el, ostr);
151 });
152 }
153 }
154 }

◆ generate_top_level_elements()

template<typename G >
void clanguml::class_diagram::generators::text_diagram_strategy< G >::generate_top_level_elements ( std::ostream &  ostr) const
inline

Definition at line 95 of file text_diagram_strategy.h.

96 {
97 for (const auto &p : generator_.model()) {
98 if (auto *pkg = dynamic_cast<package *>(p.get()); pkg) {
99 if (!pkg->is_empty())
100 generate(*pkg, ostr);
101 }
102 else {
103 generator_.model().dynamic_apply(p.get(), [&](auto *el) {
104 auto together_group =
105 generator_.config().get_together_group(
106 el->full_name(false));
107 if (together_group) {
108 together_group_stack_.group_together(
109 together_group.value(), el);
110 }
111 else {
112 generator_.generate_alias(*el, ostr);
113 generator_.generate(*el, ostr);
114 }
115 });
116 }
117 }
118 }

◆ group_methods()

template<typename G >
method_groups_t clanguml::class_diagram::generators::text_diagram_strategy< G >::group_methods ( const std::vector< model::class_method > &  methods) const
inline

Group class methods based on method type.

Parameters
methodsList of class methods.
Returns
Map of method groups.

Definition at line 209 of file text_diagram_strategy.h.

211 {
212 std::map<std::string, std::vector<model::class_method>> result;
213
214 for (const auto &g : method_groups_) {
215 result[g] = {};
216 }
217
218 for (const auto &m : methods) {
219 if (m.is_constructor() || m.is_destructor()) {
220 result["constructors"].push_back(m);
221 }
222 else if (m.is_copy_assignment() || m.is_move_assignment()) {
223 result["assignment"].push_back(m);
224 }
225 else if (m.is_operator()) {
226 result["operators"].push_back(m);
227 }
228 else {
229 result["other"].push_back(m);
230 }
231 }
232
233 return result;
234 }

◆ sort_class_elements()

template<typename G >
template<typename T >
void clanguml::class_diagram::generators::text_diagram_strategy< G >::sort_class_elements ( std::vector< T > &  elements) const
inline

Definition at line 175 of file text_diagram_strategy.h.

176 {
177 if (generator_.config().member_order() ==
179 std::sort(elements.begin(), elements.end(),
180 [](const auto &m1, const auto &m2) {
181 return m1.name() < m2.name();
182 });
183 }
184 }

Member Data Documentation

◆ generator_

template<typename G >
G& clanguml::class_diagram::generators::text_diagram_strategy< G >::generator_
private

Definition at line 240 of file text_diagram_strategy.h.

◆ method_groups_

template<typename G >
const std::vector<std::string> clanguml::class_diagram::generators::text_diagram_strategy< G >::method_groups_
private
Initial value:
{
"constructors", "assignment", "operators", "other"}

Definition at line 237 of file text_diagram_strategy.h.

◆ together_group_stack_

Definition at line 242 of file text_diagram_strategy.h.


The documentation for this class was generated from the following file: