0.6.0
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 129 of file generators.cc.

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

◆ 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 97 of file generators.cc.

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

◆ 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{})