Initial refactor of id_t to a separate class

This commit is contained in:
Bartek Kryza
2024-06-04 00:03:26 +02:00
parent e21c2d2b14
commit cf79b3184c
37 changed files with 374 additions and 248 deletions

View File

@@ -26,7 +26,7 @@ namespace clanguml::common::model {
diagram_element::diagram_element() = default;
common::id_t diagram_element::id() const { return id_; }
const common::id_t & diagram_element::id() const { return id_; }
void diagram_element::set_id(common::id_t id) { id_ = id; }
@@ -42,9 +42,9 @@ void diagram_element::set_parent_element_id(common::id_t id)
std::string diagram_element::alias() const
{
assert(id_ >= 0);
assert(id_.value() >= 0);
return fmt::format("C_{:022}", id_);
return fmt::format("C_{:022}", id_.value());
}
void diagram_element::add_relationship(relationship &&cr)

View File

@@ -53,7 +53,7 @@ public:
*
* @return Elements id.
*/
common::id_t id() const;
const common::id_t& id() const;
/**
* Set elements id.
@@ -185,8 +185,8 @@ public:
void complete(bool completed);
private:
id_t id_{0};
std::optional<id_t> parent_element_id_{0};
id_t id_{};
std::optional<common::id_t> parent_element_id_{};
std::string name_;
std::vector<relationship> relationships_;
bool nested_{false};

View File

@@ -55,7 +55,8 @@ template <typename ElementT, typename DiagramT>
const clanguml::common::optional_ref<ElementT> get(
const DiagramT &d, const std::string &full_name);
template <typename ElementT> int64_t destination_comparator(const ElementT &e)
template <typename ElementT>
common::id_t destination_comparator(const ElementT &e)
{
return e.id();
}

View File

@@ -91,7 +91,7 @@ struct hash<std::reference_wrapper<clanguml::common::model::package>> {
{
using clanguml::common::id_t;
return std::hash<id_t>{}(key.get().id());
return std::hash<id_t::type>{}(key.get().id().value());
}
};
} // namespace std

View File

@@ -22,7 +22,7 @@
namespace clanguml::common::model {
relationship::relationship(relationship_t type, int64_t destination,
relationship::relationship(relationship_t type, common::id_t destination,
access_t access, std::string label, std::string multiplicity_source,
std::string multiplicity_destination)
: type_{type}
@@ -38,7 +38,7 @@ void relationship::set_type(relationship_t type) noexcept { type_ = type; }
relationship_t relationship::type() const noexcept { return type_; }
void relationship::set_destination(int64_t destination)
void relationship::set_destination(common::id_t destination)
{
destination_ = destination;
}

View File

@@ -74,14 +74,14 @@ public:
*
* @param destination Target element id.
*/
void set_destination(int64_t destination);
void set_destination(common::id_t destination);
/**
* Get the id of the target element of this relationship.
*
* @return Target element id.
*/
clanguml::common::id_t destination() const;
common::id_t destination() const;
/**
* Set the relationship multiplicity at the source.

View File

@@ -212,7 +212,7 @@ struct hash<std::reference_wrapper<clanguml::common::model::source_file>> {
{
using clanguml::common::id_t;
return std::hash<id_t>{}(key.get().id());
return std::hash<id_t::type>{}(key.get().id().value());
}
};
} // namespace std

View File

@@ -505,7 +505,7 @@ std::string template_parameter::to_string(
}
bool template_parameter::find_nested_relationships(
std::vector<std::pair<int64_t, common::model::relationship_t>>
std::vector<std::pair<common::id_t, common::model::relationship_t>>
&nested_relationships,
common::model::relationship_t hint,
const std::function<bool(const std::string &full_name)> &should_include)

View File

@@ -19,6 +19,7 @@
#include "common/model/enums.h"
#include "common/model/namespace.h"
#include "common/types.h"
#include <deque>
#include <optional>
@@ -165,14 +166,14 @@ public:
*
* @param id Id of parameter
*/
void set_id(const int64_t id) { id_ = id; }
void set_id(const common::id_t &id) { id_ = id; }
/**
* Get id of the template parameter
*
* @return Id of the template parameter
*/
const std::optional<int64_t> &id() const { return id_; }
const std::optional<common::id_t> &id() const { return id_; }
/**
* Set the name of the template parameter
@@ -388,7 +389,7 @@ public:
* @return
*/
bool find_nested_relationships(
std::vector<std::pair<int64_t, common::model::relationship_t>>
std::vector<std::pair<common::id_t, common::model::relationship_t>>
&nested_relationships,
common::model::relationship_t hint,
const std::function<bool(const std::string &full_name)> &should_include)
@@ -532,7 +533,7 @@ private:
*/
std::vector<template_parameter> template_params_;
std::optional<int64_t> id_;
std::optional<common::id_t> id_;
bool is_unexposed_{false};
};