Fixed clang-tidy warnings

This commit is contained in:
Bartek Kryza
2024-01-02 23:17:32 +01:00
parent eec73a79e8
commit da7870f50f
43 changed files with 188 additions and 226 deletions

View File

@@ -8,6 +8,7 @@ Checks: >-
-bugprone-branch-clone, -bugprone-branch-clone,
-bugprone-exception-escape, -bugprone-exception-escape,
-bugprone-easily-swappable-parameters, -bugprone-easily-swappable-parameters,
-bugprone-empty-catch,
-clang-analyzer-alpha.*, -clang-analyzer-alpha.*,
-clang-analyzer-core.StackAddressEscape, -clang-analyzer-core.StackAddressEscape,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
@@ -16,6 +17,8 @@ Checks: >-
-cppcoreguidelines-special-member-functions, -cppcoreguidelines-special-member-functions,
-cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-missing-std-forward,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cert-env33-c, -cert-env33-c,
-cert-err58-cpp, -cert-err58-cpp,
-cert-dcl58-cpp, -cert-dcl58-cpp,
@@ -34,6 +37,7 @@ Checks: >-
-misc-no-recursion, -misc-no-recursion,
-misc-non-private-member-variables-in-classes, -misc-non-private-member-variables-in-classes,
-misc-const-correctness, -misc-const-correctness,
-misc-include-cleaner,
-modernize-use-nodiscard, -modernize-use-nodiscard,
-modernize-use-trailing-return-type, -modernize-use-trailing-return-type,
-modernize-concat-nested-namespaces, -modernize-concat-nested-namespaces,

View File

@@ -155,7 +155,7 @@ format:
.PHONY: debug_tidy .PHONY: debug_tidy
tidy: debug_tidy tidy: debug_tidy
run-clang-tidy-15 -j $(NUMPROC) -p debug_tidy ./src run-clang-tidy-15 -extra-arg=-Wno-unknown-warning-option -j $(NUMPROC) -p debug_tidy ./src
.PHONY: check-formatting .PHONY: check-formatting
check-formatting: check-formatting:

View File

