Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor id t #285

Merged
merged 8 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ format:

.PHONY: debug_tidy
tidy: debug_tidy
run-clang-tidy-15 -extra-arg=-Wno-unknown-warning-option -j $(NUMPROC) -p debug_tidy ./src
run-clang-tidy-17 -extra-arg=-Wno-unknown-warning-option -j $(NUMPROC) -p debug_tidy ./src

.PHONY: check-formatting
check-formatting:
Expand Down
10 changes: 5 additions & 5 deletions src/class_diagram/generators/json/class_diagram_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void to_json(nlohmann::json &j, const class_method &c)
void to_json(nlohmann::json &j, const class_parent &c)
{
j["is_virtual"] = c.is_virtual();
j["id"] = std::to_string(c.id());
j["id"] = std::to_string(c.id().value());
if (c.access() != common::model::access_t::kNone)
j["access"] = to_string(c.access());
j["name"] = c.name();
Expand Down Expand Up @@ -331,7 +331,7 @@ void generator::generate_relationships(
}

nlohmann::json rel = r;
rel["source"] = std::to_string(c.id());
rel["source"] = std::to_string(c.id().value());
parent["relationships"].push_back(rel);
}

Expand All @@ -340,7 +340,7 @@ void generator::generate_relationships(
common::model::relationship r(
relationship_t::kExtension, b.id(), b.access());
nlohmann::json rel = r;
rel["source"] = std::to_string(c.id());
rel["source"] = std::to_string(c.id().value());
parent["relationships"].push_back(rel);
}
}
Expand All @@ -362,7 +362,7 @@ void generator::generate_relationships(
}

nlohmann::json rel = r;
rel["source"] = std::to_string(c.id());
rel["source"] = std::to_string(c.id().value());
parent["relationships"].push_back(rel);
}
}
Expand All @@ -383,7 +383,7 @@ void generator::generate_relationships(
}

