Removed cppast dependency

This commit is contained in:
Bartek Kryza
2022-08-03 22:12:08 +02:00
parent 5917d341e2
commit 487e5d435b
46 changed files with 167 additions and 1230 deletions

View File

@@ -163,9 +163,9 @@ void generator<C, D>::generate_config_layout_hints(std::ostream &ostr) const
if (!element_opt || !hint_element_opt)
continue;
hint_str << element_opt.value().get().alias() << " -[hidden]"
hint_str << element_opt.value().alias() << " -[hidden]"
<< clanguml::config::to_string(hint.hint) << "- "
<< hint_element_opt.value().get().alias() << '\n';
<< hint_element_opt.value().alias() << '\n';
ostr << hint_str.str();
}
catch (clanguml::error::uml_alias_missing &e) {
@@ -196,8 +196,7 @@ void generator<C, D>::generate_plantuml_directives(
if (element_opt)
directive.replace(std::get<1>(alias_match),
std::get<2>(alias_match),
element_opt.value().get().alias());
std::get<2>(alias_match), element_opt.value().alias());
else {
LOG_ERROR(
"CANNOT FIND ALIAS TO ELEMENT {}", full_name.to_string());
@@ -426,7 +425,7 @@ template <typename C, typename D> void generator<C, D>::init_env()
m_config.using_namespace() | args[0]->get<std::string>();
auto element_opt = m_model.get(alias_match.to_string());
return element_opt.value().get().alias();
return element_opt.value().alias();
});
m_env.add_callback("comment", 1, [this](inja::Arguments &args) {
@@ -441,7 +440,7 @@ template <typename C, typename D> void generator<C, D>::init_env()
}
if (element.has_value()) {
auto comment = element.value().get().comment();
auto comment = element.value().comment();
if (comment.has_value())
res = comment.value();

View File

@@ -39,13 +39,11 @@ public:
virtual diagram_t type() const = 0;
virtual std::optional<
std::reference_wrapper<clanguml::common::model::diagram_element>>
get(const std::string &full_name) const = 0;
virtual common::optional_ref<clanguml::common::model::diagram_element> get(
const std::string &full_name) const = 0;
virtual std::optional<
std::reference_wrapper<clanguml::common::model::diagram_element>>
get(const diagram_element::id_t id) const = 0;
virtual common::optional_ref<clanguml::common::model::diagram_element> get(
const diagram_element::id_t id) const = 0;
diagram(const diagram &) = delete;
diagram(diagram &&);

View File

@@ -295,25 +295,25 @@ tvl::value_t context_filter::match(const diagram &d, const element &e) const
if (context_root.has_value()) {
// This is a direct match to the context root
if (context_root.value().get().id() == e.id())
if (context_root.value().id() == e.id())
return true;
// Return a positive match if the element e is in a direct
// relationship with any of the context_root's
for (const relationship &rel :
context_root.value().get().relationships()) {
context_root.value().relationships()) {
if (rel.destination() == e.id())
return true;
}
for (const relationship &rel : e.relationships()) {
if (rel.destination() == context_root.value().get().id())
if (rel.destination() == context_root.value().id())
return true;
}
// Return a positive match if the context_root is a parent
// of the element
for (const class_diagram::model::class_parent &p :
context_root.value().get().parents()) {
context_root.value().parents()) {
if (p.name() == e.full_name(false))
return true;
}
@@ -322,8 +322,7 @@ tvl::value_t context_filter::match(const diagram &d, const element &e) const
for (const class_diagram::model::class_parent &p :
static_cast<const class_diagram::model::class_ &>(e)
.parents()) {
if (p.name() ==
context_root.value().get().full_name(false))
if (p.name() == context_root.value().full_name(false))
return true;
}
}

View File

@@ -221,7 +221,7 @@ private:
while (parent.has_value()) {
parents.emplace(std::ref(parent.value()));
parent = detail::get<ElementT, DiagramT>(
cd, parent.value().get().path().to_string());
cd, parent.value().path().to_string());
}
});

View File

