Fixed rendering of member variables with alias to template or alias template (t00014)
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "util/util.h"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
std::atomic_uint64_t element::m_nextId = 1;
|
||||
@@ -28,6 +30,8 @@ element::element(const std::vector<std::string> &using_namespaces)
|
||||
: using_namespaces_{using_namespaces}
|
||||
, m_id{m_nextId++}
|
||||
{
|
||||
for (const auto &n : using_namespaces_)
|
||||
assert(!util::contains(n, "::"));
|
||||
}
|
||||
|
||||
std::string element::alias() const { return fmt::format("C_{:010}", m_id); }
|
||||
@@ -41,6 +45,13 @@ void element::add_relationship(relationship &&cr)
|
||||
return;
|
||||
}
|
||||
|
||||
if ((cr.type() == relationship_t::kInstantiation) &&
|
||||
(cr.destination() == full_name(true))) {
|
||||
LOG_WARN("Skipping self instantiation relationship for {}",
|
||||
cr.destination());
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_DBG("Adding relationship: '{}' - {} - '{}'", cr.destination(),
|
||||
to_string(cr.type()), full_name(true));
|
||||
|
||||
@@ -50,6 +61,9 @@ void element::add_relationship(relationship &&cr)
|
||||
|
||||
void element::set_using_namespaces(const std::vector<std::string> &un)
|
||||
{
|
||||
for (const auto &n : un)
|
||||
assert(!util::contains(n, "::"));
|
||||
|
||||
using_namespaces_ = un;
|
||||
}
|
||||
|
||||
@@ -71,4 +85,14 @@ bool operator==(const element &l, const element &r)
|
||||
{
|
||||
return l.full_name(false) == r.full_name(false);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const element &rhs)
|
||||
{
|
||||
out << "(" << rhs.name() << ", ns=["
|
||||
<< util::join(rhs.get_namespace(), "::") << "], full_name=["
|
||||
<< rhs.full_name(true) << "])";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
|
||||
#include "decorated_element.h"
|
||||
#include "relationship.h"
|
||||
#include "util/util.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -38,10 +40,24 @@ public:
|
||||
|
||||
std::string name() const { return name_; }
|
||||
|
||||
std::string name_and_ns() const
|
||||
{
|
||||
auto ns = namespace_;
|
||||
ns.push_back(name());
|
||||
return util::join(ns, "::");
|
||||
}
|
||||
|
||||
void set_namespace(const std::vector<std::string> &ns) { namespace_ = ns; }
|
||||
|
||||
std::vector<std::string> get_namespace() const { return namespace_; }
|
||||
|
||||
std::vector<std::string> get_relative_namespace() const
|
||||
{
|
||||
auto relative_ns = namespace_;
|
||||
util::remove_prefix(relative_ns, using_namespaces_);
|
||||
return relative_ns;
|
||||
}
|
||||
|
||||
virtual std::string full_name(bool relative) const { return name(); }
|
||||
|
||||
void set_using_namespaces(const std::vector<std::string> &un);
|
||||
@@ -58,6 +74,8 @@ public:
|
||||
|
||||
friend bool operator==(const element &l, const element &r);
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &out, const element &rhs);
|
||||
|
||||
protected:
|
||||
const uint64_t m_id{0};
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <type_safe/optional_ref.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -55,7 +56,7 @@ public:
|
||||
{
|
||||
assert(p);
|
||||
|
||||
LOG_DBG("Adding nested element {} at path '{}'", p->name(),
|
||||
LOG_DBG("Adding nested element {} at path {}", p->name(),
|
||||
fmt::join(path, "::"));
|
||||
|
||||
if (path.empty()) {
|
||||
@@ -68,9 +69,11 @@ public:
|
||||
if (parent && dynamic_cast<nested_trait<T> *>(&parent.value()))
|
||||
dynamic_cast<nested_trait<T> &>(parent.value())
|
||||
.template add_element<V>(std::move(p));
|
||||
else
|
||||
else {
|
||||
spdlog::error(
|
||||
"No parent element found at: {}", fmt::join(path, "::"));
|
||||
throw std::runtime_error("No parent element found");
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V = T>
|
||||
@@ -105,7 +108,7 @@ public:
|
||||
[&](const auto &p) { return name == p->name(); });
|
||||
|
||||
if (it == elements_.end())
|
||||
return type_safe::optional_ref<V>{};
|
||||
return type_safe::optional_ref<V>{type_safe::nullopt};
|
||||
|
||||
assert(it->get() != nullptr);
|
||||
|
||||
@@ -113,7 +116,7 @@ public:
|
||||
return type_safe::optional_ref<V>{
|
||||
type_safe::ref<V>(dynamic_cast<V &>(*it->get()))};
|
||||
|
||||
return type_safe::optional_ref<V>{};
|
||||
return type_safe::optional_ref<V>{type_safe::nullopt};
|
||||
}
|
||||
|
||||
bool has_element(const std::string &name) const
|
||||
@@ -132,6 +135,24 @@ public:
|
||||
auto begin() const { return elements_.begin(); }
|
||||
auto end() const { return elements_.end(); }
|
||||
|
||||
void print_tree(const int level)
|
||||
{
|
||||
const auto &d = *this;
|
||||
|
||||
if (level == 0) {
|
||||
std::cout << "--- Printing tree:\n";
|
||||
}
|
||||
for (const auto &e : d) {
|
||||
if (dynamic_cast<nested_trait<T> *>(e.get())) {
|
||||
std::cout << std::string(level, ' ') << "[" << *e << "]\n";
|
||||
dynamic_cast<nested_trait<T> *>(e.get())->print_tree(level + 1);
|
||||
}
|
||||
else {
|
||||
std::cout << std::string(level, ' ') << "- " << *e << "]\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<T>> elements_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user