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

Class diagram GraphML generator. More...

Detailed Description

Class diagram GraphML generator.

Definition at line 62 of file class_diagram_generator.h.

#include <class_diagram_generator.h>

Public Member Functions

 generator (diagram_config &config, diagram_model &model)
 
std::vector< std::pair< std::string, common::generators::graphml::property_type > > node_property_names () const override
 
void generate (const class_ &c, graphml_node_t &parent) const
 
void generate (const objc_interface &c, graphml_node_t &parent) const
 
void generate (const enum_ &c, graphml_node_t &parent) const
 
void generate (const concept_ &c, graphml_node_t &parent) const
 
void generate (const package &p, graphml_node_t &parent) const override
 
void generate_top_level_elements (graphml_node_t &parent) const override
 
- Public Member Functions inherited from clanguml::common::generators::graphml::generator< ConfigType, DiagramType >
 ~generator () override=default
 
virtual std::vector< std::pair< std::string, property_type > > graph_property_names () const
 
virtual std::vector< std::pair< std::string, property_type > > node_property_names () const
 
virtual std::vector< std::pair< std::string, property_type > > edge_property_names () const
 
void generate (std::ostream &ostr) const override
 Generate diagram.
 
void generate_diagram (graphml_node_t &parent) const
 Generate diagram model.
 
virtual void generate_top_level_elements (graphml_node_t &parent) const =0
 In a nested diagram, generate the top level elements.
 
template<typename T >
void generate_notes (const T &e, graphml_node_t &parent) const
 Generate any notes to be attached to diagram elements.
 
void generate_metadata (graphml_t &parent) const
 Generate metadata element with diagram metadata.
 
virtual void generate (const model::package &p, graphml_node_t &parent) const
 Generate diagram package.
 
virtual void generate_relationships (graphml_node_t &parent) const
 Generate all relationships in the diagram.
 
virtual void generate_relationships (const model::diagram_element &c, graphml_node_t &parent) const
 Generate all relationships originating at a diagram element.
 
template<typename T >
void generate_link (pugi::xml_node &node, const T &c) const
 
const property_keymap_tgraph_properties () const
 
const property_keymap_tnode_properties () const
 
const property_keymap_tedge_properties () const
 
pugi::xml_node make_node (graphml_node_t &parent, const std::string &id) const
 
pugi::xml_node make_graph (graphml_node_t &parent, const std::string &id) const
 
pugi::xml_node make_subgraph (graphml_node_t &parent, const std::string &id, const std::string &name="", const std::string &type="") const
 
void add_data (pugi::xml_node &node, const std::string &key, const std::string &value, bool cdata=false) const
 
void add_cdata (pugi::xml_node &node, const std::string &key, const std::string &value) const
 
- 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
 

Additional Inherited Members

- Protected Member Functions inherited from clanguml::common::generators::graphml::generator< ConfigType, DiagramType >
void generate_key (pugi::xml_node &parent, const std::string &attr_name, const std::string &for_value, const std::string &id_value, const std::string &attr_type="string") const
 
property_keymap_tgraph_properties ()
 
property_keymap_tnode_properties ()
 
property_keymap_tedge_properties ()
 
- Protected Attributes inherited from clanguml::common::generators::graphml::generator< ConfigType, DiagramType >
graphml_node_map_t graph_ids_ {"g"}
 
graphml_node_map_t node_ids_ {"n"}
 
graphml_node_map_t edge_ids_ {"e"}
 
- Protected Attributes inherited from clanguml::common::generators::generator< ConfigType, DiagramType >
inja::json m_context
 
inja::Environment m_env
 

Constructor & Destructor Documentation

◆ generator()

clanguml::class_diagram::generators::graphml::generator::generator ( diagram_config config,
diagram_model model 
)

Definition at line 28 of file class_diagram_generator.cc.

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

Member Function Documentation

◆ generate() [1/5]

void clanguml::class_diagram::generators::graphml::generator::generate ( const class_ c,
graphml_node_t &  parent 
) const

Render class element into a GraphML node.

Parameters
cclass diagram element
parentGraphML node

Definition at line 107 of file class_diagram_generator.cc.

108{
109 using namespace common::generators::graphml;
110
111 std::string full_name;
112 if (!config().generate_fully_qualified_name())
113 full_name = display_name_adapter(c).with_packages().full_name_no_ns();
114 else
115 full_name = display_name_adapter(c).full_name(true);
116
117 auto class_node = make_node(parent, node_ids_.add(c.alias()));
118 add_data(class_node, "type", c.type_name());
119 add_cdata(class_node, "name", config().simplify_template_type(full_name));
120 if (c.is_abstract()) {
121 add_data(class_node, "stereotype", "abstract");
122 }
123 else if (c.is_union()) {
124 add_data(class_node, "stereotype", "union");
125 }
126 add_data(class_node, "is_template", to_string(c.is_template()));
127
128 generate_link(class_node, c);
129}