nlohmann::json rel = r;
rel["source"] = std::to_string(c.id());
rel["source"] = std::to_string(c.id().value());
parent["relationships"].push_back(rel);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace clanguml::class_diagram::generators::mermaid {

using clanguml::common::eid_t;
using clanguml::common::generators::mermaid::indent;
using clanguml::common::generators::mermaid::render_name;

Expand Down Expand Up @@ -405,7 +406,7 @@ void generator::generate_relationships(
LOG_DBG("== Processing relationship {}", to_string(r.type()));

std::stringstream relstr;
clanguml::common::id_t destination{0};
eid_t destination{};
try {
destination = r.destination();

Expand Down Expand Up @@ -513,7 +514,7 @@ void generator::generate_relationships(
LOG_DBG("== Processing relationship {}", to_string(r.type()));

std::stringstream relstr;
clanguml::common::id_t destination{0};
eid_t destination{};
try {
destination = r.destination();

Expand Down Expand Up @@ -584,7 +585,7 @@ void generator::generate_relationships(const enum_ &e, std::ostream &ostr) const
if (!model().should_include(r.type()))
continue;

clanguml::common::id_t destination{0};
eid_t destination{};
std::stringstream relstr;
try {
destination = r.destination();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ void generator::generate_relationships(
plantuml_common::to_plantuml(r, config()));

std::stringstream relstr;
clanguml::common::id_t destination{0};
eid_t destination{};
try {
destination = r.destination();

Expand Down Expand Up @@ -583,7 +583,7 @@ void generator::generate_relationships(
LOG_DBG("== Processing relationship {}", to_string(r.type()));

std::stringstream relstr;
clanguml::common::id_t destination{0};
eid_t destination{};
try {
destination = r.destination();

Expand Down Expand Up @@ -664,7 +664,7 @@ void generator::generate_relationships(const enum_ &e, std::ostream &ostr) const
if (!model().should_include(r.type()))
continue;

clanguml::common::id_t destination{0};
eid_t destination{};
std::stringstream relstr;
try {
destination = r.destination();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ using clanguml::class_diagram::model::class_member;
using clanguml::class_diagram::model::class_method;
using clanguml::class_diagram::model::concept_;
using clanguml::class_diagram::model::enum_;
using clanguml::common::eid_t;
using clanguml::common::model::access_t;
using clanguml::common::model::package;
using clanguml::common::model::relationship;
Expand Down
4 changes: 1 addition & 3 deletions src/class_diagram/model/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ struct hash<std::reference_wrapper<clanguml::class_diagram::model::class_>> {
const std::reference_wrapper<clanguml::class_diagram::model::class_>
&key) const
{
using clanguml::common::id_t;

return std::hash<id_t>{}(key.get().id());
return std::hash<uint64_t>{}(key.get().id().value());
}
};
} // namespace std
4 changes: 2 additions & 2 deletions src/class_diagram/model/class_parent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void class_parent::set_name(const std::string &name) { name_ = name; }

std::string class_parent::name() const { return name_; }

void class_parent::set_id(clanguml::common::id_t id) { id_ = id; }
void class_parent::set_id(eid_t id) { id_ = id; }

clanguml::common::id_t class_parent::id() const noexcept { return id_; }
eid_t class_parent::id() const noexcept { return id_; }

void class_parent::is_virtual(bool is_virtual) { is_virtual_ = is_virtual; }

Expand Down
8 changes: 5 additions & 3 deletions src/class_diagram/model/class_parent.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace clanguml::class_diagram::model {

using clanguml::common::eid_t;

/**
* @brief Class parent relationship model.
*
Expand Down Expand Up @@ -59,14 +61,14 @@ class class_parent {
*
* @param id Id of the parent class.
*/
void set_id(clanguml::common::id_t id);
void set_id(eid_t id);

/**
* @brief Get the id of class parent.
*
* @return Id of the parent class.
*/
clanguml::common::id_t id() const noexcept;
eid_t id() const noexcept;

/**
* @brief Set whether the parent is virtual.
Expand Down Expand Up @@ -97,7 +99,7 @@ class class_parent {
common::model::access_t access() const;

private:
clanguml::common::id_t id_{};
eid_t id_{};
std::string name_;
bool is_virtual_{false};
common::model::access_t access_{common::model::access_t::kPublic};
Expand Down
10 changes: 5 additions & 5 deletions src/class_diagram/model/diagram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
}

common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
const clanguml::common::id_t id) const
const eid_t id) const
{
common::optional_ref<clanguml::common::model::diagram_element> res;

Expand Down Expand Up @@ -153,7 +153,7 @@ void diagram::get_parents(
}
}

bool diagram::has_element(clanguml::common::id_t id) const
bool diagram::has_element(eid_t id) const
{
const auto has_class = std::any_of(classes().begin(), classes().end(),
[id](const auto &c) { return c.get().id() == id; });
Expand All @@ -171,7 +171,7 @@ bool diagram::has_element(clanguml::common::id_t id) const
[id](const auto &c) { return c.get().id() == id; });
}

std::string diagram::to_alias(clanguml::common::id_t id) const
std::string diagram::to_alias(eid_t id) const
{
LOG_DBG("Looking for alias for {}", id);

Expand Down Expand Up @@ -224,12 +224,12 @@ inja::json diagram::context() const

void diagram::remove_redundant_dependencies()
{
using common::id_t;
using common::eid_t;
using common::model::relationship;
using common::model::relationship_t;

for (auto &c : element_view<class_>::view()) {
std::set<id_t> dependency_relationships_to_remove;
std::set<eid_t> dependency_relationships_to_remove;

for (auto &r : c.get().relationships()) {
if (r.type() != relationship_t::kDependency)
Expand Down
11 changes: 5 additions & 6 deletions src/class_diagram/model/diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class diagram : public common::model::diagram,
* @param id Element id.
* @return Optional reference to a diagram element.
*/
opt_ref<diagram_element> get(common::id_t id) const override;
opt_ref<diagram_element> get(eid_t id) const override;

/**
* @brief Get list of references to classes in the diagram model.
Expand Down Expand Up @@ -172,7 +172,7 @@ class diagram : public common::model::diagram,
* @param id Id of the element
* @return Optional reference to a diagram element
*/
template <typename ElementT> opt_ref<ElementT> find(common::id_t id) const;
template <typename ElementT> opt_ref<ElementT> find(eid_t id) const;

/**
* @brief Get reference to vector of elements of specific type
Expand Down Expand Up @@ -218,7 +218,7 @@ class diagram : public common::model::diagram,
* @param id Id of the diagram element.
* @return PlantUML alias.
*/
std::string to_alias(common::id_t id) const;
std::string to_alias(eid_t id) const;

/**
* @brief Given an initial set of classes, add all their parents to the
Expand All @@ -235,7 +235,7 @@ class diagram : public common::model::diagram,
* @param id Id of the element.
* @return True, if diagram contains an element with a specific id.
*/
bool has_element(common::id_t id) const override;
bool has_element(eid_t id) const override;

/**
* @brief Remove redundant dependency relationships
Expand Down Expand Up @@ -431,8 +431,7 @@ std::vector<opt_ref<ElementT>> diagram::find(
return result;
}

template <typename ElementT>
opt_ref<ElementT> diagram::find(common::id_t id) const
template <typename ElementT> opt_ref<ElementT> diagram::find(eid_t id) const
{
for (const auto &element : element_view<ElementT>::view()) {
if (element.get().id() == id) {
Expand Down
Loading
Loading