Skip to content

Commit 485a8a1

Browse files
committed
Fixed clang-tidy warnings (#415)
1 parent 5a9d4b0 commit 485a8a1

File tree

24 files changed

+191
-140
lines changed

24 files changed

+191
-140
lines changed

src/class_diagram/model/concept.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,6 @@ const std::vector<std::string> &concept_::requires_statements() const
9090
return requires_statements_;
9191
}
9292

93+
void concept_::append(const concept_ & /*unused*/) { }
94+
9395
} // namespace clanguml::class_diagram::model

src/class_diagram/model/concept.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class concept_ : public common::model::stylable_element,
8484
*/
8585
const std::vector<std::string> &requires_statements() const;
8686

87-
void append(const concept_ &) { }
87+
void append(const concept_ & /*unused*/);
8888

8989
protected:
9090
std::string full_name_impl(bool relative = true) const override;

src/class_diagram/model/diagram.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,22 @@ bool diagram::is_empty() const
425425
element_view<enum_>::is_empty() && element_view<concept_>::is_empty() &&
426426
element_view<objc_interface>::is_empty();
427427
}
428+
429+
void diagram::append(diagram &&other)
430+
{
431+
clanguml::common::model::diagram::append(
432+
dynamic_cast<clanguml::common::model::diagram &&>(other));
433+
434+
element_views<class_, enum_, concept_, objc_interface>::append(
435+
dynamic_cast<element_views<class_, enum_, concept_, objc_interface> &&>(
436+
other));
437+
438+
for (const auto &ae : other.added_elements_) {
439+
added_elements_.emplace(ae);
440+
}
441+
442+
nested_trait_t::append(dynamic_cast<nested_trait_t &&>(std::move(other)));
443+
}
428444
} // namespace clanguml::class_diagram::model
429445

