From 93a1d651039b9b237004fd2a47af565cd517b65b Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sat, 27 Aug 2022 17:04:45 +0200 Subject: [PATCH] meta: meta_type_node is no longer static --- TODO | 4 + src/entt/meta/context.hpp | 58 ++++++----- src/entt/meta/factory.hpp | 84 +++++----------- src/entt/meta/meta.hpp | 20 ++-- src/entt/meta/node.hpp | 146 +++++++++++++++------------- src/entt/meta/range.hpp | 67 +++---------- src/entt/meta/resolve.hpp | 20 ++-- test/entt/meta/meta_base.cpp | 2 +- test/entt/meta/meta_conv.cpp | 2 +- test/entt/meta/meta_ctor.cpp | 2 +- test/entt/meta/meta_data.cpp | 2 +- test/entt/meta/meta_dtor.cpp | 2 +- test/entt/meta/meta_prop.cpp | 2 +- test/entt/meta/meta_range.cpp | 12 ++- test/entt/meta/meta_type.cpp | 19 ++-- test/lib/meta/lib.cpp | 4 + test/lib/meta/main.cpp | 5 + test/lib/meta_plugin/main.cpp | 2 + test/lib/meta_plugin/plugin.cpp | 3 +- test/lib/meta_plugin/types.h | 3 +- test/lib/meta_plugin_std/main.cpp | 1 + test/lib/meta_plugin_std/plugin.cpp | 2 +- test/lib/meta_plugin_std/types.h | 4 +- 23 files changed, 217 insertions(+), 249 deletions(-) diff --git a/TODO b/TODO index 3b98fccf8..5323edbfd 100644 --- a/TODO +++ b/TODO @@ -11,6 +11,10 @@ DOC: * examples (and credits) from @alanjfs :) * update entity doc when the storage based model is in place +TODO: +* update doc (meta, lib) +* update meta natvis files + WIP: * get rid of observers, storage based views made them pointless - document alternatives * add storage getter for filters to views and groups diff --git a/src/entt/meta/context.hpp b/src/entt/meta/context.hpp index 29cf4bef5..83cac9476 100644 --- a/src/entt/meta/context.hpp +++ b/src/entt/meta/context.hpp @@ -1,10 +1,15 @@ #ifndef ENTT_META_CTX_HPP #define ENTT_META_CTX_HPP -#include "../core/attribute.h" +#include +#include "../container/dense_map.hpp" +#include "../core/fwd.hpp" +#include "../core/utility.hpp" namespace entt { +class meta_ctx; + /** * @cond TURN_OFF_DOXYGEN * Internal details not to be documented. @@ -14,20 +19,11 @@ namespace internal { struct meta_type_node; -struct ENTT_API meta_context { - // we could use the lines below but VS2017 returns with an ICE if combined with ENTT_API despite the code being valid C++ - // inline static meta_type_node *local = nullptr; - // inline static meta_type_node **global = &local; +struct meta_context { + dense_map, identity> value{}; - [[nodiscard]] static meta_type_node *&local() noexcept { - static meta_type_node *chain = nullptr; - return chain; - } - - [[nodiscard]] static meta_type_node **&global() noexcept { - static meta_type_node **chain = &local(); - return chain; - } + static inline meta_context &from(meta_ctx &ctx); + static inline const meta_context &from(const meta_ctx &ctx); }; } // namespace internal @@ -37,20 +33,30 @@ struct ENTT_API meta_context { * @endcond */ -/*! @brief Opaque container for a meta context. */ -struct meta_ctx { - /** - * @brief Binds the meta system to a given context. - * @param other A valid context to which to bind. - */ - static void bind(meta_ctx other) noexcept { - internal::meta_context::global() = other.ctx; - } - -private: - internal::meta_type_node **ctx{&internal::meta_context::local()}; +/*! @brief Opaque meta context type. */ +class meta_ctx: private internal::meta_context { + /*! @brief Attorney idiom like model to access the base class. */ + friend struct internal::meta_context; }; +/** + * @cond TURN_OFF_DOXYGEN + * Internal details not to be documented. + */ + +inline internal::meta_context &internal::meta_context::from(meta_ctx &ctx) { + return ctx; +} + +inline const internal::meta_context &internal::meta_context::from(const meta_ctx &ctx) { + return ctx; +} + +/** + * Internal details not to be documented. + * @endcond + */ + } // namespace entt #endif diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index f36a13571..8714314cf 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -19,30 +19,6 @@ namespace entt { -/** - * @cond TURN_OFF_DOXYGEN - * Internal details not to be documented. - */ - -namespace internal { - -inline void link_type_if_required(meta_type_node *owner, const id_type id) noexcept { - ENTT_ASSERT((owner->id = {}, !resolve(id)), "Duplicate identifier"); - owner->id = id; - - if(!resolve(id)) { - owner->next = *meta_context::global(); - *meta_context::global() = owner; - } -} - -} // namespace internal - -/** - * Internal details not to be documented. - * @endcond - */ - /** * @brief Meta factory to be used for reflection purposes. * @@ -82,7 +58,7 @@ public: template meta_factory prop(id_type key, Value &&...value) { (*container)[key] = internal::meta_prop_node{ - &internal::meta_node>::resolve..., + &internal::resolve>..., std::forward(value)...}; return *this; @@ -108,9 +84,9 @@ class meta_factory { /* this is never static */ (std::is_member_object_pointer_v)> && ... && std::is_const_v>) ? internal::meta_traits::is_const : internal::meta_traits::is_none, Setter::size, - &internal::meta_node>>::resolve, + &internal::resolve>>, &meta_arg::size != 1u, type_list_element_t>...>>, - [](meta_handle instance, meta_any value) -> bool { return (meta_setter>(*instance.operator->(), value.as_ref()) || ...); }, + +[](meta_handle instance, meta_any value) -> bool { return (meta_setter>(*instance.operator->(), value.as_ref()) || ...); }, &meta_getter}; auto it = owner->data.insert_or_assign(id, std::move(node)).first; @@ -120,7 +96,7 @@ class meta_factory { public: /*! @brief Default constructor. */ meta_factory() noexcept - : owner{internal::meta_node::resolve()} {} + : owner{internal::resolve()} {} /** * @brief Makes a meta type _searchable_. @@ -128,7 +104,8 @@ public: * @return An extended meta factory for the given type. */ auto type(const id_type id = type_hash::value()) noexcept { - internal::link_type_if_required(owner, id); + ENTT_ASSERT(owner->id == id || !resolve(id), "Duplicate identifier"); + owner->id = id; return meta_factory{owner->prop}; } @@ -145,8 +122,8 @@ public: static_assert(!std::is_same_v && std::is_base_of_v, "Invalid base type"); owner->base[type_id().hash()] = internal::meta_base_node{ - &internal::meta_node::resolve, - [](meta_any other) noexcept -> meta_any { + &internal::resolve, + +[](meta_any other) noexcept -> meta_any { if(auto *ptr = other.data(); ptr) { return forward_as_meta(*static_cast(static_cast(ptr))); } @@ -174,7 +151,7 @@ public: using conv_type = std::remove_cv_t>>; owner->conv[type_id().hash()] = internal::meta_conv_node{ - [](const meta_any &instance) -> meta_any { + +[](const meta_any &instance) -> meta_any { return forward_as_meta(std::invoke(Candidate, *static_cast(instance.data()))); }}; @@ -195,7 +172,7 @@ public: using conv_type = std::remove_cv_t>; owner->conv[type_id().hash()] = internal::meta_conv_node{ - [](const meta_any &instance) -> meta_any { + +[](const meta_any &instance) -> meta_any { return forward_as_meta(static_cast(*static_cast(instance.data()))); }}; @@ -272,7 +249,7 @@ public: template auto dtor() noexcept { static_assert(std::is_invocable_v, "The function doesn't accept an object of the type provided"); - owner->dtor.dtor = [](void *instance) { std::invoke(Func, *static_cast(instance)); }; + owner->dtor.dtor = +[](void *instance) { std::invoke(Func, *static_cast(instance)); }; return meta_factory{}; } @@ -298,7 +275,7 @@ public: /* this is never static */ std::is_const_v ? internal::meta_traits::is_const : internal::meta_traits::is_none, 1u, - &internal::meta_node>::resolve, + &internal::resolve>, &meta_arg>>, &meta_setter, &meta_getter}; @@ -311,7 +288,7 @@ public: internal::meta_data_node node{ ((std::is_same_v> || std::is_const_v) ? internal::meta_traits::is_const : internal::meta_traits::is_none) | internal::meta_traits::is_static, 1u, - &internal::meta_node>::resolve, + &internal::resolve>, &meta_arg>>, &meta_setter, &meta_getter}; @@ -351,7 +328,7 @@ public: /* this is never static */ internal::meta_traits::is_const, 0u, - &internal::meta_node>>::resolve, + &internal::resolve>>, &meta_arg>, &meta_setter, &meta_getter}; @@ -365,7 +342,7 @@ public: /* this is never static nor const */ internal::meta_traits::is_none, 1u, - &internal::meta_node>>::resolve, + &internal::resolve>>, &meta_arg>>, &meta_setter, &meta_getter}; @@ -419,7 +396,7 @@ public: type_id, typename descriptor::args_type>>().hash(), (descriptor::is_const ? internal::meta_traits::is_const : internal::meta_traits::is_none) | (descriptor::is_static ? internal::meta_traits::is_static : internal::meta_traits::is_none), descriptor::args_type::size, - &internal::meta_node, void, std::remove_cv_t>>>::resolve, + &internal::resolve, void, std::remove_cv_t>>>, &meta_arg, &meta_invoke}; @@ -458,7 +435,7 @@ private: */ template [[nodiscard]] auto meta() noexcept { - auto *const node = internal::meta_node::resolve(); + auto *const node = internal::resolve(); // extended meta factory to allow assigning properties to opaque meta types return meta_factory{node->prop}; } @@ -470,25 +447,16 @@ template * well as its constructors, destructors and conversion functions if any.
* Base classes aren't reset but the link between the two types is removed. * - * The type is also removed from the list of searchable types. + * The type is also removed from the set of searchable types. * * @param id Unique identifier. */ inline void meta_reset(const id_type id) noexcept { - for(auto **it = internal::meta_context::global(); *it; it = &(*it)->next) { - if(auto *node = *it; node->id == id) { - node->id = {}; - node->prop.clear(); - node->ctor.clear(); - node->base.clear(); - node->conv.clear(); - node->data.clear(); - node->func.clear(); - node->dtor.dtor = nullptr; + auto &&context = internal::meta_context::from(locator::value_or()); - *it = std::exchange(node->next, nullptr); - - break; + for(auto it = context.value.begin(); it != context.value.end(); ++it) { + if(it->second->id == id) { + it = context.value.erase(it); } } } @@ -502,18 +470,16 @@ inline void meta_reset(const id_type id) noexcept { */ template void meta_reset() noexcept { - meta_reset(internal::meta_node::resolve()->id); + internal::meta_context::from(locator::value_or()).value.erase(type_id().hash()); } /** - * @brief Resets all searchable types. + * @brief Resets all meta types. * * @sa meta_reset */ inline void meta_reset() noexcept { - while(*internal::meta_context::global()) { - meta_reset((*internal::meta_context::global())->id); - } + internal::meta_context::from(locator::value_or()).value.clear(); } } // namespace entt diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 366c1ed48..f149a77b5 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -45,7 +45,7 @@ public: */ template meta_sequence_container(std::in_place_type_t, any instance) noexcept - : value_type_node{&internal::meta_node::resolve}, + : value_type_node{&internal::resolve}, size_fn{&meta_sequence_container_traits::size}, resize_fn{&meta_sequence_container_traits::resize}, iter_fn{&meta_sequence_container_traits::iter}, @@ -93,9 +93,9 @@ public: template meta_associative_container(std::in_place_type_t, any instance) noexcept : key_only_container{meta_associative_container_traits::key_only}, - key_type_node{&internal::meta_node::resolve}, + key_type_node{&internal::resolve}, mapped_type_node{nullptr}, - value_type_node{&internal::meta_node::resolve}, + value_type_node{&internal::resolve}, size_fn{&meta_associative_container_traits::size}, clear_fn{&meta_associative_container_traits::clear}, iter_fn{&meta_associative_container_traits::iter}, @@ -103,7 +103,7 @@ public: find_fn{&meta_associative_container_traits::find}, storage{std::move(instance)} { if constexpr(!meta_associative_container_traits::key_only) { - mapped_type_node = &internal::meta_node::resolve; + mapped_type_node = &internal::resolve; } } @@ -207,7 +207,7 @@ public: template explicit meta_any(std::in_place_type_t, Args &&...args) : storage{std::in_place_type, std::forward(args)...}, - node{internal::meta_node>>::resolve()}, + node{internal::resolve>>()}, vtable{&basic_vtable>>} {} /** @@ -218,7 +218,7 @@ public: template, meta_any>>> meta_any(Type &&value) : storage{std::forward(value)}, - node{internal::meta_node>::resolve()}, + node{internal::resolve>()}, vtable{&basic_vtable>} {} /** @@ -430,7 +430,7 @@ public: if constexpr(std::is_reference_v && !std::is_const_v>) { return meta_any{}; } else { - return allow_cast(internal::meta_node>>::resolve()); + return allow_cast(internal::resolve>>()); } } @@ -442,9 +442,9 @@ public: template bool allow_cast() { if constexpr(std::is_reference_v && !std::is_const_v>) { - return allow_cast(internal::meta_node>>::resolve()) && (storage.data() != nullptr); + return allow_cast(internal::resolve>>()) && (storage.data() != nullptr); } else { - return allow_cast(internal::meta_node>>::resolve()); + return allow_cast(internal::resolve>>()); } } @@ -454,7 +454,7 @@ public: release(); vtable = &basic_vtable>>; storage.emplace(std::forward(args)...); - node = internal::meta_node>>::resolve(); + node = internal::resolve>>(); } /*! @copydoc any::assign */ diff --git a/src/entt/meta/node.hpp b/src/entt/meta/node.hpp index ab7fa00e1..35185a09f 100644 --- a/src/entt/meta/node.hpp +++ b/src/entt/meta/node.hpp @@ -12,6 +12,8 @@ #include "../core/type_info.hpp" #include "../core/type_traits.hpp" #include "../core/utility.hpp" +#include "../locator/locator.hpp" +#include "context.hpp" #include "type_traits.hpp" namespace entt { @@ -109,13 +111,12 @@ struct meta_type_node { const type_info *info; id_type id; - const meta_traits traits; - meta_type_node *next; - const size_type size_of; - meta_type_node *(*const remove_pointer)() noexcept; - meta_any (*const default_constructor)(); - double (*const conversion_helper)(void *, const void *); - meta_any (*const from_void)(void *, const void *); + meta_traits traits; + size_type size_of; + meta_type_node *(*remove_pointer)() noexcept; + meta_any (*default_constructor)(); + double (*conversion_helper)(void *, const void *); + meta_any (*from_void)(void *, const void *); meta_template_node templ; dense_map prop{}; dense_map ctor{}; @@ -126,67 +127,87 @@ struct meta_type_node { meta_dtor_node dtor{}; }; +template +meta_type_node *resolve() noexcept; + template -meta_type_node *meta_arg_node(type_list, const std::size_t index) noexcept; +[[nodiscard]] meta_type_node *meta_arg_node(type_list, const std::size_t index) noexcept { + meta_type_node *args[sizeof...(Args) + 1u]{nullptr, internal::resolve>>()...}; + return args[index + 1u]; +} template -class ENTT_API meta_node { +[[nodiscard]] auto *meta_default_constructor() noexcept { static_assert(std::is_same_v>>, "Invalid type"); - [[nodiscard]] static auto *meta_default_constructor() noexcept { - if constexpr(std::is_default_constructible_v) { - return +[]() { return meta_any{std::in_place_type}; }; - } else { - return static_cast>(nullptr); - } + if constexpr(std::is_default_constructible_v) { + return +[]() { return meta_any{std::in_place_type}; }; + } else { + return static_cast>(nullptr); } +} - [[nodiscard]] static auto *meta_conversion_helper() noexcept { - if constexpr(std::is_arithmetic_v) { - return +[](void *bin, const void *value) { - return bin ? static_cast(*static_cast(bin) = static_cast(*static_cast(value))) : static_cast(*static_cast(value)); - }; - } else if constexpr(std::is_enum_v) { - return +[](void *bin, const void *value) { - return bin ? static_cast(*static_cast(bin) = static_cast(static_cast>(*static_cast(value)))) : static_cast(*static_cast(value)); - }; - } else { - return static_cast>(nullptr); - } +template +[[nodiscard]] auto *meta_conversion_helper() noexcept { + static_assert(std::is_same_v>>, "Invalid type"); + + if constexpr(std::is_arithmetic_v) { + return +[](void *bin, const void *value) { + return bin ? static_cast(*static_cast(bin) = static_cast(*static_cast(value))) : static_cast(*static_cast(value)); + }; + } else if constexpr(std::is_enum_v) { + return +[](void *bin, const void *value) { + return bin ? static_cast(*static_cast(bin) = static_cast(static_cast>(*static_cast(value)))) : static_cast(*static_cast(value)); + }; + } else { + return static_cast>(nullptr); } +} - [[nodiscard]] static auto *meta_from_void() noexcept { - if constexpr(std::is_same_v || std::is_function_v) { - return static_cast>(nullptr); - } else { - return +[](void *element, const void *as_const) { - using value_type = std::decay_t; +template +[[nodiscard]] auto *meta_from_void() noexcept { + static_assert(std::is_same_v>>, "Invalid type"); - if(element) { - return meta_any{std::in_place_type, *static_cast(element)}; - } + if constexpr(std::is_same_v || std::is_function_v) { + return static_cast>(nullptr); + } else { + return +[](void *element, const void *as_const) { + using value_type = std::decay_t; - return meta_any{std::in_place_type, *static_cast(as_const)}; - }; - } + if(element) { + return meta_any{std::in_place_type, *static_cast(element)}; + } + + return meta_any{std::in_place_type, *static_cast(as_const)}; + }; } +} - [[nodiscard]] static auto meta_template_info() noexcept { - if constexpr(is_complete_v>) { - return meta_template_node{ - meta_template_traits::args_type::size, - &meta_node::class_type>::resolve, - +[](const std::size_t index) noexcept -> meta_type_node * { return meta_arg_node(typename meta_template_traits::args_type{}, index); }}; - } else { - return meta_template_node{}; - } +template +[[nodiscard]] auto meta_template_info() noexcept { + static_assert(std::is_same_v>>, "Invalid type"); + + if constexpr(is_complete_v>) { + return meta_template_node{ + meta_template_traits::args_type::size, + &resolve::class_type>, + +[](const std::size_t index) noexcept -> meta_type_node * { return meta_arg_node(typename meta_template_traits::args_type{}, index); }}; + } else { + return meta_template_node{}; } +} -public: - [[nodiscard]] static meta_type_node *resolve() noexcept { - static meta_type_node node{ +template +[[nodiscard]] meta_type_node *resolve() noexcept { + static_assert(std::is_same_v>>, "Invalid type"); + + auto &&context = meta_context::from(locator::value_or()); + auto it = context.value.find(type_id().hash()); + + if(it == context.value.end()) { + meta_type_node node{ &type_id(), - {}, + type_id().hash(), (std::is_arithmetic_v ? internal::meta_traits::is_arithmetic : internal::meta_traits::is_none) | (std::is_integral_v ? internal::meta_traits::is_integral : internal::meta_traits::is_none) | (std::is_signed_v ? internal::meta_traits::is_signed : internal::meta_traits::is_none) @@ -196,24 +217,17 @@ public: | (is_meta_pointer_like_v ? internal::meta_traits::is_meta_pointer_like : internal::meta_traits::is_none) | (is_complete_v> ? internal::meta_traits::is_meta_sequence_container : internal::meta_traits::is_none) | (is_complete_v> ? internal::meta_traits::is_meta_associative_container : internal::meta_traits::is_none), - nullptr, size_of_v, - &meta_node>>::resolve, - meta_default_constructor(), - meta_conversion_helper(), - meta_from_void(), - meta_template_info() - // tricks clang-format - }; + &resolve>>, + meta_default_constructor(), + meta_conversion_helper(), + meta_from_void(), + meta_template_info()}; - return &node; + it = context.value.insert_or_assign(node.info->hash(), std::make_unique(std::move(node))).first; } -}; -template -[[nodiscard]] meta_type_node *meta_arg_node(type_list, const std::size_t index) noexcept { - meta_type_node *args[sizeof...(Args) + 1u]{nullptr, internal::meta_node>>::resolve()...}; - return args[index + 1u]; + return it->second.get(); } } // namespace internal diff --git a/src/entt/meta/range.hpp b/src/entt/meta/range.hpp index d8dbfdc1e..0c876dfc8 100644 --- a/src/entt/meta/range.hpp +++ b/src/entt/meta/range.hpp @@ -16,52 +16,19 @@ namespace entt { namespace internal { -template -struct old_meta_range_iterator final { - using difference_type = std::ptrdiff_t; - using value_type = Type; - using pointer = input_iterator_pointer; - using reference = value_type; - using iterator_category = std::input_iterator_tag; - using node_type = Node; - - old_meta_range_iterator() noexcept - : it{} {} - - old_meta_range_iterator(node_type *head) noexcept - : it{head} {} - - old_meta_range_iterator &operator++() noexcept { - return (it = it->next), *this; - } - - old_meta_range_iterator operator++(int) noexcept { - old_meta_range_iterator orig = *this; - return ++(*this), orig; - } - - [[nodiscard]] reference operator*() const noexcept { - return it; - } - - [[nodiscard]] pointer operator->() const noexcept { - return operator*(); - } - - [[nodiscard]] bool operator==(const old_meta_range_iterator &other) const noexcept { - return it == other.it; - } - - [[nodiscard]] bool operator!=(const old_meta_range_iterator &other) const noexcept { - return !(*this == other); - } - -private: - node_type *it; -}; - template -struct meta_range_iterator final { +class meta_range_iterator final { + template + auto to_value(int, const Value &value) const -> decltype(*value, Type{}) { + return &*it->second; + } + + template + Type to_value(char, const Value &value) const { + return &it->second; + } + +public: using difference_type = std::ptrdiff_t; using value_type = std::pair; using pointer = input_iterator_pointer; @@ -84,7 +51,7 @@ struct meta_range_iterator final { } [[nodiscard]] reference operator*() const noexcept { - return std::make_pair(it->first, &it->second); + return std::make_pair(it->first, to_value(0, it->second)); } [[nodiscard]] pointer operator->() const noexcept { @@ -110,14 +77,6 @@ private: * @endcond */ -/** - * @brief Iterable range to use to iterate all types of meta objects. - * @tparam Type Type of meta objects returned. - * @tparam Node Type of meta nodes iterated. - */ -template -using old_meta_range = iterable_adaptor>; - /** * @brief Iterable range to use to iterate all types of meta objects. * @tparam Type Type of meta objects returned. diff --git a/src/entt/meta/resolve.hpp b/src/entt/meta/resolve.hpp index 76517eb8e..1fa6ab954 100644 --- a/src/entt/meta/resolve.hpp +++ b/src/entt/meta/resolve.hpp @@ -3,6 +3,7 @@ #include #include "../core/type_info.hpp" +#include "../locator/locator.hpp" #include "context.hpp" #include "meta.hpp" #include "node.hpp" @@ -17,15 +18,16 @@ namespace entt { */ template [[nodiscard]] meta_type resolve() noexcept { - return internal::meta_node>>::resolve(); + return internal::resolve>>(); } /** * @brief Returns a range to use to visit all meta types. * @return An iterable range to use to visit all meta types. */ -[[nodiscard]] inline old_meta_range resolve() noexcept { - return {*internal::meta_context::global(), nullptr}; +[[nodiscard]] inline meta_range resolve() noexcept { + auto &&context = internal::meta_context::from(locator::value_or()); + return {context.value.cbegin(), context.value.cend()}; } /** @@ -35,8 +37,8 @@ template */ [[nodiscard]] inline meta_type resolve(const id_type id) noexcept { for(auto &&curr: resolve()) { - if(curr.id() == id) { - return curr; + if(curr.second.id() == id) { + return curr.second; } } @@ -49,10 +51,10 @@ template * @return The meta type associated with the given type info object, if any. */ [[nodiscard]] inline meta_type resolve(const type_info &info) noexcept { - for(auto &&curr: resolve()) { - if(curr.info() == info) { - return curr; - } + auto &&context = internal::meta_context::from(locator::value_or()); + + if(auto it = context.value.find(info.hash()); it != context.value.cend()) { + return it->second.get(); } return {}; diff --git a/test/entt/meta/meta_base.cpp b/test/entt/meta/meta_base.cpp index ec0c392a7..e2e67a608 100644 --- a/test/entt/meta/meta_base.cpp +++ b/test/entt/meta/meta_base.cpp @@ -181,7 +181,7 @@ TEST_F(MetaBase, TransferWithMutatingThis) { TEST_F(MetaBase, ReRegistration) { SetUp(); - auto *node = entt::internal::meta_node::resolve(); + auto *node = entt::internal::resolve(); ASSERT_FALSE(node->base.empty()); ASSERT_EQ(node->base.size(), 2u); diff --git a/test/entt/meta/meta_conv.cpp b/test/entt/meta/meta_conv.cpp index b3a7d16b3..0671cfa33 100644 --- a/test/entt/meta/meta_conv.cpp +++ b/test/entt/meta/meta_conv.cpp @@ -62,7 +62,7 @@ TEST_F(MetaConv, Functionalities) { TEST_F(MetaConv, ReRegistration) { SetUp(); - auto *node = entt::internal::meta_node::resolve(); + auto *node = entt::internal::resolve(); ASSERT_FALSE(node->conv.empty()); ASSERT_EQ(node->conv.size(), 3u); diff --git a/test/entt/meta/meta_ctor.cpp b/test/entt/meta/meta_ctor.cpp index c5a240d76..551eed9eb 100644 --- a/test/entt/meta/meta_ctor.cpp +++ b/test/entt/meta/meta_ctor.cpp @@ -205,7 +205,7 @@ TEST_F(MetaCtor, NonDefaultConstructibleType) { TEST_F(MetaCtor, ReRegistration) { SetUp(); - auto *node = entt::internal::meta_node::resolve(); + auto *node = entt::internal::resolve(); ASSERT_NE(node->ctor, nullptr); // implicitly generated default constructor is not cleared diff --git a/test/entt/meta/meta_data.cpp b/test/entt/meta/meta_data.cpp index 2c7f6bc5d..a3d7f41d3 100644 --- a/test/entt/meta/meta_data.cpp +++ b/test/entt/meta/meta_data.cpp @@ -643,7 +643,7 @@ TEST_F(MetaData, ReRegistration) { SetUp(); - auto *node = entt::internal::meta_node::resolve(); + auto *node = entt::internal::resolve(); auto type = entt::resolve(); ASSERT_FALSE(node->data.empty()); diff --git a/test/entt/meta/meta_dtor.cpp b/test/entt/meta/meta_dtor.cpp index f0d8927a9..21788f489 100644 --- a/test/entt/meta/meta_dtor.cpp +++ b/test/entt/meta/meta_dtor.cpp @@ -101,7 +101,7 @@ TEST_F(MetaDtor, AsRefConstruction) { TEST_F(MetaDtor, ReRegistration) { SetUp(); - auto *node = entt::internal::meta_node::resolve(); + auto *node = entt::internal::resolve(); ASSERT_NE(node->dtor.dtor, nullptr); diff --git a/test/entt/meta/meta_prop.cpp b/test/entt/meta/meta_prop.cpp index e917df119..2c3e1ddca 100644 --- a/test/entt/meta/meta_prop.cpp +++ b/test/entt/meta/meta_prop.cpp @@ -86,7 +86,7 @@ TEST_F(MetaProp, ReRegistration) { SetUp(); - auto *node = entt::internal::meta_node::resolve(); + auto *node = entt::internal::resolve(); auto type = entt::resolve(); ASSERT_FALSE(node->prop.empty()); diff --git a/test/entt/meta/meta_range.cpp b/test/entt/meta/meta_range.cpp index 16297ffe4..9b747411d 100644 --- a/test/entt/meta/meta_range.cpp +++ b/test/entt/meta/meta_range.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -22,21 +23,22 @@ struct MetaRange: ::testing::Test { TEST_F(MetaRange, Range) { using namespace entt::literals; - entt::old_meta_range range{entt::internal::meta_context::local(), nullptr}; + auto range = entt::resolve(); auto it = range.begin(); ASSERT_NE(it, range.end()); ASSERT_TRUE(it != range.end()); ASSERT_FALSE(it == range.end()); - ASSERT_EQ(it->info(), entt::resolve().info()); - ASSERT_EQ((++it)->info(), entt::resolve("int"_hs).info()); - ASSERT_EQ((it++)->info(), entt::resolve().info()); + ASSERT_EQ(it->second.info(), entt::resolve().info()); + ASSERT_EQ((++it)->second.info(), entt::resolve("double"_hs).info()); + ASSERT_EQ((it++)->second.info(), entt::resolve().info()); ASSERT_EQ(it, range.end()); } TEST_F(MetaRange, EmptyRange) { - entt::old_meta_range range{}; + entt::meta_reset(); + auto range = entt::resolve(); ASSERT_EQ(range.begin(), range.end()); } diff --git a/test/entt/meta/meta_type.cpp b/test/entt/meta/meta_type.cpp index 20c6db618..28b6fd910 100644 --- a/test/entt/meta/meta_type.cpp +++ b/test/entt/meta/meta_type.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -191,15 +192,15 @@ TEST_F(MetaType, Resolve) { auto range = entt::resolve(); // it could be "char"_hs rather than entt::hashed_string::value("char") if it weren't for a bug in VS2017 - const auto it = std::find_if(range.begin(), range.end(), [](auto type) { return type.id() == entt::hashed_string::value("clazz"); }); + const auto it = std::find_if(range.begin(), range.end(), [](auto curr) { return curr.second.id() == entt::hashed_string::value("clazz"); }); ASSERT_NE(it, range.end()); - ASSERT_EQ(*it, entt::resolve()); + ASSERT_EQ(it->second, entt::resolve()); bool found = false; for(auto curr: entt::resolve()) { - found = found || curr == entt::resolve(); + found = found || curr.second == entt::resolve(); } ASSERT_TRUE(found); @@ -637,7 +638,7 @@ TEST_F(MetaType, PropertiesAndCornerCases) { TEST_F(MetaType, ResetAndReRegistrationAfterReset) { using namespace entt::literals; - ASSERT_NE(*entt::internal::meta_context::global(), nullptr); + ASSERT_FALSE(entt::internal::meta_context::from(entt::locator::value_or()).value.empty()); entt::meta_reset(); entt::meta_reset(); @@ -654,7 +655,7 @@ TEST_F(MetaType, ResetAndReRegistrationAfterReset) { ASSERT_FALSE(entt::resolve("derived"_hs)); ASSERT_FALSE(entt::resolve("clazz"_hs)); - ASSERT_EQ(*entt::internal::meta_context::global(), nullptr); + ASSERT_TRUE(entt::internal::meta_context::from(entt::locator::value_or()).value.empty()); ASSERT_FALSE(entt::resolve().prop(static_cast(property_t::value))); // implicitly generated default constructor is not cleared @@ -687,14 +688,14 @@ TEST_F(MetaType, ReRegistration) { int count = 0; - for(auto type: entt::resolve()) { - count += static_cast(type); + for([[maybe_unused]] auto type: entt::resolve()) { + ++count; } SetUp(); - for(auto type: entt::resolve()) { - count -= static_cast(type); + for([[maybe_unused]] auto type: entt::resolve()) { + --count; } ASSERT_EQ(count, 0); diff --git a/test/lib/meta/lib.cpp b/test/lib/meta/lib.cpp index c508c013f..518903c84 100644 --- a/test/lib/meta/lib.cpp +++ b/test/lib/meta/lib.cpp @@ -8,6 +8,10 @@ position create_position(int x, int y) { return position{x, y}; } +ENTT_API void share(entt::locator::node_type handle) { + entt::locator::reset(handle); +} + ENTT_API void set_up() { using namespace entt::literals; diff --git a/test/lib/meta/main.cpp b/test/lib/meta/main.cpp index d1a77136d..c8eadf453 100644 --- a/test/lib/meta/main.cpp +++ b/test/lib/meta/main.cpp @@ -6,6 +6,7 @@ #include #include "types.h" +ENTT_API void share(entt::locator::node_type); ENTT_API void set_up(); ENTT_API void tear_down(); ENTT_API entt::meta_any wrap_int(int); @@ -16,6 +17,7 @@ TEST(Lib, Meta) { ASSERT_FALSE(entt::resolve("position"_hs)); ASSERT_FALSE(entt::resolve("velocity"_hs)); + share(entt::locator::handle()); set_up(); entt::meta().conv(); @@ -40,6 +42,9 @@ TEST(Lib, Meta) { ASSERT_EQ(vel.type().data("dx"_hs).get(vel).cast(), 0.); ASSERT_EQ(vel.type().data("dy"_hs).get(vel).cast(), 0.); + pos.reset(); + vel.reset(); + ASSERT_EQ(wrap_int(42).type(), entt::resolve()); ASSERT_EQ(wrap_int(42).cast(), 42); diff --git a/test/lib/meta_plugin/main.cpp b/test/lib/meta_plugin/main.cpp index 999168c1a..13176ebb7 100644 --- a/test/lib/meta_plugin/main.cpp +++ b/test/lib/meta_plugin/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -14,6 +15,7 @@ TEST(Lib, Meta) { ASSERT_FALSE(entt::resolve("position"_hs)); userdata ud{}; + ud.ctx = entt::locator::handle(); cr_plugin ctx; cr_plugin_load(ctx, PLUGIN); diff --git a/test/lib/meta_plugin/plugin.cpp b/test/lib/meta_plugin/plugin.cpp index 9d9fa64eb..52ce1bee9 100644 --- a/test/lib/meta_plugin/plugin.cpp +++ b/test/lib/meta_plugin/plugin.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -33,7 +34,7 @@ void tear_down() { CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) { switch(operation) { case CR_LOAD: - entt::meta_ctx::bind(static_cast(ctx->userdata)->ctx); + entt::locator::reset(static_cast(ctx->userdata)->ctx); set_up(); break; case CR_STEP: diff --git a/test/lib/meta_plugin/types.h b/test/lib/meta_plugin/types.h index 5001d5d70..d4a0a4ebb 100644 --- a/test/lib/meta_plugin/types.h +++ b/test/lib/meta_plugin/types.h @@ -1,6 +1,7 @@ #ifndef ENTT_LIB_META_PLUGIN_TYPES_H #define ENTT_LIB_META_PLUGIN_TYPES_H +#include #include struct position { @@ -14,7 +15,7 @@ struct velocity { }; struct userdata { - entt::meta_ctx ctx; + entt::locator::node_type ctx; entt::meta_any any; }; diff --git a/test/lib/meta_plugin_std/main.cpp b/test/lib/meta_plugin_std/main.cpp index 999168c1a..53f7be365 100644 --- a/test/lib/meta_plugin_std/main.cpp +++ b/test/lib/meta_plugin_std/main.cpp @@ -14,6 +14,7 @@ TEST(Lib, Meta) { ASSERT_FALSE(entt::resolve("position"_hs)); userdata ud{}; + ud.ctx = entt::locator::handle(); cr_plugin ctx; cr_plugin_load(ctx, PLUGIN); diff --git a/test/lib/meta_plugin_std/plugin.cpp b/test/lib/meta_plugin_std/plugin.cpp index 9d9fa64eb..77d60f21a 100644 --- a/test/lib/meta_plugin_std/plugin.cpp +++ b/test/lib/meta_plugin_std/plugin.cpp @@ -33,7 +33,7 @@ void tear_down() { CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) { switch(operation) { case CR_LOAD: - entt::meta_ctx::bind(static_cast(ctx->userdata)->ctx); + entt::locator::reset(static_cast(ctx->userdata)->ctx); set_up(); break; case CR_STEP: diff --git a/test/lib/meta_plugin_std/types.h b/test/lib/meta_plugin_std/types.h index a89a9669d..67d6b7a85 100644 --- a/test/lib/meta_plugin_std/types.h +++ b/test/lib/meta_plugin_std/types.h @@ -15,7 +15,7 @@ struct custom_type_hash; static constexpr entt::id_type value() noexcept { \ return entt::basic_hashed_string>>>{#clazz}; \ } \ - }; + } struct position { int x; @@ -28,7 +28,7 @@ struct velocity { }; struct userdata { - entt::meta_ctx ctx; + entt::locator::node_type ctx; entt::meta_any any; };