Просмотр исходного кода

meta: limit ::context() to meta_any

Michele Caini 1 год назад
Родитель
Сommit
12859bb856

+ 0 - 2
TODO

@@ -36,8 +36,6 @@ TODO:
 * runtime types support for meta for types that aren't backed by C++ types
 * built-in no-pagination storage - no_pagination page size as limits::max
 * any cdynamic to support const ownership construction
-* return meta context from meta objects
 * allow passing arguments to meta setter/getter (we can fallback on meta invoke for everything probably)
 * delegate/sigh: forward connect/disconnect from & to *
 * a few more tests on the improved shrink_to_fit for sparse arrays
-* remove ctx from meta_any (get it from meta_type)

+ 8 - 18
src/entt/meta/meta.hpp

@@ -642,6 +642,14 @@ public:
         return storage;
     }
 
+    /**
+     * @brief Returns the underlying meta context.
+     * @return The underlying meta context.
+     */
+    const meta_ctx &context() const noexcept {
+        return *ctx;
+    }
+
 private:
     any storage;
     const meta_ctx *ctx{&locator<meta_ctx>::value_or()};
@@ -915,14 +923,6 @@ struct meta_data {
         return {node.custom};
     }
 
-    /**
-     * @brief Returns the underlying meta context.
-     * @return The underlying meta context.
-     */
-    const meta_ctx &context() const noexcept {
-        return *ctx;
-    }
-
     /**
      * @brief Returns true if an object is valid, false otherwise.
      * @return True if the object is valid, false otherwise.
@@ -1044,11 +1044,6 @@ struct meta_func {
         return {node.custom};
     }
 
-    /*! @copydoc meta_data::context */
-    const meta_ctx &context() const noexcept {
-        return *ctx;
-    }
-
     /**
      * @brief Returns the next overload of a given function, if any.
      * @return The next overload of the given function, if any.
@@ -1508,11 +1503,6 @@ public:
         return {node.custom};
     }
 
-    /*! @copydoc meta_data::context */
-    const meta_ctx &context() const noexcept {
-        return *ctx;
-    }
-
     /**
      * @brief Returns true if an object is valid, false otherwise.
      * @return True if the object is valid, false otherwise.

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

@@ -136,6 +136,19 @@ TEST_F(MetaAny, Empty) {
     ASSERT_FALSE(std::as_const(any).as_associative_container());
 }
 
+TEST_F(MetaAny, Context) {
+    entt::meta_any any{};
+    entt::meta_ctx ctx{};
+
+    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};
+
+    ASSERT_NE(&any.context(), &entt::locator<entt::meta_ctx>::value_or());
+    ASSERT_EQ(&any.context(), &ctx);
+}
+
 TEST_F(MetaAny, SBO) {
     entt::meta_any any{'c'};
 

+ 0 - 13
test/entt/meta/meta_data.cpp

@@ -163,19 +163,6 @@ TEST_F(MetaData, SafeWhenEmpty) {
     ASSERT_EQ(static_cast<const char *>(data.custom()), nullptr);
 }
 
-TEST_F(MetaData, Context) {
-    entt::meta_data data{};
-    entt::meta_ctx ctx{};
-
-    ASSERT_EQ(&data.context(), &entt::locator<entt::meta_ctx>::value_or());
-    ASSERT_NE(&data.context(), &ctx);
-
-    data = entt::meta_data{ctx, entt::internal::meta_data_node{}};
-
-    ASSERT_NE(&data.context(), &entt::locator<entt::meta_ctx>::value_or());
-    ASSERT_EQ(&data.context(), &ctx);
-}
-
 TEST_F(MetaData, UserTraits) {
     using namespace entt::literals;
 

+ 0 - 13
test/entt/meta/meta_func.cpp

@@ -181,19 +181,6 @@ TEST_F(MetaFunc, SafeWhenEmpty) {
     ASSERT_EQ(func.next(), func);
 }
 
-TEST_F(MetaFunc, Context) {
-    entt::meta_func func{};
-    entt::meta_ctx ctx{};
-
-    ASSERT_EQ(&func.context(), &entt::locator<entt::meta_ctx>::value_or());
-    ASSERT_NE(&func.context(), &ctx);
-
-    func = entt::meta_func{ctx, entt::internal::meta_func_node{}};
-
-    ASSERT_NE(&func.context(), &entt::locator<entt::meta_ctx>::value_or());
-    ASSERT_EQ(&func.context(), &ctx);
-}
-
 TEST_F(MetaFunc, UserTraits) {
     using namespace entt::literals;
 

+ 0 - 13
test/entt/meta/meta_type.cpp

@@ -261,19 +261,6 @@ TEST_F(MetaType, SafeWhenEmpty) {
     ASSERT_EQ(static_cast<const char *>(type.custom()), nullptr);
 }
 
-TEST_F(MetaType, Context) {
-    entt::meta_type type{};
-    entt::meta_ctx ctx{};
-
-    ASSERT_EQ(&type.context(), &entt::locator<entt::meta_ctx>::value_or());
-    ASSERT_NE(&type.context(), &ctx);
-
-    type = entt::meta_type{ctx, entt::internal::meta_type_node{}};
-
-    ASSERT_NE(&type.context(), &entt::locator<entt::meta_ctx>::value_or());
-    ASSERT_EQ(&type.context(), &ctx);
-}
-
 TEST_F(MetaType, UserTraits) {
     ASSERT_EQ(entt::resolve<bool>().traits<test::meta_traits>(), test::meta_traits::none);
     ASSERT_EQ(entt::resolve<clazz>().traits<test::meta_traits>(), test::meta_traits::none);