0.6.1
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Classes | Functions
clanguml::common::generators::detail Namespace Reference

Classes

struct  has_full_name
 
struct  has_full_name_no_ns
 
struct  has_name
 
struct  has_name_no_ns
 
struct  has_type
 

Functions

template<typename U >
auto has_name_impl (int) -> decltype(std::declval< U >().name(), std::true_type{})
 
template<typename >
std::false_type has_name_impl (...)
 
template<typename U >
auto has_type_impl (int) -> decltype(std::declval< U >().type(), std::true_type{})
 
template<typename >
std::false_type has_type_impl (...)
 
template<typename U >
auto has_full_name_impl (int) -> decltype(std::declval< U >().full_name(std::declval< bool >()), std::true_type{})
 
template<typename >
std::false_type has_full_name_impl (...)
 
template<typename U >
auto has_name_no_ns_impl (int) -> decltype(std::declval< U >().name_no_ns(), std::true_type{})
 
template<typename >
std::false_type has_name_no_ns_impl (...)
 
template<typename U >
auto has_full_name_no_ns_impl (int) -> decltype(std::declval< U >().full_name_no_ns(), std::true_type{})
 
template<typename >
std::false_type has_full_name_no_ns_impl (...)
 
template<typename DiagramConfig , typename GeneratorTag , typename DiagramModel >
void generate_diagram_select_generator (const std::string &od, const std::string &name, std::shared_ptr< clanguml::config::diagram > diagram, const DiagramModel &model)
 
template<typename DiagramConfig >
void generate_diagram_impl (const std::string &name, std::shared_ptr< clanguml::config::diagram > diagram, const common::compilation_database &db, const std::vector< std::string > &translation_units, const cli::runtime_config &runtime_config, std::function< void()> &&progress)
 

Function Documentation

◆ generate_diagram_impl()

template<typename DiagramConfig >
void clanguml::common::generators::detail::generate_diagram_impl ( const std::string &  name,
std::shared_ptr< clanguml::config::diagram diagram,
const common::compilation_database db,
const std::vector< std::string > &  translation_units,
const cli::runtime_config runtime_config,
std::function< void()> &&  progress 
)

Definition at line 130 of file generators.cc.

135{
136 using diagram_config = DiagramConfig;
137 using diagram_model = typename diagram_model_t<DiagramConfig>::type;
138 using diagram_visitor = typename diagram_visitor_t<DiagramConfig>::type;
139
140 auto model = clanguml::common::generators::generate<diagram_model,
141 diagram_config, diagram_visitor>(db, diagram->name,
142 dynamic_cast<diagram_config &>(*diagram), translation_units,
143 runtime_config.verbose, std::move(progress));
144
145 if constexpr (std::is_same_v<DiagramConfig, config::sequence_diagram>) {
146 if (runtime_config.print_from) {
147 auto from_values = model->list_from_values();
148
149 if (logging::logger_type() == logging::logger_type_t::text) {
150 for (const auto &from : from_values) {
151 std::cout << from << '\n';
152 }
153 }
154 else {
155 inja::json j = inja::json::array();
156 for (const auto &from : from_values) {
157 j.emplace_back(logging::escape_json(from));
158 }
159 std::cout << j.dump();
160 }
161
162 return;
163 }
164 if (runtime_config.print_to) {
165 auto to_values = model->list_to_values();
166 if (logging::logger_type() == logging::logger_type_t::text) {
167 for (const auto &to : to_values) {
168 std::cout << to << '\n';
169 }
170 }
171 else {
172 inja::json j = inja::json::array();
173 for (const auto &to : to_values) {
174 j.emplace_back(logging::escape_json(to));
175 }
176 std::cout << j.dump();
177 }
178 return;
179 }
180 }
181
182 for (const auto generator_type : runtime_config.generators) {
183 if (generator_type == generator_type_t::plantuml) {
185 plantuml_generator_tag>(
186 runtime_config.output_directory, name, diagram, model);
187 }
188 else if (generator_type == generator_type_t::json) {
190 json_generator_tag>(
191 runtime_config.output_directory, name, diagram, model);
192 }
193 else if (generator_type == generator_type_t::mermaid) {
195 mermaid_generator_tag>(
196 runtime_config.output_directory, name, diagram, model);
197 }
198 else if (generator_type == generator_type_t::graphml) {
200 graphml_generator_tag>(
201 runtime_config.output_directory, name, diagram, model);
202 }
203
204 // Convert plantuml or mermaid to an image using command provided
205 // in the command line arguments
206 if (runtime_config.render_diagrams) {
207 render_diagram(generator_type, diagram);
208 }
209 }
210}

◆ generate_diagram_select_generator()

template<typename DiagramConfig , typename GeneratorTag , typename DiagramModel >
void clanguml::common::generators::detail::generate_diagram_select_generator ( const std::string &  od,
const std::string &  name,
std::shared_ptr< clanguml::config::diagram diagram,
const DiagramModel &  model 
)

Definition at line 98 of file generators.cc.

101{
102 using diagram_generator =
104
105 if constexpr (!std::is_same_v<diagram_generator, not_supported>) {
106
107 std::stringstream buffer;
108 buffer << diagram_generator(
109 dynamic_cast<DiagramConfig &>(*diagram), *model);
110
111 // Only open the file after the diagram has been generated successfully
112 // in order not to overwrite previous diagram in case of failure
113 auto path = std::filesystem::path{od} /
114 fmt::format("{}.{}", name, GeneratorTag::extension);
115 std::ofstream ofs;
116 ofs.open(path, std::ofstream::out | std::ofstream::trunc);
117 ofs << buffer.str();
118
119 ofs.close();
120
121 LOG_INFO("Written {} diagram to {}", name, path.string());
122 }
123 else {
124 LOG_INFO("Serialization to {} not supported for {}",
125 GeneratorTag::extension, name);
126 }
127}

◆ has_full_name_impl() [1/2]

template<typename >
std::false_type clanguml::common::generators::detail::has_full_name_impl (   ...)

◆ has_full_name_impl() [2/2]

template<typename U >
auto clanguml::common::generators::detail::has_full_name_impl ( int  ) -> decltype(std::declval< U >().full_name(std::declval< bool >()), std::true_type{})

◆ has_full_name_no_ns_impl() [1/2]

template<typename >
std::false_type clanguml::common::generators::detail::has_full_name_no_ns_impl (   ...)

◆ has_full_name_no_ns_impl() [2/2]

template<typename U >
auto clanguml::common::generators::detail::has_full_name_no_ns_impl ( int  ) -> decltype(std::declval< U >().full_name_no_ns(), std::true_type{})

◆ has_name_impl() [1/2]

template<typename >
std::false_type clanguml::common::generators::detail::has_name_impl (   ...)

◆ has_name_impl() [2/2]

template<typename U >
auto clanguml::common::generators::detail::has_name_impl ( int  ) -> decltype(std::declval< U >().name(), std::true_type{})

◆ has_name_no_ns_impl() [1/2]

template<typename >
std::false_type clanguml::common::generators::detail::has_name_no_ns_impl (   ...)

◆ has_name_no_ns_impl() [2/2]

template<typename U >
auto clanguml::common::generators::detail::has_name_no_ns_impl ( int  ) -> decltype(std::declval< U >().name_no_ns(), std::true_type{})

◆ has_type_impl() [1/2]

template<typename >
std::false_type clanguml::common::generators::detail::has_type_impl (   ...)

◆ has_type_impl() [2/2]

template<typename U >
auto clanguml::common::generators::detail::has_type_impl ( int  ) -> decltype(std::declval< U >().type(), std::true_type{})