From 5bbd7e03f9e6cea6c2fbaade66d54aa933fc3919 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 27 Jan 2021 16:47:01 +0100 Subject: [PATCH] meta: prepare to make internal utilities public --- src/entt/meta/factory.hpp | 92 +++++++++++++++++++-------------------- src/entt/meta/meta.hpp | 11 ++--- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 53a99740d..2bbff1dfc 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -39,10 +39,6 @@ struct meta_function_helper { static constexpr auto is_static = Static; static constexpr auto is_const = Const; - - [[nodiscard]] static auto arg(typename internal::meta_func_node::size_type index) ENTT_NOEXCEPT { - return std::array{{meta_info::resolve()...}}[index]; - } }; @@ -69,6 +65,12 @@ template using meta_function_helper_t = decltype(to_meta_function_helper(std::declval())); +template +[[nodiscard]] static auto arg(type_list, const std::size_t index) ENTT_NOEXCEPT { + return std::array{{meta_info::resolve()...}}[index]; +} + + template [[nodiscard]] meta_any construct(meta_any * const args, std::index_sequence) { if(((args+Index)->allow_cast() && ...)) { @@ -81,34 +83,36 @@ template template [[nodiscard]] bool setter([[maybe_unused]] meta_handle instance, [[maybe_unused]] meta_any value) { - if constexpr(std::is_function_v>> || std::is_member_function_pointer_v) { - using helper_type = meta_function_helper_t; - using data_type = type_list_element_t, typename helper_type::args_type>; - - if(auto * const clazz = instance->try_cast(); clazz) { - if(value.allow_cast()) { - std::invoke(Data, *clazz, value.cast()); - return true; - } - } - } else if constexpr(std::is_member_object_pointer_v) { - using data_type = std::remove_cv_t().*Data)>>; - - if constexpr(!std::is_array_v) { + if constexpr(!std::is_same_v && !std::is_same_v) { + if constexpr(std::is_function_v>> || std::is_member_function_pointer_v) { + using helper_type = meta_function_helper_t; + using data_type = type_list_element_t, typename helper_type::args_type>; + if(auto * const clazz = instance->try_cast(); clazz) { if(value.allow_cast()) { - std::invoke(Data, clazz) = value.cast(); + std::invoke(Data, *clazz, value.cast()); return true; } } - } - } else { - using data_type = std::remove_cv_t>; - - if constexpr(!std::is_array_v) { - if(value.allow_cast()) { - *Data = value.cast(); - return true; + } else if constexpr(std::is_member_object_pointer_v) { + using data_type = std::remove_reference_t().*Data)>; + + if constexpr(!std::is_array_v && !std::is_const_v) { + if(auto * const clazz = instance->try_cast(); clazz) { + if(value.allow_cast()) { + std::invoke(Data, clazz) = value.cast(); + return true; + } + } + } + } else { + using data_type = std::remove_reference_t; + + if constexpr(!std::is_array_v && !std::is_const_v) { + if(value.allow_cast()) { + *Data = value.cast(); + return true; + } } } } @@ -146,7 +150,7 @@ template return fallback ? dispatch(std::invoke(Data, *fallback)) : meta_any{}; } } - } else if constexpr(std::is_pointer_v>) { + } else if constexpr(std::is_pointer_v) { if constexpr(std::is_array_v>) { return meta_any{}; } else { @@ -482,7 +486,9 @@ public: nullptr, nullptr, helper_type::args_type::size, - &helper_type::arg, + [](const typename internal::meta_ctor_node::size_type index) ENTT_NOEXCEPT { + return internal::arg(typename helper_type::args_type{}, index); + }, [](meta_any * const any) { return internal::invoke({}, any, std::make_index_sequence{}); } @@ -515,7 +521,9 @@ public: nullptr, nullptr, helper_type::args_type::size, - &helper_type::arg, + [](const typename internal::meta_ctor_node::size_type index) ENTT_NOEXCEPT { + return internal::arg(typename helper_type::args_type{}, index); + }, [](meta_any * const any) { return internal::construct(any, std::make_index_sequence{}); } @@ -578,7 +586,7 @@ public: if constexpr(std::is_member_object_pointer_v) { return data(id); } else { - using data_type = std::remove_pointer_t>; + using data_type = std::remove_pointer_t; auto * const type = internal::meta_info::resolve(); static internal::meta_data_node node{ @@ -586,15 +594,10 @@ public: type, nullptr, nullptr, + std::is_same_v || std::is_const_v, true, &internal::meta_info::resolve, - []() -> std::remove_cv_t { - if constexpr(std::is_same_v || std::is_const_v) { - return nullptr; - } else { - return &internal::setter; - } - }(), + &internal::setter, &internal::getter }; @@ -638,15 +641,10 @@ public: type, nullptr, nullptr, + std::is_same_v || (std::is_member_object_pointer_v && std::is_const_v), false, &internal::meta_info::resolve, - []() -> std::remove_cv_t { - if constexpr(std::is_same_v || (std::is_member_object_pointer_v && std::is_const_v)) { - return nullptr; - } else { - return &internal::setter; - } - }(), + &internal::setter, &internal::getter }; @@ -686,7 +684,9 @@ public: helper_type::is_const, helper_type::is_static, &internal::meta_info, void, typename helper_type::return_type>>::resolve, - &helper_type::arg, + [](const typename internal::meta_func_node::size_type index) ENTT_NOEXCEPT { + return internal::arg(typename helper_type::args_type{}, index); + }, [](meta_handle instance, meta_any *args) { return internal::invoke(std::move(instance), args, std::make_index_sequence{}); } diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 9920dd0e1..1aad52749 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -70,7 +70,7 @@ struct meta_ctor_node { meta_ctor_node * next; meta_prop_node * prop; const size_type size; - meta_type_node *(* const arg)(size_type) ENTT_NOEXCEPT; + meta_type_node *(* const arg)(const size_type) ENTT_NOEXCEPT; meta_any(* const invoke)(meta_any * const); }; @@ -80,6 +80,7 @@ struct meta_data_node { meta_type_node * const parent; meta_data_node * next; meta_prop_node * prop; + const bool is_const; const bool is_static; meta_type_node *(* const type)() ENTT_NOEXCEPT; bool(* const set)(meta_handle, meta_any); @@ -97,7 +98,7 @@ struct meta_func_node { const bool is_const; const bool is_static; meta_type_node *(* const ret)() ENTT_NOEXCEPT; - meta_type_node *(* const arg)(size_type) ENTT_NOEXCEPT; + meta_type_node *(* const arg)(const size_type) ENTT_NOEXCEPT; meta_any(* const invoke)(meta_handle, meta_any *); }; @@ -124,7 +125,7 @@ struct meta_type_node { const bool is_sequence_container; const bool is_associative_container; const size_type rank; - size_type(* const extent)(size_type); + size_type(* const extent)(const size_type); meta_type_node *(* const remove_pointer)() ENTT_NOEXCEPT; meta_type_node *(* const remove_extent)() ENTT_NOEXCEPT; meta_ctor_node *def_ctor{nullptr}; @@ -163,7 +164,7 @@ class ENTT_API meta_node { static_assert(std::is_same_v>>, "Invalid type"); template - [[nodiscard]] static auto extent(meta_type_node::size_type dim, std::index_sequence) { + [[nodiscard]] static auto extent(const meta_type_node::size_type dim, std::index_sequence) { meta_type_node::size_type ext{}; ((ext = (dim == Index ? std::extent_v : ext)), ...); return ext; @@ -976,7 +977,7 @@ struct meta_data { * @return True if the data member is constant, false otherwise. */ [[nodiscard]] bool is_const() const ENTT_NOEXCEPT { - return (node->set == nullptr); + return node->is_const; } /**