Kaynağa Gözat

meta: refine meta_any::type and add non-regression tests

skypjack 1 gün önce
ebeveyn
işleme
cc0f41e748

+ 1 - 1
TODO

@@ -43,4 +43,4 @@ TODO:
 * test (and fix) resolve where the type id conflicts with the type hash
 * test (and fix) resolve where the type id conflicts with the type hash
 * rename meta-type::id -> ::alias
 * rename meta-type::id -> ::alias
 * assert and test type mismatch on meta factory construction and type(...) - ie id vs alias on overloaded and standard
 * assert and test type mismatch on meta factory construction and type(...) - ie id vs alias on overloaded and standard
-* test meta_any::type(value) and use it with from_void and the like to avoid lookups in some cases
+* use meta_any::type(value) with from_void and the like to avoid lookups in some cases

+ 4 - 2
src/entt/meta/factory.hpp

@@ -184,7 +184,7 @@ public:
      * @param area The context into which to construct meta types.
      * @param area The context into which to construct meta types.
      */
      */
     meta_factory(meta_ctx &area) noexcept
     meta_factory(meta_ctx &area) noexcept
-        : internal::basic_meta_factory{area, internal::setup_node_for<element_type>(), type_hash<Type>::value()} {}
+        : base_type{area, internal::setup_node_for<element_type>(), type_hash<Type>::value()} {}
 
 
     /**
     /**
      * @brief Context aware constructor.
      * @brief Context aware constructor.
@@ -192,7 +192,9 @@ public:
      * @param area The context into which to construct meta types.
      * @param area The context into which to construct meta types.
      */
      */
     meta_factory(meta_ctx &area, const id_type id) noexcept
     meta_factory(meta_ctx &area, const id_type id) noexcept
-        : internal::basic_meta_factory{area, internal::setup_node_for<element_type>(), id} {}
+        : base_type{area, internal::setup_node_for<element_type>(), id} {
+        base_type::type(id, nullptr);
+    }
 
 
     /**
     /**
      * @brief Assigns a custom unique identifier to a meta type.
      * @brief Assigns a custom unique identifier to a meta type.

+ 28 - 0
test/entt/meta/meta_any.cpp

@@ -160,6 +160,34 @@ TEST_F(MetaAny, Context) {
     ASSERT_EQ(&any.context(), &ctx);
     ASSERT_EQ(&any.context(), &ctx);
 }
 }
 
 
+TEST_F(MetaAny, Type) {
+    using namespace entt::literals;
+
+    entt::meta_ctx ctx{};
+
+    entt::meta_factory<clazz>{ctx, "other"_hs}
+        .data<nullptr, &clazz::value>("value"_hs);
+
+    entt::meta_any any{clazz{}};
+    const auto type = entt::resolve(ctx, "other"_hs);
+
+    ASSERT_EQ(any.type(), entt::resolve<clazz>());
+    ASSERT_NE(any.type(), entt::resolve<clazz>(ctx));
+
+    ASSERT_NE(type, entt::resolve<clazz>());
+    ASSERT_NE(type, entt::resolve<clazz>(ctx));
+
+    ASSERT_NE(&any.context(), &ctx);
+    ASSERT_EQ(&any.context(), &entt::locator<entt::meta_ctx>::value());
+    ASSERT_FALSE(any.type().data("value"_hs).is_const());
+
+    any.type(type);
+
+    ASSERT_EQ(&any.context(), &ctx);
+    ASSERT_NE(&any.context(), &entt::locator<entt::meta_ctx>::value());
+    ASSERT_TRUE(any.type().data("value"_hs).is_const());
+}
+
 TEST_F(MetaAny, SBO) {
 TEST_F(MetaAny, SBO) {
     entt::meta_any any{'c'};
     entt::meta_any any{'c'};
 
 

+ 2 - 2
test/entt/meta/meta_context.cpp

@@ -234,8 +234,8 @@ TEST_F(MetaContext, MetaOverloadedType) {
 
 
     ASSERT_NE(global, local);
     ASSERT_NE(global, local);
 
 
-    ASSERT_EQ(global.id(), entt::type_hash<void>::value());
-    ASSERT_EQ(local.id(), entt::type_hash<void>::value());
+    ASSERT_EQ(global.id(), "global"_hs);
+    ASSERT_EQ(local.id(), "local"_hs);
 
 
     clazz instance{'c', 8};
     clazz instance{'c', 8};
     const argument value{2};
     const argument value{2};