diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 63a3fbdab..0e4f4e8cd 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -46,6 +46,26 @@ protected: elem.id = id; } + void extend(const id_type id, meta_base_node node) { + owner().details->base.insert_or_assign(id, std::move(node)); + properties = nullptr; + } + + void extend(const id_type id, meta_conv_node node) { + owner().details->conv.insert_or_assign(id, std::move(node)); + properties = nullptr; + } + + void extend(const id_type id, meta_ctor_node node) { + owner().details->ctor.insert_or_assign(id, std::move(node)); + properties = nullptr; + } + + void extend(meta_dtor_node node) { + owner().dtor = std::move(node); + properties = nullptr; + } + void extend(const id_type id, meta_data_node node) { auto &&elem = owner().details->data.insert_or_assign(id, std::move(node)).first->second; properties = &elem.prop; @@ -158,8 +178,7 @@ public: auto 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))); }; - this->owner().details->base.insert_or_assign(type_id().hash(), internal::meta_base_node{&internal::resolve, op}); - this->bucket(nullptr); + this->extend(type_id().hash(), internal::meta_base_node{&internal::resolve, op}); return *this; } @@ -179,8 +198,7 @@ public: 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))); }; - this->owner().details->conv.insert_or_assign(type_id().hash(), internal::meta_conv_node{op}); - this->bucket(nullptr); + this->extend(type_id().hash(), internal::meta_conv_node{op}); return *this; } @@ -197,8 +215,7 @@ public: 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, static_cast(*static_cast(instance))); }; - this->owner().details->conv.insert_or_assign(type_id().hash(), internal::meta_conv_node{op}); - this->bucket(nullptr); + this->extend(type_id().hash(), internal::meta_conv_node{op}); return *this; } @@ -220,8 +237,7 @@ public: 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"); - this->owner().details->ctor.insert_or_assign(type_id().hash(), internal::meta_ctor_node{descriptor::args_type::size, &meta_arg, &meta_construct}); - this->bucket(nullptr); + this->extend(type_id().hash(), internal::meta_ctor_node{descriptor::args_type::size, &meta_arg, &meta_construct}); return *this; } @@ -240,10 +256,9 @@ public: // default constructor is already implicitly generated, no need for redundancy if constexpr(sizeof...(Args) != 0u) { using descriptor = meta_function_helper_t; - this->owner().details->ctor.insert_or_assign(type_id().hash(), internal::meta_ctor_node{descriptor::args_type::size, &meta_arg, &meta_construct}); + this->extend(type_id().hash(), internal::meta_ctor_node{descriptor::args_type::size, &meta_arg, &meta_construct}); } - this->bucket(nullptr); return *this; } @@ -269,8 +284,7 @@ public: auto dtor() noexcept { static_assert(std::is_invocable_v, "The function doesn't accept an object of the type provided"); auto *const op = +[](void *instance) { std::invoke(Func, *static_cast(instance)); }; - this->owner().dtor = internal::meta_dtor_node{op}; - this->bucket(nullptr); + this->extend(internal::meta_dtor_node{op}); return *this; }