◆ generate() [2/5]

void clanguml::class_diagram::generators::graphml::generator::generate ( const concept_ c,
graphml_node_t &  parent 
) const

Render concept element into a GraphML node.

Parameters
cconcept diagram element
parentJSON node

Definition at line 147 of file class_diagram_generator.cc.

148{
149 using namespace common::generators::graphml;
150
151 std::string full_name;
152 if (!config().generate_fully_qualified_name())
153 full_name = display_name_adapter(c).with_packages().full_name_no_ns();
154 else
155 full_name = display_name_adapter(c).full_name(true);
156
157 auto node = make_node(parent, node_ids_.add(c.alias()));
158 add_data(node, "type", c.type_name());
159 add_cdata(node, "name", full_name);
160 generate_link(node, c);
161}

◆ generate() [3/5]

void clanguml::class_diagram::generators::graphml::generator::generate ( const enum_ c,
graphml_node_t &  parent 
) const

Render enum element into a GraphML node.

Parameters
cenum diagram element
parentGraphML node

Definition at line 131 of file class_diagram_generator.cc.

132{
133 using namespace common::generators::graphml;
134
135 std::string full_name;
136 if (!config().generate_fully_qualified_name())
137 full_name = display_name_adapter(e).with_packages().name();
138 else
139 full_name = display_name_adapter(e).full_name(true);
140
141 auto node = make_node(parent, node_ids_.add(e.alias()));
142 add_data(node, "type", e.type_name());
143 add_cdata(node, "name", full_name);
144 generate_link(node, e);
145}

◆ generate() [4/5]

void clanguml::class_diagram::generators::graphml::generator::generate ( const objc_interface c,
graphml_node_t &  parent 
) const

Render ObjC interface or protocol element into a GraphML node.

Parameters
cenum diagram element
parentGraphML node

Definition at line 163 of file class_diagram_generator.cc.

164{
165 using namespace common::generators::graphml;
166
167 auto node = make_node(parent, node_ids_.add(c.alias()));
168 add_data(node, "type", c.type_name());
169 add_data(node, "name", display_name_adapter(c).full_name(true));
170 generate_link(node, c);
171}

◆ generate() [5/5]

void clanguml::class_diagram::generators::graphml::generator::generate ( const package p,
graphml_node_t &  parent 
) const
override

Render package element into a GraphML node.

Parameters
ppackage diagram element
parentGraphML node

Definition at line 57 of file class_diagram_generator.cc.

58{
59 const auto &uns = config().using_namespace();
60 using namespace common::generators::graphml;
61
62 pugi::xml_node package_node;
63 pugi::xml_node graph_node;
64
65 if (config().generate_packages()) {
66 // Don't generate packages from namespaces filtered out by
67 // using_namespace
68 if (!uns.starts_with({p.full_name(false)})) {
69 auto name = display_name_adapter(p).with_packages().name();
70 LOG_DBG("Generating package {}", name);
71
72 package_node = make_subgraph(
73 parent, p.alias(), name, to_string(config().package_type()));
74 graph_node = make_graph(package_node, p.alias());
75 }
76 }
77
78 for (const auto &subpackage : p) {
79 if (dynamic_cast<package *>(subpackage.get()) != nullptr) {
80 const auto &sp = dynamic_cast<package &>(*subpackage);
81 if (!sp.is_empty()) {
82 if (config().generate_packages()) {
83 generate(sp, graph_node);
84 }
85 else
86 generate(sp, parent);
87 }
88 }
89 else {
90 model().dynamic_apply(subpackage.get(), [&](auto *el) {
91 if (config().generate_packages()) {
92 generate(*el, graph_node);
93 }
94 else
95 generate(*el, parent);
96 });
97 }
98 }
99
100 // When generating packages as subgraphs, we want to render the note nodes
101 // and their relationship to their elements within the subgraph
102 if (config().generate_packages()) {
103 generate_notes(p, package_node);
104 }
105}

◆ generate_top_level_elements()

void clanguml::class_diagram::generators::graphml::generator::generate_top_level_elements ( graphml_node_t &  parent) const
override

Definition at line 43 of file class_diagram_generator.cc.

44{
45 for (const auto &p : model()) {
46 if (auto *pkg = dynamic_cast<package *>(p.get()); pkg) {
47 if (!pkg->is_empty())
48 generate(*pkg, parent);
49 }
50 else {
51 model().dynamic_apply(
52 p.get(), [&](auto *el) { generate(*el, parent); });
53 }
54 }
55}

◆ node_property_names()

std::vector< std::pair< std::string, common::generators::graphml::property_type > > clanguml::class_diagram::generators::graphml::generator::node_property_names ( ) const
overridevirtual

Reimplemented from clanguml::common::generators::graphml::generator< ConfigType, DiagramType >.

Definition at line 34 of file class_diagram_generator.cc.

35{
36 auto defaults =
38 defaults.emplace_back(
40 return defaults;
41}

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