@@ -19,8 +19,8 @@
#include "path.h"
#include <optional>
#include <string>
#include <type_safe/optional.hpp>
#include <vector>
namespace clanguml::common::model {

View File

@@ -19,9 +19,8 @@
#include "util/util.h"
#include <type_safe/optional_ref.hpp>
#include <iostream>
#include <optional>
#include <string>
#include <vector>
@@ -84,7 +83,7 @@ public:
if (path.is_empty() || !has_element(path[0])) {
LOG_DBG("Nested element {} not found in element", path.to_string());
return type_safe::optional_ref<V>{};
return optional_ref<V>{};
}
if (path.size() == 1) {
@@ -94,13 +93,13 @@ public:
auto p = get_element<T>(path[0]);
if (!p)
return type_safe::optional_ref<V>{};
return optional_ref<V>{};
if (dynamic_cast<nested_trait<T, Path> *>(&p.value()))
return dynamic_cast<nested_trait<T, Path> &>(p.value())
.get_element<V>(Path{path.begin() + 1, path.end()});
return type_safe::optional_ref<V>{};
return optional_ref<V>{};
}
template <typename V = T> auto get_element_parent(const T &element) const
@@ -109,10 +108,10 @@ public:
auto parent = get_element(path);
if (parent.has_value())
return type_safe::optional_ref<V>{
type_safe::ref<V>(dynamic_cast<V &>(parent.value()))};
return optional_ref<V>{
std::ref<V>(dynamic_cast<V &>(parent.value()))};
return type_safe::optional_ref<V>{};
return optional_ref<V>{};
}
template <typename V = T> auto get_element(const std::string &name) const
@@ -123,15 +122,14 @@ public:
[&](const auto &p) { return name == p->name(); });
if (it == elements_.end())
return type_safe::optional_ref<V>{type_safe::nullopt};
return optional_ref<V>{};
assert(it->get() != nullptr);
if (dynamic_cast<V *>(it->get()))
return type_safe::optional_ref<V>{
type_safe::ref<V>(dynamic_cast<V &>(*it->get()))};
return optional_ref<V>{std::ref<V>(dynamic_cast<V &>(*it->get()))};
return type_safe::optional_ref<V>{type_safe::nullopt};
return optional_ref<V>{};
}
bool has_element(const std::string &name) const

View File

@@ -24,7 +24,6 @@
#include "util/util.h"
#include <spdlog/spdlog.h>
#include <type_safe/optional_ref.hpp>
#include <set>
#include <string>

View File

@@ -19,8 +19,8 @@
#include "util/util.h"
#include <optional>
#include <string>
#include <type_safe/optional.hpp>
#include <vector>
namespace clanguml::common::model {
@@ -130,7 +130,7 @@ public:
void pop_back() { path_.pop_back(); }
type_safe::optional<path> parent() const
std::optional<path> parent() const
{
if (size() <= 1) {
return {};

View File

@@ -27,7 +27,6 @@
#include "util/util.h"
#include <spdlog/spdlog.h>
#include <type_safe/optional_ref.hpp>
#include <set>
#include <string>

View File

@@ -17,6 +17,7 @@
*/
#pragma once
#include <cassert>
#include <cstdint>
#include <optional>
#include <unordered_set>
@@ -26,8 +27,89 @@ namespace clanguml::common {
using id_t = int64_t;
template <typename T>
using optional_ref = std::optional<std::reference_wrapper<T>>;
template <typename T> class optional_ref {
public:
using optional_type = T;
optional_ref()
: value_{nullptr}
{
}
optional_ref(T &value) { value_ = &value; }
optional_ref(const T &value) { value_ = &value; }
optional_ref(optional_ref &right) { value_ = right.get(); }
template <typename V,
typename = std::enable_if<
std::is_base_of_v<optional_type, typename V::optional_type> ||
std::is_same_v<optional_type, typename V::optional_type>>>
optional_ref(const V &t)
{
value_ = t.get();
}
template <typename V,
typename = std::enable_if<
std::is_base_of_v<optional_type, typename V::optional_type> ||
std::is_same_v<optional_type, typename V::optional_type>>>
optional_ref(V &&t)
{
value_ = t.get();
t.reset();
}
template <typename V,
typename = std::enable_if<std::is_base_of_v<optional_type, V>>>
optional_ref(const std::reference_wrapper<V> &t)
{
value_ = &t.get();
}
optional_ref &operator=(const optional_ref &right)
{
if (this == &right)
return *this;
value_ = right.value_;
return *this;
}
optional_ref &operator=(optional_ref &&right) noexcept
{
if (this == &right)
return *this;
value_ = right.value_;
right.reset();
return *this;
}
bool has_value() const noexcept { return value_ != nullptr; }
operator bool() const noexcept { return has_value(); }
const T &value() const
{
assert(value_ != nullptr);
return *value_;
}
T &value()
{
assert(value_ != nullptr);
return *value_;
}
void reset() { value_ = nullptr; }
T *get() const { return value_; }
private:
T *value_;
};
template <typename T>
using reference_vector = std::vector<std::reference_wrapper<T>>;