From 94735d04b32e3877fb443e87dad52a7b83816c3d Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 26 Aug 2024 16:44:00 +0200 Subject: [PATCH] meta: prepare meta_base/meta_conv/meta_ctor rework --- src/entt/meta/factory.hpp | 18 +++++++++--------- src/entt/meta/node.hpp | 3 +++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 51c2e0e98..b3eb99d26 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -55,16 +55,16 @@ class basic_meta_factory { } template - void insert_or_assign(const id_type id, Type node) { + void insert_or_assign(Type node) { reset_bucket(parent); if constexpr(std::is_same_v) { - details->base.insert_or_assign(id, node); + details->base.insert_or_assign(node.id, node); } else if constexpr(std::is_same_v) { - details->conv.insert_or_assign(id, node); + details->conv.insert_or_assign(node.type, node); } else { static_assert(std::is_same_v, "Unexpected type"); - details->ctor.insert_or_assign(id, node); + details->ctor.insert_or_assign(node.id, node); } } @@ -221,7 +221,7 @@ class meta_factory: private internal::basic_meta_factory { meta_factory base() noexcept { static_assert(!std::is_same_v && std::is_base_of_v, "Invalid base type"); auto *const op = +[](const void *instance) noexcept { return static_cast(static_cast(static_cast(instance))); }; - base_type::insert_or_assign(type_id().hash(), internal::meta_base_node{&internal::resolve, op}); + base_type::insert_or_assign(internal::meta_base_node{type_id().hash(), &internal::resolve, op}); return *this; } @@ -241,7 +241,7 @@ class meta_factory: private internal::basic_meta_factory { auto conv() noexcept { using conv_type = std::remove_cv_t>>; auto *const op = +[](const meta_ctx &area, const void *instance) { return forward_as_meta(area, std::invoke(Candidate, *static_cast(instance))); }; - base_type::insert_or_assign(type_id().hash(), internal::meta_conv_node{op}); + base_type::insert_or_assign(internal::meta_conv_node{type_id().hash(), op}); return *this; } @@ -258,7 +258,7 @@ class meta_factory: private internal::basic_meta_factory { meta_factory conv() noexcept { using conv_type = std::remove_cv_t>; auto *const op = +[](const meta_ctx &area, const void *instance) { return forward_as_meta(area, static_cast(*static_cast(instance))); }; - base_type::insert_or_assign(type_id().hash(), internal::meta_conv_node{op}); + base_type::insert_or_assign(internal::meta_conv_node{type_id().hash(), op}); return *this; } @@ -280,7 +280,7 @@ class meta_factory: private internal::basic_meta_factory { using descriptor = meta_function_helper_t; static_assert(Policy::template value, "Invalid return type for the given policy"); static_assert(std::is_same_v>, Type>, "The function doesn't return an object of the required type"); - base_type::insert_or_assign(type_id().hash(), internal::meta_ctor_node{descriptor::args_type::size, &meta_arg, &meta_construct}); + base_type::insert_or_assign(internal::meta_ctor_node{type_id().hash(), descriptor::args_type::size, &meta_arg, &meta_construct}); return *this; } @@ -299,7 +299,7 @@ class meta_factory: private internal::basic_meta_factory { // default constructor is already implicitly generated, no need for redundancy if constexpr(sizeof...(Args) != 0u) { using descriptor = meta_function_helper_t; - base_type::insert_or_assign(type_id().hash(), internal::meta_ctor_node{descriptor::args_type::size, &meta_arg, &meta_construct}); + base_type::insert_or_assign(internal::meta_ctor_node{type_id().hash(), descriptor::args_type::size, &meta_arg, &meta_construct}); } return *this; diff --git a/src/entt/meta/node.hpp b/src/entt/meta/node.hpp index 983803aae..93103eb0d 100644 --- a/src/entt/meta/node.hpp +++ b/src/entt/meta/node.hpp @@ -74,17 +74,20 @@ struct meta_prop_node { }; struct meta_base_node { + id_type id{}; meta_type_node (*type)(const meta_context &) noexcept {}; const void *(*cast)(const void *) noexcept {}; }; struct meta_conv_node { + id_type type{}; meta_any (*conv)(const meta_ctx &, const void *){}; }; struct meta_ctor_node { using size_type = std::size_t; + id_type id{}; size_type arity{0u}; meta_type (*arg)(const meta_ctx &, const size_type) noexcept {}; meta_any (*invoke)(const meta_ctx &, meta_any *const){};