Bladeren bron

meta: rebind meta_any with context(ctx)

Michele Caini 1 jaar geleden
bovenliggende
commit
e3e84490e5
3 gewijzigde bestanden met toevoegingen van 17 en 2 verwijderingen
  1. 1 0
      TODO
  2. 10 0
      src/entt/meta/meta.hpp
  3. 6 2
      test/entt/meta/meta_any.cpp

+ 1 - 0
TODO

@@ -35,3 +35,4 @@ TODO:
 * any cdynamic to support const ownership construction
 * allow passing arguments to meta setter/getter (we can fallback on meta invoke probably)
 * meta: review/update rebind policy for handles and arguments
+* meta: deprecate rebinding ctors for meta any/handle

+ 10 - 0
src/entt/meta/meta.hpp

@@ -650,6 +650,16 @@ public:
         return *ctx;
     }
 
+    /**
+     * @brief Returns the underlying meta context.
+     * @return The underlying meta context.
+     */
+    void context(const meta_ctx &area) noexcept {
+        if(ctx = &area; node.resolve != nullptr) {
+            node = node.resolve(internal::meta_context::from(*ctx));
+        }
+    }
+
 private:
     any storage;
     const meta_ctx *ctx{&locator<meta_ctx>::value_or()};

+ 6 - 2
test/entt/meta/meta_any.cpp

@@ -137,14 +137,18 @@ TEST_F(MetaAny, Empty) {
 }
 
 TEST_F(MetaAny, Context) {
-    entt::meta_any any{};
+    using namespace entt::literals;
+
+    entt::meta_any any{std::in_place_type<clazz>};
     const entt::meta_ctx ctx{};
 
+    ASSERT_TRUE(any.type().data("value"_hs));
     ASSERT_EQ(&any.context(), &entt::locator<entt::meta_ctx>::value_or());
     ASSERT_NE(&any.context(), &ctx);
 
-    any = entt::meta_any{entt::meta_ctx_arg, ctx};
+    any.context(ctx);
 
+    ASSERT_FALSE(any.type().data("value"_hs));
     ASSERT_NE(&any.context(), &entt::locator<entt::meta_ctx>::value_or());
     ASSERT_EQ(&any.context(), &ctx);
 }