From 2f2bdcac4d65d3ece56ff086ba410d60f8161d86 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 10 Oct 2022 15:08:45 +0200 Subject: [PATCH] meta: * make meta_getter use properly meta contexts * remove the meta context from the argument list of meta setters (not required) --- src/entt/meta/factory.hpp | 2 +- src/entt/meta/meta.hpp | 2 +- src/entt/meta/node.hpp | 2 +- src/entt/meta/utility.hpp | 30 ++++++++---------------------- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 532e25789..c481267a2 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -104,7 +104,7 @@ class meta_factory { Setter::size, &internal::resolve>>, &meta_arg::size != 1u, type_list_element_t>...>>, - +[](const meta_ctx &area, meta_handle instance, meta_any value) { return (meta_setter>(area, *instance.operator->(), value.as_ref()) || ...); }, + +[](meta_handle instance, meta_any value) { return (meta_setter>(*instance.operator->(), value.as_ref()) || ...); }, &meta_getter}); bucket = &elem.prop; diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index fd9bf11a6..995b58f7e 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -788,7 +788,7 @@ struct meta_data { */ template bool set(meta_handle instance, Type &&value) const { - return node->set && node->set(*ctx, std::move(instance), std::forward(value)); + return node->set && node->set(std::move(instance), std::forward(value)); } /** diff --git a/src/entt/meta/node.hpp b/src/entt/meta/node.hpp index ee01e8565..3b34e95b2 100644 --- a/src/entt/meta/node.hpp +++ b/src/entt/meta/node.hpp @@ -81,7 +81,7 @@ struct meta_data_node { size_type arity{0u}; meta_type_node (*type)(const meta_context &) noexcept {}; meta_type (*arg)(const meta_ctx &, const size_type) noexcept {}; - bool (*set)(const meta_ctx &, meta_handle, meta_any){}; + bool (*set)(meta_handle, meta_any){}; meta_any (*get)(const meta_ctx &, meta_handle){}; dense_map prop{}; }; diff --git a/src/entt/meta/utility.hpp b/src/entt/meta/utility.hpp index 2881c5d9a..160cf962b 100644 --- a/src/entt/meta/utility.hpp +++ b/src/entt/meta/utility.hpp @@ -211,13 +211,12 @@ template * @brief Sets the value of a given variable. * @tparam Type Reflected type to which the variable is associated. * @tparam Data The actual variable to set. - * @param ctx The context from which to search for meta types. * @param instance An opaque instance of the underlying type, if required. * @param value Parameter to use to set the variable. * @return True in case of success, false otherwise. */ template -[[nodiscard]] bool meta_setter(const meta_ctx &ctx /*_TODO*/, [[maybe_unused]] meta_handle instance, [[maybe_unused]] meta_any value) { +[[nodiscard]] bool meta_setter([[maybe_unused]] meta_handle instance, [[maybe_unused]] meta_any value) { if constexpr(!std::is_same_v && !std::is_same_v) { if constexpr(std::is_member_function_pointer_v || std::is_function_v>>) { using descriptor = meta_function_helper_t; @@ -251,19 +250,6 @@ template return false; } -/** - * @brief Sets the value of a given variable. - * @tparam Type Reflected type to which the variable is associated. - * @tparam Data The actual variable to set. - * @param instance An opaque instance of the underlying type, if required. - * @param value Parameter to use to set the variable. - * @return True in case of success, false otherwise. - */ -template -[[nodiscard]] bool meta_setter(meta_handle instance, meta_any value) { - return meta_setter(locator::value_or(), std::move(instance), std::move(value)); -} - /** * @brief Gets the value of a given variable. * @tparam Type Reflected type to which the variable is associated. @@ -274,31 +260,31 @@ template * @return A meta any containing the value of the underlying variable. */ template -[[nodiscard]] meta_any meta_getter(const meta_ctx &ctx /*_TODO*/, [[maybe_unused]] meta_handle instance) { +[[nodiscard]] meta_any meta_getter(const meta_ctx &ctx, [[maybe_unused]] meta_handle instance) { if constexpr(std::is_member_pointer_v || std::is_function_v>>) { if constexpr(!std::is_array_v>>>) { if constexpr(std::is_invocable_v) { if(auto *clazz = instance->try_cast(); clazz) { - return meta_dispatch(std::invoke(Data, *clazz)); + return meta_dispatch(ctx, std::invoke(Data, *clazz)); } } if constexpr(std::is_invocable_v) { if(auto *fallback = instance->try_cast(); fallback) { - return meta_dispatch(std::invoke(Data, *fallback)); + return meta_dispatch(ctx, std::invoke(Data, *fallback)); } } } - return meta_any{}; + return meta_any{meta_ctx_arg, ctx}; } else if constexpr(std::is_pointer_v) { if constexpr(std::is_array_v>) { - return meta_any{}; + return meta_any{meta_ctx_arg, ctx}; } else { - return meta_dispatch(*Data); + return meta_dispatch(ctx, *Data); } } else { - return meta_dispatch(Data); + return meta_dispatch(ctx, Data); } }