From efa98379b00f16454bb6ca397f298a836319691e Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Fri, 24 Sep 2021 12:24:47 +0200 Subject: [PATCH] meta: internal changes and cleanup --- src/entt/meta/factory.hpp | 6 +++--- src/entt/meta/meta.hpp | 11 +++++++++-- src/entt/meta/node.hpp | 22 +--------------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index c8e328cdb..b59584593 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -272,7 +272,7 @@ public: static internal::meta_conv_node node{ nullptr, internal::meta_node::resolve(), - [](const void *instance) -> meta_any { return forward_as_meta(static_cast(instance)->*Candidate)(); } + [](const meta_any &instance) -> meta_any { return forward_as_meta(static_cast(instance.data())->*Candidate)(); } // tricks clang-format }; @@ -288,7 +288,7 @@ public: static internal::meta_conv_node node{ nullptr, internal::meta_node::resolve(), - [](const void *instance) -> meta_any { return forward_as_meta(Candidate(*static_cast(instance))); } + [](const meta_any &instance) -> meta_any { return forward_as_meta(Candidate(*static_cast(instance.data()))); } // tricks clang-format }; @@ -312,7 +312,7 @@ public: static internal::meta_conv_node node{ nullptr, internal::meta_node>>::resolve(), - [](const void *instance) -> meta_any { return forward_as_meta(static_cast(*static_cast(instance))); } + [](const meta_any &instance) -> meta_any { return forward_as_meta(static_cast(*static_cast(instance.data()))); } // tricks clang-format }; diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index d399ff512..05fd5768a 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -971,7 +971,14 @@ class meta_type { for(size_type next{}; next < sz && next == (direct + ext) && args[next]; ++next) { const auto type = args[next].type(); const auto other = curr->arg(next); - type.info() == other.info() ? ++direct : (ext += internal::can_cast_or_convert(type.node, other.node)); + + if(const auto &info = other.info(); info == type.info()) { + ++direct; + } else { + ext += internal::find_by<&node_type::base>(info, type.node) + || internal::find_by<&node_type::conv>(info, type.node) + || (type.node->conversion_helper && other.node->conversion_helper); + } } if((direct + ext) == sz) { @@ -1381,7 +1388,7 @@ bool meta_any::set(const id_type id, Type &&value) { if(const auto &info = type.info(); (node && *node->info == info) || internal::find_by<&internal::meta_type_node::base>(info, node)) { return as_ref(); } else if(const auto *const conv = internal::find_by<&internal::meta_type_node::conv>(info, node); conv) { - return conv->conv(storage.data()); + return conv->conv(*this); } else if(node && node->conversion_helper && (type.is_arithmetic() || type.is_enum())) { // exploits the fact that arithmetic types and enums are also default constructible auto other = type.construct(); diff --git a/src/entt/meta/node.hpp b/src/entt/meta/node.hpp index 006dfe7f3..3c906a3b7 100644 --- a/src/entt/meta/node.hpp +++ b/src/entt/meta/node.hpp @@ -57,7 +57,7 @@ struct meta_base_node { struct meta_conv_node { meta_conv_node *next; meta_type_node *const type; - meta_any (*const conv)(const void *); + meta_any (*const conv)(const meta_any &); }; struct meta_ctor_node { @@ -227,26 +227,6 @@ template return nullptr; } -[[nodiscard]] inline bool can_cast_or_convert(const internal::meta_type_node *type, const internal::meta_type_node *other) ENTT_NOEXCEPT { - if(type->info == other->info) { - return true; - } - - for(const auto *curr = type->conv; curr; curr = curr->next) { - if(curr->type->info == other->info) { - return true; - } - } - - for(const auto *curr = type->base; curr; curr = curr->next) { - if(can_cast_or_convert(curr->type, other)) { - return true; - } - } - - return (type->conversion_helper && other->conversion_helper); -} - } // namespace internal /**