430446
namespace clanguml::common::model {

src/class_diagram/model/diagram.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,7 @@ class diagram : public common::model::diagram,
306306

307307
void apply_filter() override;
308308

309-
void append(diagram &&other)
310-
{
311-
clanguml::common::model::diagram::append(
312-
dynamic_cast<clanguml::common::model::diagram &&>(other));
313-
314-
element_views<class_, enum_, concept_, objc_interface>::append(
315-
dynamic_cast<
316-
element_views<class_, enum_, concept_, objc_interface> &&>(
317-
other));
318-
319-
nested_trait_t::append(dynamic_cast<nested_trait_t &&>(other));
320-
321-
for (auto &&ae : other.added_elements_) {
322-
added_elements_.emplace(std::move(ae));
323-
}
324-
}
309+
void append(diagram &&other);
325310

326311
private:
327312
const config::class_diagram &config_;

src/class_diagram/model/enum.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ std::vector<std::string> &enum_::constants() { return constants_; }
5353

5454
const std::vector<std::string> &enum_::constants() const { return constants_; }
5555

56+
void enum_::append(const enum_ & /*unused*/) { }
57+
5658
std::optional<std::string> enum_::doxygen_link() const
5759
{
5860
auto name = name_and_ns();

src/class_diagram/model/enum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class enum_ : public common::model::element,
6262
*/
6363
std::optional<std::string> doxygen_link() const override;
6464

65-
void append(const enum_ &) { }
65+
void append(const enum_ & /*unused*/);
6666

6767
protected:
6868
std::string full_name_impl(bool relative = true) const override;

src/class_diagram/model/objc_interface.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,24 @@ std::optional<std::string> objc_interface::doxygen_link() const
7272
{
7373
return std::nullopt;
7474
}
75+
76+
void objc_interface::append(const objc_interface &other)
77+
{
78+
// Add members from other only if they don't already exist in this
79+
for (const auto &member : other.members()) {
80+
auto it = std::find(members_.begin(), members_.end(), member);
81+
if (it == members_.end()) {
82+
members_.push_back(member);
83+
}
84+
}
85+
86+
// Add methods from other only if they don't already exist in this
87+
for (const auto &method : other.methods()) {
88+
auto it = std::find(methods_.begin(), methods_.end(), method);
89+
if (it == methods_.end()) {
90+
methods_.push_back(method);
91+
}
92+
}
93+
}
94+
7595
} // namespace clanguml::class_diagram::model

src/class_diagram/model/objc_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class objc_interface : public common::model::element,
7676
*/
7777
std::optional<std::string> doxygen_link() const override;
7878

79-
void append(const objc_interface &) { }
79+
void append(const objc_interface &other);
8080

8181
protected:
8282
std::string full_name_impl(bool relative = true) const override;

src/common/generators/generators.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,15 @@ namespace detail {
9797
template <typename DiagramConfig, typename GeneratorTag, typename DiagramModel>
9898
void generate_diagram_select_generator(const std::string &od,
9999
const std::string &name, std::shared_ptr<clanguml::config::diagram> diagram,
100-
const DiagramModel &model)
100+
DiagramModel &model)
101101
{
102102
using diagram_generator =
103103
typename diagram_generator_t<DiagramConfig, GeneratorTag>::type;
104104

105105
if constexpr (!std::is_same_v<diagram_generator, not_supported>) {
106-
107106
std::stringstream buffer;
108-
buffer << diagram_generator(dynamic_cast<DiagramConfig &>(*diagram),
109-
const_cast<DiagramModel &>(model));
107+
buffer << diagram_generator(
108+
dynamic_cast<DiagramConfig &>(*diagram), model);
110109

111110
// Only open the file after the diagram has been generated successfully
112111
// in order not to overwrite previous diagram in case of failure
@@ -138,7 +137,7 @@ auto generate_diagram_impl(const std::string &name,
138137
using diagram_visitor = typename diagram_visitor_t<DiagramConfig>::type;
139138

140139
return clanguml::common::generators::generate_diagram_model<diagram_model,
141-
diagram_config, diagram_visitor>(db, diagram->name,
140+
diagram_config, diagram_visitor>(db, name,
142141
dynamic_cast<diagram_config &>(*diagram), translation_units,
143142
runtime_config.verbose, std::move(progress));
144143
}
@@ -272,7 +271,7 @@ std::unique_ptr<T> combine_partial_diagram_models(
272271

273272
template <typename DiagramConfig, typename DiagramModel>
274273
void generate_diagrams_by_type(std::shared_ptr<config::diagram> diagram_config,
275-
const DiagramModel &model, const std::string &name,
274+
DiagramModel &model, const std::string &name,
276275
const cli::runtime_config &runtime_config)
277276
{
278277
for (const auto generator_type : runtime_config.generators) {

src/common/generators/generators.h

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -397,51 +397,6 @@ class diagram_action_visitor_factory
397397
std::function<void()> progress_;
398398
};
399399

400-
template <typename DiagramConfig>
401-
auto make_generator(const std::string &name,
402-
const std::string &translation_unit,
403-
const common::compilation_database_ptr &db, DiagramConfig &diagram,
404-
const cli::runtime_config &runtime_config,
405-
std::shared_ptr<progress_indicator_base> indicator)
406-
{
407-
using diagram_model = typename diagram_model_t<DiagramConfig>::type;
408-
using diagram_visitor = typename diagram_visitor_t<DiagramConfig>::type;
409-
410-
return [name, diagram, indicator, db = std::ref(*db),
411-
translation_units = std::vector<std::string>{translation_unit},
412-
runtime_config]() mutable -> std::unique_ptr<diagram_model> {
413-
try {
414-
std::unique_ptr<diagram_model> model;
415-
auto progress_fun = [&indicator, &name]() {
416-
if (indicator)
417-
indicator->increment(name);
418-
};
419-
420-
model = generate_diagram_model<diagram_model, DiagramConfig,
421-
diagram_visitor>(db, name, diagram, translation_units,
422-
false, // runtime_config,
423-
std::move(progress_fun));
424-
return model;
425-
}
426-
catch (clanguml::generators::clang_tool_exception &e) {
427-
if (indicator)
428-
indicator->fail(name);
429-
throw std::move(e);
430-
}
431-
catch (std::exception &e) {
432-
if (indicator)
433-
indicator->fail(name);
434-
435-
LOG_ERROR("Failed to generate diagram '{}': {}", name, e.what());
436-
437-
throw std::runtime_error(fmt::format(
438-
"Failed to generate diagram '{}': {}", name, e.what()));
439-
}
440-
441-
return {};
442-
};
443-
};
444-
445400
/**
446401
* @brief Specialization of
447402
* [clang::ASTFrontendAction](https://clang.llvm.org/doxygen/classclang_1_1tooling_1_1FrontendActionFactory.html)
@@ -493,6 +448,72 @@ std::unique_ptr<DiagramModel> generate_diagram_model(
493448
return diagram;
494449
}
495450

451+
/**
452+
* @brief Create a generator function for a specific diagram and translation
453+
* unit
454+
*
455+
* This function creates a lambda that will generate a diagram model for a
456+
* single translation unit. The returned lambda can be executed asynchronously
457+
* to build partial diagram models that can later be combined.
458+
*
459+
* @tparam DiagramConfig Type of diagram configuration (e.g., class_diagram,
460+
* sequence_diagram)
461+
* @param name Name of the diagram being generated
462+
* @param translation_unit Path to the translation unit to process
463+
* @param db Shared pointer to the compilation database
464+
* @param diagram Reference to the diagram configuration
465+
* @param runtime_config Runtime configuration including threading and output
466+
* settings
467+
* @param indicator Shared pointer to progress indicator for tracking generation
468+
* progress
469+
* @return Lambda function that returns a unique_ptr to the generated diagram
470+
* model
471+
*/
472+
template <typename DiagramConfig>
473+
auto make_generator(const std::string &name,
474+
const std::string &translation_unit,
475+
const common::compilation_database_ptr &db, DiagramConfig &diagram,
476+
const cli::runtime_config &runtime_config,
477+
std::shared_ptr<progress_indicator_base> indicator)
478+
{
479+
using diagram_model = typename diagram_model_t<DiagramConfig>::type;
480+
using diagram_visitor = typename diagram_visitor_t<DiagramConfig>::type;
481+
482+
return [name, diagram, indicator, db = std::ref(*db),
483+
translation_units = std::vector<std::string>{translation_unit},
484+
runtime_config]() mutable -> std::unique_ptr<diagram_model> {
485+
try {
486+
std::unique_ptr<diagram_model> model;
487+
auto progress_fun = [&indicator, &name]() {
488+
if (indicator)
489+
indicator->increment(name);
490+
};
491+
492+
model = generate_diagram_model<diagram_model, DiagramConfig,
493+
diagram_visitor>(db, name, diagram, translation_units, false,
494+
std::move(progress_fun));
495+
496+
return model;
497+
}
498+
catch (clanguml::generators::clang_tool_exception &e) {
499+
if (indicator)
500+
indicator->fail(name);
501+
throw std::move(e);
502+
}
503+
catch (std::exception &e) {
504+
if (indicator)
505+
indicator->fail(name);
506+
507+
LOG_ERROR("Failed to generate diagram '{}': {}", name, e.what());
508+
509+
throw std::runtime_error(fmt::format(
510+
"Failed to generate diagram '{}': {}", name, e.what()));
511+
}
512+
513+
return {};
514+
};
515+
};
516+
496517
/**
497518
* @brief Generate a single diagram
498519
*

0 commit comments

Comments
 (0)