@@ -74,7 +74,7 @@ common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
} }
common::optional_ref<clanguml::common::model::diagram_element> diagram::get( common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
const clanguml::common::model::diagram_element::id_t id) const const clanguml::common::id_t id) const
{ {
common::optional_ref<clanguml::common::model::diagram_element> res; common::optional_ref<clanguml::common::model::diagram_element> res;
@@ -149,8 +149,7 @@ void diagram::get_parents(
} }
} }
bool diagram::has_element( bool diagram::has_element(clanguml::common::id_t id) const
clanguml::common::model::diagram_element::id_t id) const
{ {
const auto has_class = std::any_of(classes().begin(), classes().end(), const auto has_class = std::any_of(classes().begin(), classes().end(),
[id](const auto &c) { return c.get().id() == id; }); [id](const auto &c) { return c.get().id() == id; });
@@ -168,8 +167,7 @@ bool diagram::has_element(
[id](const auto &c) { return c.get().id() == id; }); [id](const auto &c) { return c.get().id() == id; });
} }
std::string diagram::to_alias( std::string diagram::to_alias(clanguml::common::id_t id) const
clanguml::common::model::diagram_element::id_t id) const
{ {
LOG_DBG("Looking for alias for {}", id); LOG_DBG("Looking for alias for {}", id);

View File

@@ -103,7 +103,7 @@ public:
* @param id Element id. * @param id Element id.
* @return Optional reference to a diagram element. * @return Optional reference to a diagram element.
*/ */
opt_ref<diagram_element> get(diagram_element::id_t id) const override; opt_ref<diagram_element> get(common::id_t id) const override;
/** /**
* @brief Get list of references to classes in the diagram model. * @brief Get list of references to classes in the diagram model.
@@ -172,8 +172,7 @@ public:
* @param id Id of the element * @param id Id of the element
* @return Optional reference to a diagram element * @return Optional reference to a diagram element
*/ */
template <typename ElementT> template <typename ElementT> opt_ref<ElementT> find(common::id_t id) const;
opt_ref<ElementT> find(diagram_element::id_t id) const;
/** /**
* @brief Get reference to vector of elements of specific type * @brief Get reference to vector of elements of specific type
@@ -219,7 +218,7 @@ public:
* @param id Id of the diagram element. * @param id Id of the diagram element.
* @return PlantUML alias. * @return PlantUML alias.
*/ */
std::string to_alias(diagram_element::id_t id) const; std::string to_alias(common::id_t id) const;
/** /**
* @brief Given an initial set of classes, add all their parents to the * @brief Given an initial set of classes, add all their parents to the
@@ -236,7 +235,7 @@ public:
* @param id Id of the element. * @param id Id of the element.
* @return True, if diagram contains an element with a specific id. * @return True, if diagram contains an element with a specific id.
*/ */
bool has_element(diagram_element::id_t id) const override; bool has_element(common::id_t id) const override;
/** /**
* @brief Remove redundant dependency relationships * @brief Remove redundant dependency relationships
@@ -421,7 +420,7 @@ std::vector<opt_ref<ElementT>> diagram::find(
} }
template <typename ElementT> template <typename ElementT>
opt_ref<ElementT> diagram::find(diagram_element::id_t id) const opt_ref<ElementT> diagram::find(common::id_t id) const
{ {
for (const auto &element : element_view<ElementT>::view()) { for (const auto &element : element_view<ElementT>::view()) {
if (element.get().id() == id) { if (element.get().id() == id) {

View File

@@ -216,7 +216,7 @@ std::unique_ptr<class_> template_builder::build(const clang::NamedDecl *cls,
std::string best_match_full_name{}; std::string best_match_full_name{};
auto full_template_name = template_instantiation.full_name(false); auto full_template_name = template_instantiation.full_name(false);
int best_match{}; int best_match{};
common::model::diagram_element::id_t best_match_id{0}; common::id_t best_match_id{0};
for (const auto templ : diagram().classes()) { for (const auto templ : diagram().classes()) {
if (templ.get() == template_instantiation) if (templ.get() == template_instantiation)
@@ -318,7 +318,7 @@ template_builder::build_from_class_template_specialization(
std::string best_match_full_name{}; std::string best_match_full_name{};
auto full_template_name = template_instantiation.full_name(false); auto full_template_name = template_instantiation.full_name(false);
int best_match{}; int best_match{};
common::model::diagram_element::id_t best_match_id{0}; common::id_t best_match_id{0};
for (const auto templ : diagram().classes()) { for (const auto templ : diagram().classes()) {
if (templ.get() == template_instantiation) if (templ.get() == template_instantiation)

View File

@@ -30,9 +30,8 @@ using common::model::namespace_;
using common::model::relationship_t; using common::model::relationship_t;
using common::model::template_parameter; using common::model::template_parameter;
using found_relationships_t = using found_relationships_t = std::vector<
std::vector<std::pair<clanguml::common::model::diagram_element::id_t, std::pair<clanguml::common::id_t, common::model::relationship_t>>;
common::model::relationship_t>>;
class translation_unit_visitor; class translation_unit_visitor;

View File

@@ -116,7 +116,7 @@ bool translation_unit_visitor::VisitEnumDecl(clang::EnumDecl *enm)
const auto *parent = enm->getParent(); const auto *parent = enm->getParent();
std::optional<common::model::diagram_element::id_t> id_opt; std::optional<common::id_t> id_opt;
if (parent != nullptr) { if (parent != nullptr) {
const auto *parent_record_decl = const auto *parent_record_decl =
@@ -863,7 +863,7 @@ void translation_unit_visitor::process_record_parent(
{ {
const auto *parent = cls->getParent(); const auto *parent = cls->getParent();
std::optional<common::model::diagram_element::id_t> id_opt; std::optional<common::id_t> id_opt;
auto parent_ns = ns; auto parent_ns = ns;
if (parent != nullptr) { if (parent != nullptr) {

View File

@@ -477,7 +477,7 @@ private:
template_builder template_builder_; template_builder template_builder_;
std::map<common::model::diagram_element::id_t, std::map<common::id_t,
std::unique_ptr<clanguml::class_diagram::model::class_>> std::unique_ptr<clanguml::class_diagram::model::class_>>
forward_declarations_; forward_declarations_;

View File

@@ -384,14 +384,13 @@ runtime_config cli_handler::get_runtime_config() const
cli_flow_t cli_handler::print_version() cli_flow_t cli_handler::print_version()
{ {
ostr_ << "clang-uml " << clanguml::version::CLANG_UML_VERSION << std::endl; ostr_ << "clang-uml " << clanguml::version::CLANG_UML_VERSION << '\n';
ostr_ << "Copyright (C) 2021-2023 Bartek Kryza <bkryza@gmail.com>" ostr_ << "Copyright (C) 2021-2023 Bartek Kryza <bkryza@gmail.com>" << '\n';
<< std::endl; ostr_ << util::get_os_name() << '\n';
ostr_ << util::get_os_name() << std::endl;
ostr_ << "Built against LLVM/Clang libraries version: " ostr_ << "Built against LLVM/Clang libraries version: "
<< LLVM_VERSION_STRING << std::endl; << LLVM_VERSION_STRING << '\n';
ostr_ << "Using LLVM/Clang libraries version: " ostr_ << "Using LLVM/Clang libraries version: "
<< clang::getClangFullVersion() << std::endl; << clang::getClangFullVersion() << '\n';
return cli_flow_t::kExit; return cli_flow_t::kExit;
} }

View File

@@ -127,7 +127,7 @@ void generate_diagram_impl(const std::string &name,
auto from_values = model->list_from_values(); auto from_values = model->list_from_values();
for (const auto &from : from_values) { for (const auto &from : from_values) {
std::cout << from << std::endl; std::cout << from << '\n';
} }
return; return;
@@ -136,7 +136,7 @@ void generate_diagram_impl(const std::string &name,
auto to_values = model->list_to_values(); auto to_values = model->list_to_values();
for (const auto &to : to_values) { for (const auto &to : to_values) {
std::cout << "|" << to << "|" << std::endl; std::cout << "|" << to << "|" << '\n';
} }
return; return;

View File

@@ -65,7 +65,7 @@ public:
* @return Optional reference to a diagram element. * @return Optional reference to a diagram element.
*/ */
virtual common::optional_ref<clanguml::common::model::diagram_element> get( virtual common::optional_ref<clanguml::common::model::diagram_element> get(
diagram_element::id_t id) const = 0; common::id_t id) const = 0;
/** /**
* Return optional reference to a diagram_element by name and namespace. * Return optional reference to a diagram_element by name and namespace.
@@ -152,10 +152,7 @@ public:
// Disallow std::string overload // Disallow std::string overload
bool should_include(const std::string &s) const = delete; bool should_include(const std::string &s) const = delete;
virtual bool has_element(const diagram_element::id_t /*id*/) const virtual bool has_element(const common::id_t /*id*/) const { return false; }
{
return false;
}
virtual bool should_include( virtual bool should_include(
const namespace_ &ns, const std::string &name) const; const namespace_ &ns, const std::string &name) const;

View File

@@ -26,16 +26,16 @@ namespace clanguml::common::model {
diagram_element::diagram_element() = default; diagram_element::diagram_element() = default;
diagram_element::id_t diagram_element::id() const { return id_; } common::id_t diagram_element::id() const { return id_; }
void diagram_element::set_id(diagram_element::id_t id) { id_ = id; } void diagram_element::set_id(common::id_t id) { id_ = id; }
std::optional<id_t> diagram_element::parent_element_id() const std::optional<id_t> diagram_element::parent_element_id() const
{ {
return parent_element_id_; return parent_element_id_;
} }
void diagram_element::set_parent_element_id(diagram_element::id_t id) void diagram_element::set_parent_element_id(common::id_t id)
{ {
parent_element_id_ = id; parent_element_id_ = id;
} }

View File

@@ -39,8 +39,6 @@ namespace clanguml::common::model {
*/ */
class diagram_element : public decorated_element, public source_location { class diagram_element : public decorated_element, public source_location {
public: public:
using id_t = int64_t;
diagram_element(); diagram_element();
~diagram_element() override = default; ~diagram_element() override = default;
@@ -55,14 +53,14 @@ public:
* *
* @return Elements id. * @return Elements id.
*/ */
id_t id() const; common::id_t id() const;
/** /**
* Set elements id. * Set elements id.
* *
* @param id Elements id. * @param id Elements id.
*/ */
void set_id(id_t id); void set_id(common::id_t id);
/** /**
* Get elements parent package id. * Get elements parent package id.
@@ -76,7 +74,7 @@ public:
* *
* @param id Id of parent package. * @param id Id of parent package.
*/ */
void set_parent_element_id(diagram_element::id_t id); void set_parent_element_id(id_t id);
/** /**
* @brief Return elements' diagram alias. * @brief Return elements' diagram alias.

View File

@@ -595,7 +595,7 @@ tvl::value_t module_access_filter::match(
access_.begin(), access_.end(), [&e](const auto &access) { access_.begin(), access_.end(), [&e](const auto &access) {
if (access == module_access_t::kPublic) if (access == module_access_t::kPublic)
return !e.module_private(); return !e.module_private();
else
return e.module_private(); return e.module_private();
}); });
} }

View File

@@ -58,8 +58,7 @@ public:
* *
* @return * @return
*/ */
common::optional_ref<T> get( common::optional_ref<T> get(clanguml::common::id_t id) const
clanguml::common::model::diagram_element::id_t id) const
{ {
for (const auto &e : elements_) { for (const auto &e : elements_) {
if (e.get().id() == id) { if (e.get().id() == id) {

View File

@@ -29,6 +29,9 @@ std::string to_string(const path_type pt)
return "namespace"; return "namespace";
case path_type::kFilesystem: case path_type::kFilesystem:
return "directory"; return "directory";
default:
assert(false);
return "";
} }
} }

View File

@@ -40,7 +40,7 @@ namespace clanguml::common::visitor {
*/ */
class ast_id_mapper { class ast_id_mapper {
public: public:
using id_t = common::model::diagram_element::id_t; using id_t = common::id_t;
ast_id_mapper() = default; ast_id_mapper() = default;

View File

@@ -20,8 +20,10 @@
#include "comment/clang_visitor.h" #include "comment/clang_visitor.h"
#include "comment/plain_visitor.h" #include "comment/plain_visitor.h"
#include "common/clang_utils.h"
#include "clang/Basic/Module.h" #include <clang/AST/Expr.h>
#include <clang/Basic/Module.h>
namespace clanguml::common::visitor { namespace clanguml::common::visitor {

View File

@@ -18,9 +18,12 @@
#pragma once #pragma once
#include "comment/comment_visitor.h" #include "comment/comment_visitor.h"
#include "common/model/element.h"
#include "common/model/source_location.h"
#include "config/config.h" #include "config/config.h"
#include <clang/AST/Comment.h> #include <clang/AST/Comment.h>
#include <clang/AST/RawCommentList.h>
#include <clang/Basic/SourceManager.h> #include <clang/Basic/SourceManager.h>
#include <deque> #include <deque>
@@ -31,9 +34,8 @@
namespace clanguml::common::visitor { namespace clanguml::common::visitor {
using found_relationships_t = using found_relationships_t = std::vector<
std::vector<std::pair<clanguml::common::model::diagram_element::id_t, std::pair<clanguml::common::id_t, common::model::relationship_t>>;
common::model::relationship_t>>;
/** /**
* @brief Diagram translation unit visitor base class * @brief Diagram translation unit visitor base class

View File

@@ -17,7 +17,6 @@
*/ */
#pragma once #pragma once
#include "class_diagram/model/diagram.h"
#include "common/model/enums.h" #include "common/model/enums.h"
#include "common/types.h" #include "common/types.h"
#include "option.h" #include "option.h"

View File

@@ -35,7 +35,7 @@ common::optional_ref<common::model::diagram_element> diagram::get(
} }
common::optional_ref<common::model::diagram_element> diagram::get( common::optional_ref<common::model::diagram_element> diagram::get(
const common::model::diagram_element::id_t id) const const common::id_t id) const
{ {
return find<source_file>(id); return find<source_file>(id);
} }

View File

@@ -68,7 +68,7 @@ public:
* @param id Element id. * @param id Element id.
* @return Optional reference to a diagram element. * @return Optional reference to a diagram element.
*/ */
opt_ref<diagram_element> get(diagram_element::id_t id) const override; opt_ref<diagram_element> get(common::id_t id) const override;
/** /**
* @brief Add include diagram element, an include file. * @brief Add include diagram element, an include file.
@@ -100,8 +100,7 @@ public:
* @param id Id of the element * @param id Id of the element
* @return Optional reference to a diagram element * @return Optional reference to a diagram element
*/ */
template <typename ElementT> template <typename ElementT> opt_ref<ElementT> find(common::id_t id) const;
opt_ref<ElementT> find(diagram_element::id_t id) const;
/** /**
* @brief Convert element id to PlantUML alias. * @brief Convert element id to PlantUML alias.
@@ -153,7 +152,7 @@ opt_ref<ElementT> diagram::find(const std::string &name) const
} }
template <typename ElementT> template <typename ElementT>
opt_ref<ElementT> diagram::find(diagram_element::id_t id) const opt_ref<ElementT> diagram::find(common::id_t id) const
{ {
for (const auto &element : element_view<ElementT>::view()) { for (const auto &element : element_view<ElementT>::view()) {
if (element.get().id() == id) { if (element.get().id() == id) {

View File

@@ -41,13 +41,12 @@ common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
} }
common::optional_ref<clanguml::common::model::diagram_element> diagram::get( common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
const clanguml::common::model::diagram_element::id_t id) const const clanguml::common::id_t id) const
{ {
return find<package>(id); return find<package>(id);
} }
std::string diagram::to_alias( std::string diagram::to_alias(const clanguml::common::id_t id) const
const clanguml::common::model::diagram_element::id_t id) const
{ {
LOG_DBG("Looking for alias for {}", id); LOG_DBG("Looking for alias for {}", id);

View File

@@ -75,7 +75,7 @@ public:
* @param id Element id. * @param id Element id.
* @return Optional reference to a diagram element. * @return Optional reference to a diagram element.
*/ */
opt_ref<diagram_element> get(diagram_element::id_t id) const override; opt_ref<diagram_element> get(common::id_t id) const override;
/** /**
* @brief Find an element in the diagram by name. * @brief Find an element in the diagram by name.
@@ -100,8 +100,7 @@ public:
* @param id Id of the element * @param id Id of the element
* @return Optional reference to a diagram element * @return Optional reference to a diagram element
*/ */
template <typename ElementT> template <typename ElementT> opt_ref<ElementT> find(common::id_t id) const;
opt_ref<ElementT> find(diagram_element::id_t id) const;
/** /**
* @brief Find elements in the diagram by regex pattern. * @brief Find elements in the diagram by regex pattern.
@@ -135,7 +134,8 @@ public:
if (parent_path.type() == common::model::path_type::kNamespace) { if (parent_path.type() == common::model::path_type::kNamespace) {
return add_with_namespace_path(std::move(e)); return add_with_namespace_path(std::move(e));
} }
else if (parent_path.type() == common::model::path_type::kModule) {
if (parent_path.type() == common::model::path_type::kModule) {
return add_with_module_path(parent_path, std::move(e)); return add_with_module_path(parent_path, std::move(e));
} }
@@ -148,7 +148,7 @@ public:
* @param id Id of a package in the diagram * @param id Id of a package in the diagram
* @return PlantUML alias of the element * @return PlantUML alias of the element
*/ */
std::string to_alias(diagram_element::id_t id) const; std::string to_alias(common::id_t id) const;
/** /**
* @brief Return the elements JSON context for inja templates. * @brief Return the elements JSON context for inja templates.
@@ -207,7 +207,7 @@ opt_ref<ElementT> diagram::find(const std::string &name) const
} }
template <typename ElementT> template <typename ElementT>
opt_ref<ElementT> diagram::find(diagram_element::id_t id) const opt_ref<ElementT> diagram::find(common::id_t id) const
{ {
for (const auto &element : element_view<ElementT>::view()) { for (const auto &element : element_view<ElementT>::view()) {
if (element.get().id() == id) { if (element.get().id() == id) {

View File

@@ -287,7 +287,7 @@ void translation_unit_visitor::add_relationships(
auto current_package = diagram().get(current_package_id); auto current_package = diagram().get(current_package_id);
if (current_package) { if (current_package) {
std::vector<common::model::diagram_element::id_t> parent_ids = std::vector<common::id_t> parent_ids =
get_parent_package_ids(current_package_id); get_parent_package_ids(current_package_id);
for (const auto &dependency : relationships) { for (const auto &dependency : relationships) {
@@ -310,8 +310,7 @@ void translation_unit_visitor::add_relationships(
} }
} }
common::model::diagram_element::id_t translation_unit_visitor::get_package_id( common::id_t translation_unit_visitor::get_package_id(const clang::Decl *cls)
const clang::Decl *cls)
{ {
if (config().package_type() == config::package_type_t::kNamespace) { if (config().package_type() == config::package_type_t::kNamespace) {
const auto *namespace_context = const auto *namespace_context =
@@ -680,12 +679,11 @@ translation_unit_visitor::config() const
void translation_unit_visitor::finalize() { } void translation_unit_visitor::finalize() { }
std::vector<common::model::diagram_element::id_t> std::vector<common::id_t> translation_unit_visitor::get_parent_package_ids(
translation_unit_visitor::get_parent_package_ids( common::id_t id)
common::model::diagram_element::id_t id)
{ {
std::vector<common::model::diagram_element::id_t> parent_ids; std::vector<common::id_t> parent_ids;
std::optional<common::model::diagram_element::id_t> parent_id = id; std::optional<common::id_t> parent_id = id;
while (parent_id.has_value()) { while (parent_id.has_value()) {
parent_ids.push_back(parent_id.value()); parent_ids.push_back(parent_id.value());

View File

@@ -33,9 +33,8 @@
namespace clanguml::package_diagram::visitor { namespace clanguml::package_diagram::visitor {
using found_relationships_t = using found_relationships_t = std::vector<
std::vector<std::pair<clanguml::common::model::diagram_element::id_t, std::pair<clanguml::common::id_t, common::model::relationship_t>>;
common::model::relationship_t>>;
/** /**
* @brief Package diagram translation unit visitor * @brief Package diagram translation unit visitor
@@ -109,7 +108,7 @@ private:
* @param cls C++ entity declaration * @param cls C++ entity declaration
* @return Id of the package containing that declaration * @return Id of the package containing that declaration
*/ */
common::model::diagram_element::id_t get_package_id(const clang::Decl *cls); common::id_t get_package_id(const clang::Decl *cls);
/** /**
* @brief Process class declaration * @brief Process class declaration
@@ -214,8 +213,7 @@ private:
void add_relationships( void add_relationships(
clang::Decl *cls, found_relationships_t &relationships); clang::Decl *cls, found_relationships_t &relationships);
std::vector<common::model::diagram_element::id_t> get_parent_package_ids( std::vector<common::id_t> get_parent_package_ids(common::id_t id);
common::model::diagram_element::id_t id);
// Reference to the output diagram model // Reference to the output diagram model
clanguml::package_diagram::model::diagram &diagram_; clanguml::package_diagram::model::diagram &diagram_;

View File

@@ -170,8 +170,8 @@ void generator::generate_call(const message &m, nlohmann::json &parent) const
m.from(), to, m.to()); m.from(), to, m.to());
} }
void generator::generate_activity(const activity &a, void generator::generate_activity(
std::vector<common::model::diagram_element::id_t> &visited) const const activity &a, std::vector<common::id_t> &visited) const
{ {
// Generate calls from this activity to other activities // Generate calls from this activity to other activities
for (const auto &m : a.messages()) { for (const auto &m : a.messages()) {
@@ -247,8 +247,8 @@ nlohmann::json &generator::current_block_statement() const
return block_statements_stack_.back().get(); return block_statements_stack_.back().get();
} }
void generator::process_call_message(const model::message &m, void generator::process_call_message(
std::vector<common::model::diagram_element::id_t> &visited) const const model::message &m, std::vector<common::id_t> &visited) const
{ {
visited.push_back(m.from()); visited.push_back(m.from());
@@ -523,7 +523,7 @@ void generator::generate_participant(
} }
common::id_t generator::generate_participant( common::id_t generator::generate_participant(
nlohmann::json &parent, common::id_t id, bool force) const nlohmann::json & /*parent*/, common::id_t id, bool force) const
{ {
common::id_t participant_id{0}; common::id_t participant_id{0};
@@ -570,7 +570,7 @@ common::id_t generator::generate_participant(
return class_participant_id; return class_participant_id;
} }
else {
if (!is_participant_generated(participant_id)) { if (!is_participant_generated(participant_id)) {
for (auto &p : json_["participants"]) { for (auto &p : json_["participants"]) {
if (p.at("id") == std::to_string(class_participant_id)) { if (p.at("id") == std::to_string(class_participant_id)) {
@@ -581,7 +581,6 @@ common::id_t generator::generate_participant(
} }
} }
} }
}
else if ((participant_type == "function" || else if ((participant_type == "function" ||
participant_type == "function_template") && participant_type == "function_template") &&
config().combine_free_functions_into_file_participants()) { config().combine_free_functions_into_file_participants()) {
@@ -619,7 +618,7 @@ common::id_t generator::generate_participant(
return file_participant_id; return file_participant_id;
} }
else {
if (!is_participant_generated(participant_id)) { if (!is_participant_generated(participant_id)) {
for (auto &p : json_["participants"]) { for (auto &p : json_["participants"]) {
if (p.at("id") == std::to_string(file_participant_id)) { if (p.at("id") == std::to_string(file_participant_id)) {
@@ -628,9 +627,9 @@ common::id_t generator::generate_participant(
} }
} }
} }
return file_participant_id; return file_participant_id;
} }
}
else { else {
json_["participants"].push_back(participant); json_["participants"].push_back(participant);
} }
@@ -745,7 +744,7 @@ void generator::generate_diagram(nlohmann::json &parent) const
for (const auto &sf : config().from()) { for (const auto &sf : config().from()) {
if (sf.location_type == location_t::function) { if (sf.location_type == location_t::function) {
common::model::diagram_element::id_t start_from{0}; common::id_t start_from{0};
std::string start_from_str; std::string start_from_str;
for (const auto &[k, v] : model().sequences()) { for (const auto &[k, v] : model().sequences()) {
const auto &caller = *model().participants().at(v.from()); const auto &caller = *model().participants().at(v.from());
@@ -765,8 +764,7 @@ void generator::generate_diagram(nlohmann::json &parent) const
} }
// Use this to break out of recurrent loops // Use this to break out of recurrent loops
std::vector<common::model::diagram_element::id_t> std::vector<common::id_t> visited_participants;
visited_participants;
const auto &from = const auto &from =
model().get_participant<model::function>(start_from); model().get_participant<model::function>(start_from);

View File

@@ -99,7 +99,7 @@ public:
* for breaking infinite recursion on recursive calls * for breaking infinite recursion on recursive calls
*/ */
void generate_activity(const sequence_diagram::model::activity &a, void generate_activity(const sequence_diagram::model::activity &a,
std::vector<common::model::diagram_element::id_t> &visited) const; std::vector<common::id_t> &visited) const;
/** /**
* @brief Get reference to the current block statement. * @brief Get reference to the current block statement.
@@ -126,8 +126,8 @@ private:
* @param m Message model * @param m Message model
* @param visited List of already visited participants * @param visited List of already visited participants
*/ */
void process_call_message(const model::message &m, void process_call_message(
std::vector<common::model::diagram_element::id_t> &visited) const; const model::message &m, std::vector<common::id_t> &visited) const;
/** /**
* @brief Process `if` statement message * @brief Process `if` statement message

View File

@@ -180,7 +180,7 @@ void generator::generate_return(const message &m, std::ostream &ostr) const
} }
void generator::generate_activity(const activity &a, std::ostream &ostr, void generator::generate_activity(const activity &a, std::ostream &ostr,
std::vector<common::model::diagram_element::id_t> &visited) const std::vector<common::id_t> &visited) const
{ {
for (const auto &m : a.messages()) { for (const auto &m : a.messages()) {
if (m.in_static_declaration_context()) { if (m.in_static_declaration_context()) {
@@ -202,7 +202,7 @@ void generator::generate_activity(const activity &a, std::ostream &ostr,
std::string to_alias = generate_alias(to.value()); std::string to_alias = generate_alias(to.value());
ostr << indent(1) << "activate " << to_alias << std::endl; ostr << indent(1) << "activate " << to_alias << '\n';
if (model().sequences().find(m.to()) != model().sequences().end()) { if (model().sequences().find(m.to()) != model().sequences().end()) {
if (std::find(visited.begin(), visited.end(), m.to()) == if (std::find(visited.begin(), visited.end(), m.to()) ==
@@ -220,7 +220,7 @@ void generator::generate_activity(const activity &a, std::ostream &ostr,
generate_return(m, ostr); generate_return(m, ostr);
ostr << indent(1) << "deactivate " << to_alias << std::endl; ostr << indent(1) << "deactivate " << to_alias << '\n';
visited.pop_back(); visited.pop_back();
} }
@@ -495,7 +495,7 @@ void generator::generate_diagram(std::ostream &ostr) const
<< " " << generate_alias(from.value()) << " : " << " " << generate_alias(from.value()) << " : "
<< from.value().message_name( << from.value().message_name(
select_method_arguments_render_mode()) select_method_arguments_render_mode())
<< std::endl; << '\n';
} }
for (const auto &m : mc) { for (const auto &m : mc) {
@@ -528,7 +528,7 @@ void generator::generate_diagram(std::ostream &ostr) const
<< " " << generate_alias(from.value()) << " : " << " " << generate_alias(from.value()) << " : "
<< from.value().message_name( << from.value().message_name(
select_method_arguments_render_mode()) select_method_arguments_render_mode())
<< std::endl; << '\n';
} }
for (const auto &m : mc) { for (const auto &m : mc) {
@@ -539,7 +539,7 @@ void generator::generate_diagram(std::ostream &ostr) const
for (const auto &sf : config().from()) { for (const auto &sf : config().from()) {
if (sf.location_type == location_t::function) { if (sf.location_type == location_t::function) {
common::model::diagram_element::id_t start_from{0}; common::id_t start_from{0};
for (const auto &[k, v] : model().sequences()) { for (const auto &[k, v] : model().sequences()) {
const auto &caller = *model().participants().at(v.from()); const auto &caller = *model().participants().at(v.from());
std::string vfrom = caller.full_name(false); std::string vfrom = caller.full_name(false);
@@ -558,8 +558,7 @@ void generator::generate_diagram(std::ostream &ostr) const
} }
// Use this to break out of recurrent loops // Use this to break out of recurrent loops
std::vector<common::model::diagram_element::id_t> std::vector<common::id_t> visited_participants;
visited_participants;
const auto &from = const auto &from =
model().get_participant<model::function>(start_from); model().get_participant<model::function>(start_from);
@@ -588,10 +587,10 @@ void generator::generate_diagram(std::ostream &ostr) const
<< common::generators::mermaid::to_mermaid( << common::generators::mermaid::to_mermaid(
message_t::kCall) message_t::kCall)
<< " " << from_alias << " : " << " " << from_alias << " : "
<< from.value().message_name(render_mode) << std::endl; << from.value().message_name(render_mode) << '\n';
} }
ostr << indent(1) << "activate " << from_alias << std::endl; ostr << indent(1) << "activate " << from_alias << '\n';
generate_activity( generate_activity(
model().get_activity(start_from), ostr, visited_participants); model().get_activity(start_from), ostr, visited_participants);
@@ -613,7 +612,7 @@ void generator::generate_diagram(std::ostream &ostr) const
} }
} }
ostr << indent(1) << "deactivate " << from_alias << std::endl; ostr << indent(1) << "deactivate " << from_alias << '\n';
} }
else { else {
// TODO: Add support for other sequence start location types // TODO: Add support for other sequence start location types

View File

@@ -117,8 +117,7 @@ public:
* for breaking infinite recursion on recursive calls * for breaking infinite recursion on recursive calls
*/ */
void generate_activity(const clanguml::sequence_diagram::model::activity &a, void generate_activity(const clanguml::sequence_diagram::model::activity &a,
std::ostream &ostr, std::ostream &ostr, std::vector<common::id_t> &visited) const;
std::vector<common::model::diagram_element::id_t> &visited) const;
private: private:
/** /**

View File

@@ -134,7 +134,7 @@ void generator::generate_return(const message &m, std::ostream &ostr) const
} }
void generator::generate_activity(const activity &a, std::ostream &ostr, void generator::generate_activity(const activity &a, std::ostream &ostr,
std::vector<common::model::diagram_element::id_t> &visited) const std::vector<common::id_t> &visited) const
{ {
for (const auto &m : a.messages()) { for (const auto &m : a.messages()) {
if (m.in_static_declaration_context()) { if (m.in_static_declaration_context()) {
@@ -156,7 +156,7 @@ void generator::generate_activity(const activity &a, std::ostream &ostr,
std::string to_alias = generate_alias(to.value()); std::string to_alias = generate_alias(to.value());
ostr << "activate " << to_alias << std::endl; ostr << "activate " << to_alias << '\n';
if (model().sequences().find(m.to()) != model().sequences().end()) { if (model().sequences().find(m.to()) != model().sequences().end()) {
if (std::find(visited.begin(), visited.end(), m.to()) == if (std::find(visited.begin(), visited.end(), m.to()) ==
@@ -174,7 +174,7 @@ void generator::generate_activity(const activity &a, std::ostream &ostr,
generate_return(m, ostr); generate_return(m, ostr);
ostr << "deactivate " << to_alias << std::endl; ostr << "deactivate " << to_alias << '\n';
visited.pop_back(); visited.pop_back();
} }
@@ -498,7 +498,7 @@ void generator::generate_diagram(std::ostream &ostr) const
<< " " << generate_alias(from.value()) << " : " << " " << generate_alias(from.value()) << " : "
<< from.value().message_name( << from.value().message_name(
select_method_arguments_render_mode()) select_method_arguments_render_mode())
<< std::endl; << '\n';
} }
for (const auto &m : mc) { for (const auto &m : mc) {
@@ -535,7 +535,7 @@ void generator::generate_diagram(std::ostream &ostr) const
<< " " << generate_alias(from.value()) << " : " << " " << generate_alias(from.value()) << " : "
<< from.value().message_name( << from.value().message_name(
select_method_arguments_render_mode()) select_method_arguments_render_mode())
<< std::endl; << '\n';
} }
for (const auto &m : mc) { for (const auto &m : mc) {
@@ -546,7 +546,7 @@ void generator::generate_diagram(std::ostream &ostr) const
for (const auto &sf : config().from()) { for (const auto &sf : config().from()) {
if (sf.location_type == location_t::function) { if (sf.location_type == location_t::function) {
common::model::diagram_element::id_t start_from{0}; common::id_t start_from{0};
for (const auto &[k, v] : model().sequences()) { for (const auto &[k, v] : model().sequences()) {
const auto &caller = *model().participants().at(v.from()); const auto &caller = *model().participants().at(v.from());
std::string vfrom = caller.full_name(false); std::string vfrom = caller.full_name(false);
@@ -565,8 +565,7 @@ void generator::generate_diagram(std::ostream &ostr) const
} }
// Use this to break out of recurrent loops // Use this to break out of recurrent loops
std::vector<common::model::diagram_element::id_t> std::vector<common::id_t> visited_participants;
visited_participants;
const auto &from = const auto &from =
model().get_participant<model::function>(start_from); model().get_participant<model::function>(start_from);
@@ -593,10 +592,10 @@ void generator::generate_diagram(std::ostream &ostr) const
config().combine_free_functions_into_file_participants()) { config().combine_free_functions_into_file_participants()) {
ostr << "[->" ostr << "[->"
<< " " << from_alias << " : " << " " << from_alias << " : "
<< from.value().message_name(render_mode) << std::endl; << from.value().message_name(render_mode) << '\n';
} }
ostr << "activate " << from_alias << std::endl; ostr << "activate " << from_alias << '\n';
generate_activity( generate_activity(
model().get_activity(start_from), ostr, visited_participants); model().get_activity(start_from), ostr, visited_participants);
@@ -615,7 +614,7 @@ void generator::generate_diagram(std::ostream &ostr) const
} }
} }
ostr << "deactivate " << from_alias << std::endl; ostr << "deactivate " << from_alias << '\n';
} }
else { else {
// TODO: Add support for other sequence start location types // TODO: Add support for other sequence start location types

View File

@@ -111,8 +111,7 @@ public:
* for breaking infinite recursion on recursive calls * for breaking infinite recursion on recursive calls
*/ */
void generate_activity(const clanguml::sequence_diagram::model::activity &a, void generate_activity(const clanguml::sequence_diagram::model::activity &a,
std::ostream &ostr, std::ostream &ostr, std::vector<common::id_t> &visited) const;
std::vector<common::model::diagram_element::id_t> &visited) const;
private: private:
/** /**

View File

@@ -20,7 +20,7 @@
namespace clanguml::sequence_diagram::model { namespace clanguml::sequence_diagram::model {
activity::activity(common::model::diagram_element::id_t id) activity::activity(common::id_t id)
: from_{id} : from_{id}
{ {
} }
@@ -31,6 +31,6 @@ std::vector<message> &activity::messages() { return messages_; }
const std::vector<message> &activity::messages() const { return messages_; } const std::vector<message> &activity::messages() const { return messages_; }
common::model::diagram_element::id_t activity::from() const { return from_; } common::id_t activity::from() const { return from_; }
} // namespace clanguml::sequence_diagram::model } // namespace clanguml::sequence_diagram::model

View File

@@ -35,7 +35,7 @@ public:
* *
* @param id Id of the participant parent for the activity * @param id Id of the participant parent for the activity
*/ */
activity(common::model::diagram_element::id_t id); activity(common::id_t id);
/** /**
* @brief Add a message call to the activity * @brief Add a message call to the activity
@@ -63,10 +63,10 @@ public:
* *
* @return Id of activity participant * @return Id of activity participant
*/ */
common::model::diagram_element::id_t from() const; common::id_t from() const;
private: private:
common::model::diagram_element::id_t from_; common::id_t from_;
std::vector<message> messages_; std::vector<message> messages_;
}; };

View File

@@ -42,7 +42,7 @@ common::optional_ref<common::model::diagram_element> diagram::get(
} }
common::optional_ref<common::model::diagram_element> diagram::get( common::optional_ref<common::model::diagram_element> diagram::get(
const common::model::diagram_element::id_t id) const const common::id_t id) const
{ {
if (participants_.find(id) != participants_.end()) if (participants_.find(id) != participants_.end())
return {*participants_.at(id)}; return {*participants_.at(id)};
@@ -88,21 +88,17 @@ void diagram::add_participant(std::unique_ptr<participant> p)
} }
} }
void diagram::add_active_participant(common::model::diagram_element::id_t id) void diagram::add_active_participant(common::id_t id)
{ {
active_participants_.emplace(id); active_participants_.emplace(id);
} }
const activity &diagram::get_activity( const activity &diagram::get_activity(common::id_t id) const
common::model::diagram_element::id_t id) const
{ {
return sequences_.at(id); return sequences_.at(id);
} }
activity &diagram::get_activity(common::model::diagram_element::id_t id) activity &diagram::get_activity(common::id_t id) { return sequences_.at(id); }
{
return sequences_.at(id);
}
void diagram::add_message(model::message &&message) void diagram::add_message(model::message &&message)
{ {
@@ -150,37 +146,30 @@ void diagram::add_case_stmt_message(model::message &&m)
} }
} }
std::map<common::model::diagram_element::id_t, activity> &diagram::sequences() std::map<common::id_t, activity> &diagram::sequences() { return sequences_; }
const std::map<common::id_t, activity> &diagram::sequences() const
{ {
return sequences_; return sequences_;
} }
const std::map<common::model::diagram_element::id_t, activity> & std::map<common::id_t, std::unique_ptr<participant>> &diagram::participants()
diagram::sequences() const
{
return sequences_;
}
std::map<common::model::diagram_element::id_t, std::unique_ptr<participant>> &
diagram::participants()
{ {
return participants_; return participants_;
} }
const std::map<common::model::diagram_element::id_t, const std::map<common::id_t, std::unique_ptr<participant>> &
std::unique_ptr<participant>> &
diagram::participants() const diagram::participants() const
{ {
return participants_; return participants_;
} }
std::set<common::model::diagram_element::id_t> &diagram::active_participants() std::set<common::id_t> &diagram::active_participants()
{ {
return active_participants_; return active_participants_;
} }
const std::set<common::model::diagram_element::id_t> & const std::set<common::id_t> &diagram::active_participants() const
diagram::active_participants() const
{ {
return active_participants_; return active_participants_;
} }
@@ -232,10 +221,10 @@ std::vector<std::string> diagram::list_to_values() const
return result; return result;
} }
common::model::diagram_element::id_t diagram::get_to_activity_id( common::id_t diagram::get_to_activity_id(
const config::source_location &to_location) const const config::source_location &to_location) const
{ {
common::model::diagram_element::id_t to_activity{0}; common::id_t to_activity{0};
for (const auto &[k, v] : sequences()) { for (const auto &[k, v] : sequences()) {
for (const auto &m : v.messages()) { for (const auto &m : v.messages()) {
@@ -261,10 +250,10 @@ common::model::diagram_element::id_t diagram::get_to_activity_id(
return to_activity; return to_activity;
} }
common::model::diagram_element::id_t diagram::get_from_activity_id( common::id_t diagram::get_from_activity_id(
const config::source_location &from_location) const const config::source_location &from_location) const
{ {
common::model::diagram_element::id_t from_activity{0}; common::id_t from_activity{0};
for (const auto &[k, v] : sequences()) { for (const auto &[k, v] : sequences()) {
const auto &caller = *participants().at(v.from()); const auto &caller = *participants().at(v.from());
@@ -286,8 +275,7 @@ common::model::diagram_element::id_t diagram::get_from_activity_id(
} }
std::vector<message_chain_t> diagram::get_all_from_to_message_chains( std::vector<message_chain_t> diagram::get_all_from_to_message_chains(
const common::model::diagram_element::id_t from_activity, const common::id_t from_activity, const common::id_t to_activity) const
const common::model::diagram_element::id_t to_activity) const
{ {
std::vector<message_chain_t> message_chains_unique{}; std::vector<message_chain_t> message_chains_unique{};

View File

@@ -67,7 +67,7 @@ public:
* @return Optional reference to a diagram element. * @return Optional reference to a diagram element.
*/ */
common::optional_ref<common::model::diagram_element> get( common::optional_ref<common::model::diagram_element> get(
common::model::diagram_element::id_t id) const override; common::id_t id) const override;
/** /**
* @brief Get participant by id * @brief Get participant by id
@@ -76,8 +76,7 @@ public:
* @return Optional reference to a diagram element. * @return Optional reference to a diagram element.
*/ */
template <typename T> template <typename T>
common::optional_ref<T> get_participant( common::optional_ref<T> get_participant(common::id_t id) const
common::model::diagram_element::id_t id) const
{ {
if (participants_.find(id) == participants_.end()) { if (participants_.find(id) == participants_.end()) {
return {}; return {};
@@ -99,7 +98,7 @@ public:
* *
* @param id Id of participant to activate * @param id Id of participant to activate
*/ */
void add_active_participant(common::model::diagram_element::id_t id); void add_active_participant(common::id_t id);
/** /**
* @brief Get reference to current activity of a participant * @brief Get reference to current activity of a participant
@@ -107,7 +106,7 @@ public:
* @param id Participant id * @param id Participant id
* @return * @return
*/ */
const activity &get_activity(common::model::diagram_element::id_t id) const; const activity &get_activity(common::id_t id) const;
/** /**
* @brief Get reference to current activity of a participant * @brief Get reference to current activity of a participant
@@ -115,7 +114,7 @@ public:
* @param id Participant id * @param id Participant id
* @return * @return
*/ */
activity &get_activity(common::model::diagram_element::id_t id); activity &get_activity(common::id_t id);
/** /**
* @brief Add message to current activity * @brief Add message to current activity
@@ -156,31 +155,28 @@ public:
* *
* @return Map of sequences in the diagram * @return Map of sequences in the diagram
*/ */
std::map<common::model::diagram_element::id_t, activity> &sequences(); std::map<common::id_t, activity> &sequences();
/** /**
* @brief Get all sequences in the diagram * @brief Get all sequences in the diagram
* *
* @return Map of sequences in the diagram * @return Map of sequences in the diagram
*/ */
const std::map<common::model::diagram_element::id_t, activity> & const std::map<common::id_t, activity> &sequences() const;
sequences() const;
/** /**
* @brief Get map of all participants in the diagram * @brief Get map of all participants in the diagram
* *
* @return Map of participants in the diagram * @return Map of participants in the diagram
*/ */
std::map<common::model::diagram_element::id_t, std::unique_ptr<participant>> std::map<common::id_t, std::unique_ptr<participant>> &participants();
&participants();
/** /**
* @brief Get map of all participants in the diagram * @brief Get map of all participants in the diagram
* *
* @return Map of participants in the diagram * @return Map of participants in the diagram
*/ */
const std::map<common::model::diagram_element::id_t, const std::map<common::id_t, std::unique_ptr<participant>> &
std::unique_ptr<participant>> &
participants() const; participants() const;
/** /**
@@ -188,15 +184,14 @@ public:
* *
* @return Set of all active participant ids * @return Set of all active participant ids
*/ */
std::set<common::model::diagram_element::id_t> &active_participants(); std::set<common::id_t> &active_participants();
/** /**
* @brief Get all active participants in the diagram * @brief Get all active participants in the diagram
* *
* @return Set of all active participant ids * @return Set of all active participant ids
*/ */
const std::set<common::model::diagram_element::id_t> & const std::set<common::id_t> &active_participants() const;
active_participants() const;
/** /**
* @brief Convert element full name to PlantUML alias. * @brief Convert element full name to PlantUML alias.
@@ -256,8 +251,7 @@ public:
* @return List of message chains * @return List of message chains
*/ */
std::vector<message_chain_t> get_all_from_to_message_chains( std::vector<message_chain_t> get_all_from_to_message_chains(
common::model::diagram_element::id_t from_activity, common::id_t from_activity, common::id_t to_activity) const;
common::model::diagram_element::id_t to_activity) const;
/** /**
* @brief Get id of a 'to' activity * @brief Get id of a 'to' activity
@@ -265,7 +259,7 @@ public:
* @param to_location Target activity * @param to_location Target activity
* @return Activity id * @return Activity id
*/ */
common::model::diagram_element::id_t get_to_activity_id( common::id_t get_to_activity_id(
const config::source_location &to_location) const; const config::source_location &to_location) const;
/** /**
@@ -274,7 +268,7 @@ public:
* @param from_location Source activity * @param from_location Source activity
* @return Activity id * @return Activity id
*/ */
common::model::diagram_element::id_t get_from_activity_id( common::id_t get_from_activity_id(
const config::source_location &from_location) const; const config::source_location &from_location) const;
/** /**
@@ -328,12 +322,11 @@ private:
return block_end_types.count(mt) > 0; return block_end_types.count(mt) > 0;
}; };
std::map<common::model::diagram_element::id_t, activity> sequences_; std::map<common::id_t, activity> sequences_;
std::map<common::model::diagram_element::id_t, std::unique_ptr<participant>> std::map<common::id_t, std::unique_ptr<participant>> participants_;
participants_;
std::set<common::model::diagram_element::id_t> active_participants_; std::set<common::id_t> active_participants_;
}; };
} // namespace clanguml::sequence_diagram::model } // namespace clanguml::sequence_diagram::model

View File

@@ -20,8 +20,7 @@
namespace clanguml::sequence_diagram::model { namespace clanguml::sequence_diagram::model {
message::message( message::message(common::model::message_t type, common::id_t from)
common::model::message_t type, common::model::diagram_element::id_t from)
: type_{type} : type_{type}
, from_{from} , from_{from}
{ {
@@ -39,13 +38,13 @@ void message::set_type(common::model::message_t t) { type_ = t; }
common::model::message_t message::type() const { return type_; } common::model::message_t message::type() const { return type_; }
void message::set_from(common::model::diagram_element::id_t f) { from_ = f; } void message::set_from(common::id_t f) { from_ = f; }
common::model::diagram_element::id_t message::from() const { return from_; } common::id_t message::from() const { return from_; }
void message::set_to(common::model::diagram_element::id_t t) { to_ = t; } void message::set_to(common::id_t t) { to_ = t; }
common::model::diagram_element::id_t message::to() const { return to_; } common::id_t message::to() const { return to_; }
void message::set_message_name(std::string name) void message::set_message_name(std::string name)
{ {

View File

@@ -38,8 +38,7 @@ public:
* @param type Message type * @param type Message type
* @param from Id of originating sequence * @param from Id of originating sequence
*/ */
message(common::model::message_t type, message(common::model::message_t type, common::id_t from);
common::model::diagram_element::id_t from);
/** /**
* @brief Equality operator * @brief Equality operator
@@ -68,28 +67,28 @@ public:
* *
* @param f Id of the participant from which message originates * @param f Id of the participant from which message originates
*/ */
void set_from(common::model::diagram_element::id_t f); void set_from(common::id_t f);
/** /**
* @brief Get the id of source of message * @brief Get the id of source of message
* *
* @return * @return
*/ */
common::model::diagram_element::id_t from() const; common::id_t from() const;
/** /**
* @brief Set the id of the message target * @brief Set the id of the message target
* *
* @param t Id of the message target * @param t Id of the message target
*/ */
void set_to(common::model::diagram_element::id_t t); void set_to(common::id_t t);
/** /**
* @brief Get the id of the message target * @brief Get the id of the message target
* *
* @return Id of the message target * @return Id of the message target
*/ */
common::model::diagram_element::id_t to() const; common::id_t to() const;
/** /**
* @brief Set the message label * @brief Set the message label
@@ -163,9 +162,9 @@ public:
private: private:
common::model::message_t type_{common::model::message_t::kNone}; common::model::message_t type_{common::model::message_t::kNone};
common::model::diagram_element::id_t from_{}; common::id_t from_{};
common::model::diagram_element::id_t to_{}; common::id_t to_{};
common::model::message_scope_t scope_{ common::model::message_scope_t scope_{
common::model::message_scope_t::kNormal}; common::model::message_scope_t::kNormal};

View File

@@ -189,7 +189,7 @@ void method::is_assignment(bool a) { is_assignment_ = a; }
void method::set_method_name(const std::string &name) { method_name_ = name; } void method::set_method_name(const std::string &name) { method_name_ = name; }
void method::set_class_id(diagram_element::id_t id) { class_id_ = id; } void method::set_class_id(common::id_t id) { class_id_ = id; }
void method::set_class_full_name(const std::string &name) void method::set_class_full_name(const std::string &name)
{ {
@@ -230,7 +230,7 @@ std::string method::message_name(message_render_mode mode) const
fmt::join(parameters(), ","), is_const() ? " const" : "", style); fmt::join(parameters(), ","), is_const() ? " const" : "", style);
} }
class_::diagram_element::id_t method::class_id() const { return class_id_; } common::id_t method::class_id() const { return class_id_; }
std::string method::to_string() const std::string method::to_string() const
{ {

View File

@@ -384,7 +384,7 @@ struct method : public function {
* *
* @param id Id of the class to which this method belongs to * @param id Id of the class to which this method belongs to
*/ */
void set_class_id(diagram_element::id_t id); void set_class_id(common::id_t id);
/** /**
* @brief Set full qualified name of the class * @brief Set full qualified name of the class
@@ -414,7 +414,7 @@ struct method : public function {
* *
* @return Class id * @return Class id
*/ */
diagram_element::id_t class_id() const; common::id_t class_id() const;
/** /**
* @brief Create a string representation of the participant * @brief Create a string representation of the participant
@@ -466,7 +466,7 @@ struct method : public function {
void is_assignment(bool a); void is_assignment(bool a);
private: private:
diagram_element::id_t class_id_{}; common::id_t class_id_{};
std::string method_name_; std::string method_name_;
std::string class_full_name_; std::string class_full_name_;
bool is_constructor_{false}; bool is_constructor_{false};

View File

@@ -1454,7 +1454,7 @@ translation_unit_visitor::create_class_model(clang::CXXRecordDecl *cls)
// Here we have 2 options, either: // Here we have 2 options, either:
// - the parent is a regular C++ class/struct // - the parent is a regular C++ class/struct
// - the parent is a class template declaration/specialization // - the parent is a class template declaration/specialization
std::optional<common::model::diagram_element::id_t> id_opt; std::optional<common::id_t> id_opt;
const auto *parent_record_decl = const auto *parent_record_decl =
clang::dyn_cast<clang::RecordDecl>(parent); clang::dyn_cast<clang::RecordDecl>(parent);
@@ -1626,15 +1626,15 @@ bool translation_unit_visitor::process_template_parameters(
} }
void translation_unit_visitor::set_unique_id( void translation_unit_visitor::set_unique_id(
int64_t local_id, common::model::diagram_element::id_t global_id) int64_t local_id, common::id_t global_id)
{ {
LOG_TRACE("Setting local element mapping {} --> {}", local_id, global_id); LOG_TRACE("Setting local element mapping {} --> {}", local_id, global_id);
local_ast_id_map_[local_id] = global_id; local_ast_id_map_[local_id] = global_id;
} }
std::optional<common::model::diagram_element::id_t> std::optional<common::id_t> translation_unit_visitor::get_unique_id(
translation_unit_visitor::get_unique_id(int64_t local_id) const int64_t local_id) const
{ {
if (local_ast_id_map_.find(local_id) == local_ast_id_map_.end()) if (local_ast_id_map_.find(local_id) == local_ast_id_map_.end())
return {}; return {};
@@ -2228,7 +2228,7 @@ translation_unit_visitor::build_template_instantiation(
std::string best_match_full_name{}; std::string best_match_full_name{};
auto full_template_name = template_instantiation.full_name(false); auto full_template_name = template_instantiation.full_name(false);
int best_match{}; int best_match{};
common::model::diagram_element::id_t best_match_id{0}; common::id_t best_match_id{0};
for (const auto &[id, c] : diagram().participants()) { for (const auto &[id, c] : diagram().participants()) {
const auto *participant_as_class = const auto *participant_as_class =
@@ -2378,7 +2378,7 @@ void translation_unit_visitor::pop_message_to_diagram(
void translation_unit_visitor::finalize() void translation_unit_visitor::finalize()
{ {
std::set<common::model::diagram_element::id_t> active_participants_unique; std::set<common::id_t> active_participants_unique;
// Change all active participants AST local ids to diagram global ids // Change all active participants AST local ids to diagram global ids
for (auto id : diagram().active_participants()) { for (auto id : diagram().active_participants()) {

View File

@@ -204,8 +204,7 @@ public:
* @return Optional reference to participant diagram element * @return Optional reference to participant diagram element
*/ */
template <typename T = model::participant> template <typename T = model::participant>
common::optional_ref<T> get_participant( common::optional_ref<T> get_participant(const common::id_t id)
const common::model::diagram_element::id_t id)
{ {
if (diagram().participants().find(id) == diagram().participants().end()) if (diagram().participants().find(id) == diagram().participants().end())
return {}; return {};
@@ -222,8 +221,7 @@ public:
* @return Optional reference to participant diagram element * @return Optional reference to participant diagram element
*/ */
template <typename T = model::participant> template <typename T = model::participant>
common::optional_ref<T> get_participant( common::optional_ref<T> get_participant(common::id_t id) const
common::model::diagram_element::id_t id) const
{ {
if (diagram().participants().find(id) == diagram().participants().end()) if (diagram().participants().find(id) == diagram().participants().end())
return {}; return {};
@@ -241,8 +239,7 @@ public:
* @param local_id Local AST element id * @param local_id Local AST element id
* @param global_id Globa diagram element id * @param global_id Globa diagram element id
*/ */
void set_unique_id( void set_unique_id(int64_t local_id, common::id_t global_id);
int64_t local_id, common::model::diagram_element::id_t global_id);
/** /**
* @brief Retrieve the global `clang-uml` entity id based on the Clang * @brief Retrieve the global `clang-uml` entity id based on the Clang
@@ -250,8 +247,7 @@ public:
* @param local_id AST local element id * @param local_id AST local element id
* @return Global diagram element id * @return Global diagram element id
*/ */
std::optional<common::model::diagram_element::id_t> get_unique_id( std::optional<common::id_t> get_unique_id(int64_t local_id) const;
int64_t local_id) const;
/** /**
* @brief Finalize diagram model for this translation unit * @brief Finalize diagram model for this translation unit
@@ -531,7 +527,7 @@ private:
std::map<clang::CXXConstructExpr *, model::message> std::map<clang::CXXConstructExpr *, model::message>
construct_expr_message_map_; construct_expr_message_map_;
std::map<common::model::diagram_element::id_t, std::map<common::id_t,
std::unique_ptr<clanguml::sequence_diagram::model::class_>> std::unique_ptr<clanguml::sequence_diagram::model::class_>>
forward_declarations_; forward_declarations_;
@@ -539,7 +535,7 @@ private:
* @todo Refactor to @ref ast_id_mapper * @todo Refactor to @ref ast_id_mapper
*/ */
std::map</* local id from ->getID() */ int64_t, std::map</* local id from ->getID() */ int64_t,
/* global ID based on full name */ common::model::diagram_element::id_t> /* global ID based on full name */ common::id_t>
local_ast_id_map_; local_ast_id_map_;
std::map<int64_t /* local anonymous struct id */, std::map<int64_t /* local anonymous struct id */,

View File

@@ -76,8 +76,8 @@ public:
const std::vector<std::string> &system_include_paths() const; const std::vector<std::string> &system_include_paths() const;
private: private:
const std::string command_; std::string command_;
const std::string language_; std::string language_;
std::string target_; std::string target_;
std::vector<std::string> system_include_paths_; std::vector<std::string> system_include_paths_;
}; };