From 9347e91db606f3ce19f034da88843b07e7a73594 Mon Sep 17 00:00:00 2001 From: skypjack Date: Fri, 19 Sep 2025 11:30:21 +0200 Subject: [PATCH] meta: stable meta types --- src/entt/meta/context.hpp | 3 ++- src/entt/meta/factory.hpp | 8 ++++---- src/entt/meta/node.hpp | 4 ++-- src/entt/meta/range.hpp | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/entt/meta/context.hpp b/src/entt/meta/context.hpp index 6516f50c2..dbb072d10 100644 --- a/src/entt/meta/context.hpp +++ b/src/entt/meta/context.hpp @@ -1,6 +1,7 @@ #ifndef ENTT_META_CTX_HPP #define ENTT_META_CTX_HPP +#include #include "../container/dense_map.hpp" #include "../core/fwd.hpp" #include "../core/utility.hpp" @@ -14,7 +15,7 @@ namespace internal { struct meta_type_node; struct meta_context { - dense_map value; + dense_map, identity> value; [[nodiscard]] inline static meta_context &from(meta_ctx &ctx); [[nodiscard]] inline static const meta_context &from(const meta_ctx &ctx); diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 5b99f8b6a..b1c3c6709 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -33,7 +33,7 @@ class basic_meta_factory { using invoke_type = std::remove_pointer_t; [[nodiscard]] auto &fetch_node() noexcept { - return meta_context::from(*ctx).value[parent]; + return *meta_context::from(*ctx).value[parent]; } [[nodiscard]] auto *find_member_or_assert() { @@ -131,8 +131,8 @@ public: : ctx{&area}, parent{node.info->hash()}, bucket{parent} { - if(auto &curr = meta_context::from(*ctx).value.try_emplace(parent, std::move(node)).first->second; curr.details == nullptr) { - curr.details = std::make_shared(); + if(auto *curr = meta_context::from(*ctx).value.try_emplace(parent, std::make_unique(std::move(node))).first->second.get(); curr->details == nullptr) { + curr->details = std::make_unique(); } } @@ -513,7 +513,7 @@ inline void meta_reset(meta_ctx &ctx, const id_type id) noexcept { auto &&context = internal::meta_context::from(ctx); for(auto it = context.value.begin(); it != context.value.end();) { - if(it->second.id == id) { + if(it->second->id == id) { it = context.value.erase(it); } else { ++it; diff --git a/src/entt/meta/node.hpp b/src/entt/meta/node.hpp index 5b1d5b989..15e59510f 100644 --- a/src/entt/meta/node.hpp +++ b/src/entt/meta/node.hpp @@ -145,7 +145,7 @@ struct meta_type_node { double (*conversion_helper)(void *, const void *){}; meta_any (*from_void)(const meta_ctx &, void *, const void *){}; meta_template_node templ{}; - std::shared_ptr details; + std::unique_ptr details; }; template @@ -302,7 +302,7 @@ auto setup_node_for() noexcept { [[nodiscard]] inline const meta_type_node *try_resolve(const meta_context &context, const type_info &info) noexcept { const auto it = context.value.find(info.hash()); - return it != context.value.end() ? &it->second : nullptr; + return it != context.value.end() ? it->second.get() : nullptr; } template diff --git a/src/entt/meta/range.hpp b/src/entt/meta/range.hpp index ff795789e..a63bbf66e 100644 --- a/src/entt/meta/range.hpp +++ b/src/entt/meta/range.hpp @@ -70,7 +70,7 @@ struct meta_range_iterator final { [[nodiscard]] constexpr reference operator[](const difference_type value) const noexcept { if constexpr(std::is_same_v) { - return {it[value].first, Type{*ctx, it[value].second}}; + return {it[value].first, Type{*ctx, *it[value].second}}; } else if constexpr(std::is_same_v::value_type, meta_base_node>) { return {it[value].type, Type{*ctx, it[value]}}; } else {