Added test case for subclass filter

This commit is contained in:
Bartek Kryza
2022-03-27 22:59:45 +02:00
parent 36065a7819
commit ece02c09df
6 changed files with 143 additions and 35 deletions

View File

@@ -48,6 +48,18 @@ 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(
const std::string &name) const
{
for (const auto &c : classes_) {
if (c.get().full_name(false) == name) {
return {c};
}
}
return type_safe::nullopt;
}
void diagram::add_type_alias(std::unique_ptr<type_alias> &&ta)
{
LOG_DBG(
@@ -107,6 +119,28 @@ void diagram::add_enum(std::unique_ptr<enum_> &&e)
LOG_DBG("Enum {} already in the model", e->name());
}
void diagram::get_parents(
std::unordered_set<type_safe::object_ref<const class_>> &parents) const
{
bool found_new = false;
for (const auto &parent : parents) {
for (const auto &rel : parent.get().relationships()) {
if (rel.type() == common::model::relationship_t::kExtension) {
const auto p = get_class(rel.destination());
if (p.has_value()) {
auto [it, found] = parents.emplace(p.value());
if (found)
found_new = true;
}
}
}
}
if (found_new) {
get_parents(parents);
}
}
std::string diagram::to_alias(const std::string &full_name) const
{
LOG_DBG("Looking for alias for {}", full_name);

View File

@@ -25,6 +25,7 @@
#include "type_alias.h"
#include <string>
#include <unordered_set>
#include <vector>
namespace clanguml::class_diagram::model {
@@ -48,6 +49,9 @@ public:
bool has_enum(const enum_ &e) const;
type_safe::optional_ref<const class_> get_class(
const std::string &name) const;
void add_type_alias(std::unique_ptr<type_alias> &&ta);
void add_class(std::unique_ptr<class_> &&c);
@@ -58,6 +62,9 @@ public:
std::string to_alias(const std::string &full_name) const;
void get_parents(
std::unordered_set<type_safe::object_ref<const class_>> &parents) const;
friend void print_diagram_tree(const diagram &d, const int level);
private:
@@ -66,3 +73,18 @@ private:
std::map<std::string, std::unique_ptr<type_alias>> type_aliases_;
};
}
namespace std {
template <>
struct hash<
type_safe::object_ref<const clanguml::class_diagram::model::class_>> {
std::size_t operator()(const type_safe::object_ref<
const clanguml::class_diagram::model::class_> &key) const
{
using clanguml::class_diagram::model::class_;
return std::hash<std::string>{}(key.get().full_name(false));
}
};
}