0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
clanguml::package_diagram::generators::plantuml::generator Class Reference

Package diagram PlantUML generator. More...

Detailed Description

Package diagram PlantUML generator.

Definition at line 54 of file package_diagram_generator.h.

#include <package_diagram_generator.h>

Public Member Functions

 generator (diagram_config &config, diagram_model &model)
 
void generate_diagram (std::ostream &ostr) const override
 Main generator method.
 
void generate_relationships (const package &p, std::ostream &ostr) const
 Generate relationships originating from package p
 
void generate (const package &e, std::ostream &ostr) const
 Generate diagram package element.
 
void generate_groups (std::ostream &ostr) const
 Generate package elements grouped using together PlantUML tag.
 
- Public Member Functions inherited from clanguml::common::generators::plantuml::generator< ConfigType, DiagramType >
 generator (ConfigType &config, DiagramType &model)
 Constructor.
 
 ~generator () override=default
 
void generate (std::ostream &ostr) const override
 Generate diagram.
 
virtual void generate_diagram (std::ostream &ostr) const =0
 Generate diagram specific part.
 
void generate_config_layout_hints (std::ostream &ostr) const
 Generate diagram layout hints.
 
void generate_plantuml_directives (std::ostream &ostr, const std::vector< std::string > &directives) const
 Generate PlantUML directives from config file.
 
void generate_notes (std::ostream &ostr, const model::element &element) const
 Generate diagram notes.
 
void generate_style (std::ostream &ostr, const std::string &element_type, const model::stylable_element &el) const
 Generate diagram element PlantUML style.
 
void generate_metadata (std::ostream &ostr) const
 Generate comment with diagram metadata.
 
void generate_title (std::ostream &ostr) const
 Generate diagram title.
 
template<typename E >
void generate_link (std::ostream &ostr, const E &e) const
 Generate hyper link to element.
 
void generate_link (std::ostream &ostr, const relationship &e) const
 generate_link specialization for relationship
 
void print_debug (const common::model::source_location &e, std::ostream &ostr) const
 Print debug information in diagram comments.
 
- Public Member Functions inherited from clanguml::common::generators::generator< ConfigType, DiagramType >
 generator (ConfigType &config, DiagramType &model)
 Constructor.
 
virtual ~generator ()=default
 
virtual void generate (std::ostream &ostr) const =0
 Generate diagram.
 
const ConfigType & config () const
 Get reference to diagram config.
 
const DiagramType & model () const
 Get reference to diagram model.
 
std::optional< std::pair< std::string, std::string > > get_link_pattern (const common::model::source_location &sl) const
 
std::optional< std::pair< std::string, std::string > > get_tooltip_pattern (const common::model::source_location &sl) const
 
std::optional< std::string > render_link (const common::model::diagram_element &e) const
 
std::optional< std::string > render_link (const common::model::relationship &e) const
 
std::optional< std::string > render_tooltip (const common::model::diagram_element &e) const
 
std::optional< std::string > render_tooltip (const common::model::relationship &e) const
 
void init_context ()
 Initialize diagram Jinja context.
 
void update_context () const
 Update diagram Jinja context.
 
void init_env ()
 
const inja::json & context () const
 
inja::Environment & env () const
 

Private Attributes

common::generators::nested_element_stack< common::model::packagetogether_group_stack_
 

Additional Inherited Members

- Protected Attributes inherited from clanguml::common::generators::plantuml::generator< ConfigType, DiagramType >
std::set< std::string > m_generated_aliases
 
- Protected Attributes inherited from clanguml::common::generators::generator< ConfigType, DiagramType >
inja::json m_context
 
inja::Environment m_env
 

Constructor & Destructor Documentation

◆ generator()

clanguml::package_diagram::generators::plantuml::generator::generator ( diagram_config config,
diagram_model model 
)

Definition at line 27 of file package_diagram_generator.cc.

28 : common_generator<diagram_config, diagram_model>{config, model}
30{
31}

Member Function Documentation

◆ generate()

void clanguml::package_diagram::generators::plantuml::generator::generate ( const package e,
std::ostream &  ostr 
) const

Generate diagram package element.

Parameters
pPackage diagram element
parentOutput stream

Definition at line 76 of file package_diagram_generator.cc.

