meta: stable meta types

This commit is contained in:
skypjack
2025-09-19 11:30:21 +02:00
parent bebfbada68
commit 9347e91db6
4 changed files with 9 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
#ifndef ENTT_META_CTX_HPP
#define ENTT_META_CTX_HPP
#include <memory>
#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<id_type, meta_type_node, identity> value;
dense_map<id_type, std::unique_ptr<meta_type_node>, identity> value;
[[nodiscard]] inline static meta_context &from(meta_ctx &ctx);
[[nodiscard]] inline static const meta_context &from(const meta_ctx &ctx);

View File

@@ -33,7 +33,7 @@ class basic_meta_factory {
using invoke_type = std::remove_pointer_t<decltype(meta_func_node::invoke)>;
[[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<meta_type_descriptor>();
if(auto *curr = meta_context::from(*ctx).value.try_emplace(parent, std::make_unique<meta_type_node>(std::move(node))).first->second.get(); curr->details == nullptr) {
curr->details = std::make_unique<meta_type_descriptor>();
}
}
@@ -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;

View File

@@ -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<meta_type_descriptor> details;
std::unique_ptr<meta_type_descriptor> details;
};
template<auto Member, typename Type, typename Value>
@@ -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<typename Type>

View File

@@ -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<It, typename decltype(meta_context::value)::const_iterator>) {
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<typename std::iterator_traits<It>::value_type, meta_base_node>) {
return {it[value].type, Type{*ctx, it[value]}};
} else {