WIP
This commit is contained in:
@@ -23,11 +23,10 @@
|
||||
#include "common/model/element.h"
|
||||
#include "common/model/enums.h"
|
||||
#include "common/model/stylable_element.h"
|
||||
#include "common/types.h"
|
||||
#include "template_parameter.h"
|
||||
#include "type_alias.h"
|
||||
|
||||
#include <type_safe/reference.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -108,14 +107,14 @@ private:
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<
|
||||
type_safe::object_ref<const clanguml::class_diagram::model::class_>> {
|
||||
std::size_t operator()(const type_safe::object_ref<
|
||||
struct hash<std::reference_wrapper<
|
||||
const clanguml::class_diagram::model::class_>> {
|
||||
std::size_t operator()(const std::reference_wrapper<
|
||||
const clanguml::class_diagram::model::class_> &key) const
|
||||
{
|
||||
using clanguml::class_diagram::model::class_;
|
||||
using clanguml::common::id_t;
|
||||
|
||||
return std::hash<std::string>{}(key.get().full_name(false));
|
||||
return std::hash<id_t>{}(key.get().id());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/model/enums.h"
|
||||
#include "common/types.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -28,6 +29,11 @@ public:
|
||||
void set_name(const std::string &name);
|
||||
std::string name() const;
|
||||
|
||||
clanguml::common::id_t id() const noexcept { return id_; }
|
||||
void set_id(clanguml::common::id_t id) { id_ = id; }
|
||||
|
||||
void set_id(id_t id);
|
||||
|
||||
void is_virtual(bool is_virtual);
|
||||
bool is_virtual() const;
|
||||
|
||||
@@ -35,6 +41,7 @@ public:
|
||||
common::model::access_t access() const;
|
||||
|
||||
private:
|
||||
clanguml::common::id_t id_;
|
||||
std::string name_;
|
||||
bool is_virtual_{false};
|
||||
common::model::access_t access_;
|
||||
|
||||
@@ -25,12 +25,13 @@
|
||||
|
||||
namespace clanguml::class_diagram::model {
|
||||
|
||||
const std::vector<type_safe::object_ref<const class_>> &diagram::classes() const
|
||||
const std::vector<std::reference_wrapper<const class_>> &
|
||||
diagram::classes() const
|
||||
{
|
||||
return classes_;
|
||||
}
|
||||
|
||||
const std::vector<type_safe::object_ref<const enum_>> &diagram::enums() const
|
||||
const std::vector<std::reference_wrapper<const enum_>> &diagram::enums() const
|
||||
{
|
||||
return enums_;
|
||||
}
|
||||
@@ -40,10 +41,15 @@ common::model::diagram_t diagram::type() const
|
||||
return common::model::diagram_t::kClass;
|
||||
}
|
||||
|
||||
type_safe::optional_ref<const clanguml::common::model::diagram_element>
|
||||
std::optional<
|
||||
std::reference_wrapper<const clanguml::common::model::diagram_element>>
|
||||
diagram::get(const std::string &full_name) const
|
||||
{
|
||||
type_safe::optional_ref<const clanguml::common::model::diagram_element> res;
|
||||
// type_safe::optional_ref<const clanguml::common::model::diagram_element>
|
||||
// res;
|
||||
std::optional<
|
||||
std::reference_wrapper<const clanguml::common::model::diagram_element>>
|
||||
res;
|
||||
|
||||
res = get_class(full_name);
|
||||
|
||||
@@ -67,7 +73,7 @@ bool diagram::has_enum(const enum_ &e) const
|
||||
[&e](const auto &ee) { return ee.get().full_name() == e.full_name(); });
|
||||
}
|
||||
|
||||
type_safe::optional_ref<const class_> diagram::get_class(
|
||||
std::optional<std::reference_wrapper<const class_>> diagram::get_class(
|
||||
const std::string &name) const
|
||||
{
|
||||
for (const auto &c : classes_) {
|
||||
@@ -76,10 +82,10 @@ type_safe::optional_ref<const class_> diagram::get_class(
|
||||
}
|
||||
}
|
||||
|
||||
return type_safe::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
type_safe::optional_ref<const enum_> diagram::get_enum(
|
||||
std::optional<std::reference_wrapper<const enum_>> diagram::get_enum(
|
||||
const std::string &name) const
|
||||
{
|
||||
for (const auto &e : enums_) {
|
||||
@@ -88,7 +94,7 @@ type_safe::optional_ref<const enum_> diagram::get_enum(
|
||||
}
|
||||
}
|
||||
|
||||
return type_safe::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
void diagram::add_type_alias(std::unique_ptr<type_alias> &&ta)
|
||||
@@ -131,7 +137,7 @@ bool diagram::add_class(std::unique_ptr<class_> &&c)
|
||||
auto name_and_ns = ns | name;
|
||||
const auto &cc = *c;
|
||||
|
||||
auto cc_ref = type_safe::ref(cc);
|
||||
auto cc_ref = std::ref(cc);
|
||||
|
||||
if (!has_class(cc)) {
|
||||
if (add_element(ns, std::move(c)))
|
||||
@@ -159,7 +165,7 @@ bool diagram::add_enum(std::unique_ptr<enum_> &&e)
|
||||
|
||||
assert(!util::contains(e->name(), "::"));
|
||||
|
||||
auto e_ref = type_safe::ref(*e);
|
||||
auto e_ref = std::ref(*e);
|
||||
auto ns = e->get_relative_namespace();
|
||||
|
||||
if (!has_enum(*e)) {
|
||||
@@ -175,9 +181,9 @@ bool diagram::add_enum(std::unique_ptr<enum_> &&e)
|
||||
}
|
||||
|
||||
void diagram::get_parents(
|
||||
std::unordered_set<type_safe::object_ref<const class_>> &parents) const
|
||||
clanguml::common::reference_set<class_> &parents) const
|
||||
{
|
||||
bool found_new = false;
|
||||
bool found_new{false};
|
||||
for (const auto &parent : parents) {
|
||||
for (const auto &pp : parent.get().parents()) {
|
||||
const auto p = get_class(pp.name());
|
||||
@@ -194,25 +200,39 @@ void diagram::get_parents(
|
||||
}
|
||||
}
|
||||
|
||||
std::string diagram::to_alias(const std::string &full_name) const
|
||||
bool diagram::has_element(
|
||||
clanguml::common::model::diagram_element::id_t id) const
|
||||
{
|
||||
LOG_DBG("Looking for alias for {}", full_name);
|
||||
for (const auto &c : classes_) {
|
||||
if (c.get().id() == id)
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const auto &c : enums_) {
|
||||
if (c.get().id() == id)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string diagram::to_alias(
|
||||
clanguml::common::model::diagram_element::id_t id) const
|
||||
{
|
||||
LOG_DBG("Looking for alias for {}", id);
|
||||
|
||||
for (const auto &c : classes_) {
|
||||
const auto &cc = c.get();
|
||||
if (cc.full_name() == full_name) {
|
||||
return c->alias();
|
||||
if (c.get().id() == id) {
|
||||
return c.get().alias();
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &e : enums_) {
|
||||
if (e.get().full_name() == full_name) {
|
||||
return e->alias();
|
||||
}
|
||||
if (e.get().id() == id)
|
||||
return e.get().alias();
|
||||
}
|
||||
|
||||
throw error::uml_alias_missing(
|
||||
fmt::format("Missing alias for {}", full_name));
|
||||
throw error::uml_alias_missing(fmt::format("Missing alias for {}", id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "common/model/diagram.h"
|
||||
#include "common/model/nested_trait.h"
|
||||
#include "common/model/package.h"
|
||||
#include "common/types.h"
|
||||
#include "enum.h"
|
||||
#include "type_alias.h"
|
||||
|
||||
@@ -44,21 +45,22 @@ public:
|
||||
|
||||
common::model::diagram_t type() const override;
|
||||
|
||||
type_safe::optional_ref<const clanguml::common::model::diagram_element> get(
|
||||
const std::string &full_name) const override;
|
||||
std::optional<
|
||||
std::reference_wrapper<const clanguml::common::model::diagram_element>>
|
||||
get(const std::string &full_name) const override;
|
||||
|
||||
const std::vector<type_safe::object_ref<const class_>> &classes() const;
|
||||
const std::vector<std::reference_wrapper<const class_>> &classes() const;
|
||||
|
||||
const std::vector<type_safe::object_ref<const enum_>> &enums() const;
|
||||
const std::vector<std::reference_wrapper<const enum_>> &enums() const;
|
||||
|
||||
bool has_class(const class_ &c) const;
|
||||
|
||||
bool has_enum(const enum_ &e) const;
|
||||
|
||||
type_safe::optional_ref<const class_> get_class(
|
||||
std::optional<std::reference_wrapper<const class_>> get_class(
|
||||
const std::string &name) const;
|
||||
|
||||
type_safe::optional_ref<const enum_> get_enum(
|
||||
std::optional<std::reference_wrapper<const enum_>> get_enum(
|
||||
const std::string &name) const;
|
||||
|
||||
void add_type_alias(std::unique_ptr<type_alias> &&ta);
|
||||
@@ -69,16 +71,22 @@ public:
|
||||
|
||||
bool add_package(std::unique_ptr<common::model::package> &&p);
|
||||
|
||||
std::string to_alias(const std::string &full_name) const;
|
||||
std::string to_alias(
|
||||
clanguml::common::model::diagram_element::id_t id) const;
|
||||
|
||||
void get_parents(
|
||||
std::unordered_set<type_safe::object_ref<const class_>> &parents) const;
|
||||
void get_parents(clanguml::common::reference_set<class_> &parents) const;
|
||||
|
||||
friend void print_diagram_tree(const diagram &d, const int level);
|
||||
|
||||
bool has_element(
|
||||
const clanguml::common::model::diagram_element::id_t id) const override;
|
||||
|
||||
private:
|
||||
std::vector<type_safe::object_ref<const class_, false>> classes_;
|
||||
std::vector<type_safe::object_ref<const enum_, false>> enums_;
|
||||
std::vector<std::reference_wrapper<const class_>> classes_;
|
||||
std::vector<std::reference_wrapper<const enum_>> enums_;
|
||||
|
||||
// std::vector<type_safe::object_ref<const class_, false>> classes_;
|
||||
// std::vector<type_safe::object_ref<const enum_, false>> enums_;
|
||||
std::map<std::string, std::unique_ptr<type_alias>> type_aliases_;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user