77{
79
80 LOG_DBG("Generating package {}", p.name());
81
83
84 const auto &uns = config().using_namespace();
85
86 // Don't generate packages from namespaces filtered out by
87 // using_namespace
88 if (!uns.starts_with({p.full_name(false)})) {
89 print_debug(p, ostr);
90
91 ostr << "package [" << display_name_adapter(p).with_packages().name()
92 << "] ";
93 ostr << "as " << p.alias();
94
95 if (p.is_deprecated())
96 ostr << " <<deprecated>>";
97
98 if (config().generate_links) {
99 generate_link(ostr, p);
100 }
101
102 generate_style(ostr, p.type_name(), p);
103
104 ostr << " {" << '\n';
105 }
106
107 for (const auto &subpackage : p) {
108 auto &pkg = dynamic_cast<package &>(*subpackage);
109 auto together_group = config().get_together_group(pkg.full_name(false));
110 if (together_group) {
111 together_group_stack_.group_together(together_group.value(), &pkg);
112 }
113 else {
114 generate(pkg, ostr);
115 }
116 }
117
118 generate_groups(ostr);
119
120 if (!uns.starts_with({p.full_name(false)})) {
121 ostr << "}" << '\n';
122 }
123
124 generate_notes(ostr, p);
125
126 together_group_stack_.leave();
127}

◆ generate_diagram()

void clanguml::package_diagram::generators::plantuml::generator::generate_diagram ( std::ostream &  ostr) const
overridevirtual

Main generator method.

This method is called first and coordinates the entire diagram generation.

Parameters
ostrOutput stream.

Implements clanguml::common::generators::plantuml::generator< ConfigType, DiagramType >.

Definition at line 143 of file package_diagram_generator.cc.

144{
145 for (const auto &p : model()) {
146 auto &pkg = dynamic_cast<package &>(*p);
147 auto together_group = config().get_together_group(pkg.full_name(false));
148 if (together_group) {
149 together_group_stack_.group_together(together_group.value(), &pkg);
150 }
151 else {
152 generate(pkg, ostr);
153 }
154 }
155
156 generate_groups(ostr);
157
158 // Process package relationships
159 for (const auto &p : model()) {
160 generate_relationships(dynamic_cast<package &>(*p), ostr);
161 }
162
164}

◆ generate_groups()

void clanguml::package_diagram::generators::plantuml::generator::generate_groups ( std::ostream &  ostr) const

Generate package elements grouped using together PlantUML tag.

Parameters
ostrOutput stream

Definition at line 129 of file package_diagram_generator.cc.

130{
131 for (const auto &[group_name, group_elements] :
132 together_group_stack_.get_current_groups()) {
133 ostr << "together {\n";
134
135 for (auto *pkg : group_elements) {
136 generate(*pkg, ostr);
137 }
138
139 ostr << "}\n";
140 }
141}

◆ generate_relationships()

void clanguml::package_diagram::generators::plantuml::generator::generate_relationships ( const package p,
std::ostream &  ostr 
) const

Generate relationships originating from package p

Parameters
pDiagram element
parentOutput stream

Definition at line 33 of file package_diagram_generator.cc.

35{
36 LOG_DBG("Generating relationships for package {}", p.full_name(true));
37
38 // Generate this packages relationship
39 if (model().should_include(relationship_t::kDependency)) {
40 for (const auto &r : p.relationships()) {
41 std::stringstream relstr;
42 try {
43 auto destination_package = model().get(r.destination());
44 if (!destination_package)
45 continue;
46
47 auto destination_alias = model().to_alias(r.destination());
48
49 if (!destination_alias.empty()) {
50 print_debug(r, ostr);
51 relstr << p.alias() << " ..> " << destination_alias;
52
53 if (config().generate_links) {
54 generate_link(relstr, r);
55 }
56
57 relstr << '\n';
58 ostr << relstr.str();
59 }
60 }
61 catch (error::uml_alias_missing &e) {
62 LOG_DBG("=== Skipping dependency relation from {} to {} due "
63 "to: {}",
64 p.full_name(false), r.destination(), e.what());
65 }
66 }
67 }
68
69 // Process it's subpackages relationships
70 for (const auto &subpackage : p) {
72 dynamic_cast<const package &>(*subpackage), ostr);
73 }
74}

Member Data Documentation

◆ together_group_stack_

common::generators::nested_element_stack<common::model::package> clanguml::package_diagram::generators::plantuml::generator::together_group_stack_
mutableprivate

Definition at line 95 of file package_diagram_generator.h.


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