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

Include diagram JSON generator. More...

Detailed Description

Include diagram JSON generator.

Definition at line 51 of file include_diagram_generator.h.

#include <include_diagram_generator.h>

Public Member Functions

 generator (diagram_config &config, diagram_model &model)
 
void generate_diagram (nlohmann::json &parent) const override
 Main generator method.
 
void generate_relationships (const source_file &f, nlohmann::json &parent) const
 Generate relationships originating from source_file f
 
void generate (const source_file &e, nlohmann::json &parent) const
 Generate diagram element.
 
- Public Member Functions inherited from clanguml::common::generators::json::generator< ConfigType, DiagramType >
 ~generator () override=default
 
void generate (std::ostream &ostr) const override
 Generate diagram.
 
virtual void generate_diagram (nlohmann::json &parent) const =0
 Generate diagram model.
 
void generate_metadata (nlohmann::json &parent) const
 Generate metadata element with diagram metadata.
 
- 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 Member Functions

void generate_with_packages (const source_file &f, nlohmann::json &parent) const
 
void generate_without_packages (const source_file &f, nlohmann::json &parent) const
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ generator()

clanguml::include_diagram::generators::json::generator::generator ( diagram_config config,
diagram_model model 
)

Definition at line 25 of file include_diagram_generator.cc.

26 : common_generator<diagram_config, diagram_model>{config, model}
27{
28}

Member Function Documentation

◆ generate()

void clanguml::include_diagram::generators::json::generator::generate ( const source_file e,
nlohmann::json &  parent 
) const

Generate diagram element.

Parameters
eSource file diagram element
parentParent JSON node

Definition at line 50 of file include_diagram_generator.cc.

51{
52 if (config().generate_packages && !config().generate_packages()) {
54 }
55 else {
56 generate_with_packages(f, parent);
57 }
58}

◆ generate_diagram()

void clanguml::include_diagram::generators::json::generator::generate_diagram ( nlohmann::json &  parent) const
overridevirtual

Main generator method.

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

Parameters
ostrOutput stream.

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

Definition at line 126 of file include_diagram_generator.cc.

127{
128 parent["elements"] = std::vector<nlohmann::json>{};
129 parent["relationships"] = std::vector<nlohmann::json>{};
130
131 // Generate files and folders
132 util::for_each(model(), [this, &parent](const auto &f) {
133 generate(dynamic_cast<source_file &>(*f), parent);
134 });
135
136 // Process file include relationships
137 util::for_each(model(), [this, &parent](const auto &f) {
138 generate_relationships(dynamic_cast<source_file &>(*f), parent);
139 });
140}

◆ generate_relationships()

void clanguml::include_diagram::generators::json::generator::generate_relationships ( const source_file f,
nlohmann::json &  parent 
) const

Generate relationships originating from source_file f

Parameters
pDiagram element
parentJSON node

Definition at line 30 of file include_diagram_generator.cc.

32{
33 LOG_DBG("Generating relationships for file {}", f.full_name(true));
34
36 util::for_each(f, [this, &parent](const auto &file) {
38 dynamic_cast<const source_file &>(*file), parent);
39 });
40 }
41 else {
42 for (const auto &r : f.relationships()) {
43 nlohmann::json rel = r;
44 rel["source"] = std::to_string(f.id().value());
45 parent["relationships"].push_back(std::move(rel));
46 }
47 }
48}

◆ generate_with_packages()

void clanguml::include_diagram::generators::json::generator::generate_with_packages ( const source_file f,
nlohmann::json &  parent 
) const
private

Definition at line 60 of file include_diagram_generator.cc.

62{
63 nlohmann::json j;
64 j["id"] = std::to_string(f.id().value());
65 j["name"] = f.name();
66 auto display_name = f.full_name(false);
67#if defined(_MSC_VER)
68 util::replace_all(display_name, "\\", "/");
69#endif
70 j["display_name"] = std::move(display_name);
71
73 LOG_DBG("Generating directory {}", f.name());
74
75 j["type"] = "folder";
76
77 util::for_each(f, [this, &j](const auto &file) {
78 generate(dynamic_cast<const source_file &>(*file), j);
79 });
80
81 parent["elements"].push_back(std::move(j));
82 }
83 else {
84 LOG_DBG("Generating file {}", f.name());
85
86 j["type"] = "file";
87 j["file_kind"] = to_string(f.type());
89 j["is_system"] = f.is_system_header();
90 }
91
92 parent["elements"].push_back(std::move(j));
93 }
94}

◆ generate_without_packages()

void clanguml::include_diagram::generators::json::generator::generate_without_packages ( const source_file f,
nlohmann::json &  parent 
) const
private

Definition at line 96 of file include_diagram_generator.cc.

98{
99 nlohmann::json j;
100 j["id"] = std::to_string(f.id().value());
101 j["name"] = f.file_relative();
102 auto display_name = f.full_name(false);
103#if defined(_MSC_VER)
104 util::replace_all(display_name, "\\", "/");
105#endif
106 j["display_name"] = std::move(display_name);
107
109 util::for_each(f, [this, &parent](const auto &file) {
110 generate(dynamic_cast<const source_file &>(*file), parent);
111 });
112 }
113 else {
114 LOG_DBG("Generating file {}", f.file_relative());
115
116 j["type"] = "file";
117 j["file_kind"] = to_string(f.type());
119 j["is_system"] = f.is_system_header();
120 }
121
122 parent["elements"].push_back(std::move(j));
123 }
124}

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