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

meta: removed meta_base, meta_base_node is used internally when needed

Michele Caini 5 лет назад
Родитель
Сommit
3eb00382e7
5 измененных файлов с 10 добавлено и 122 удалено
  1. 4 4
      docs/md/meta.md
  2. 6 73
      src/entt/meta/meta.hpp
  3. 0 1
      test/CMakeLists.txt
  4. 0 29
      test/entt/meta/meta_base.cpp
  5. 0 15
      test/entt/meta/meta_type.cpp

+ 4 - 4
docs/md/meta.md

@@ -344,11 +344,11 @@ member function in its API. Destructors are invoked implicitly by `meta_any`
 behind the scenes and users have not to deal with them explicitly. Furthermore,
 they have no name, cannot be searched and wouldn't have member functions to
 expose anyway.<br/>
-Similarly, conversion functions aren't directly accessible. They are used under
-the hood by `meta_any` and the other meta objects when needed.<br/>
-It wouldn't make sense to give direct access to these objects and to open the
+Similarly, conversion functions and base types aren't directly accessible. They
+are used internally by `meta_any` and the meta objects when needed.<br/>
+It wouldn't make sense to give direct access to these elements and to open the
 doors to the possibility of making mistakes. On the other side, the library
-already offers enough methods to use them correctly.
+already offers enough ways to use them correctly.
 
 Meta types and meta objects in general contain much more than what is said: a
 plethora of functions in addition to those listed whose purposes and uses go

+ 6 - 73
src/entt/meta/meta.hpp

@@ -661,47 +661,6 @@ private:
 };
 
 
-/*! @brief Opaque wrapper for base classes. */
-struct meta_base {
-    /*! @brief Node type. */
-    using node_type = internal::meta_base_node;
-
-    /*! @copydoc meta_prop::meta_prop */
-    meta_base(const node_type *curr = nullptr) ENTT_NOEXCEPT
-        : node{curr}
-    {}
-
-    /**
-     * @brief Returns the type to which an object belongs.
-     * @return The type to which the object belongs.
-     */
-    [[nodiscard]] inline meta_type parent() const ENTT_NOEXCEPT;
-
-    /*! @copydoc meta_any::type */
-    [[nodiscard]] inline meta_type type() const ENTT_NOEXCEPT;
-
-    /**
-     * @brief Casts an instance from a parent type to a base type.
-     * @param instance The instance to cast.
-     * @return An opaque pointer to the base type.
-     */
-    [[nodiscard]] const void * cast(const void *instance) const ENTT_NOEXCEPT {
-        return node->cast(instance);
-    }
-
-    /**
-     * @brief Returns true if an object is valid, false otherwise.
-     * @return True if the object is valid, false otherwise.
-     */
-    [[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
-        return !(node == nullptr);
-    }
-
-private:
-    const node_type *node;
-};
-
-
 /*! @brief Opaque wrapper for constructors. */
 struct meta_ctor {
     /*! @brief Node type. */
@@ -714,7 +673,10 @@ struct meta_ctor {
         : node{curr}
     {}
 
-    /*! @copydoc meta_base::parent */
+    /**
+     * @brief Returns the type to which an object belongs.
+     * @return The type to which the object belongs.
+     */
     [[nodiscard]] inline meta_type parent() const ENTT_NOEXCEPT;
 
     /**
@@ -807,7 +769,7 @@ struct meta_data {
         return node->id;
     }
 
-    /*! @copydoc meta_base::parent */
+    /*! @copydoc meta_ctor::parent */
     [[nodiscard]] inline meta_type parent() const ENTT_NOEXCEPT;
 
     /**
@@ -906,7 +868,7 @@ struct meta_func {
         return node->id;
     }
 
-    /*! @copydoc meta_base::parent */
+    /*! @copydoc meta_ctor::parent */
     [[nodiscard]] inline meta_type parent() const ENTT_NOEXCEPT;
 
     /**
@@ -1232,25 +1194,6 @@ public:
         return node->remove_extent();
     }
 
-    /**
-     * @brief Returns a range to use to visit top-level bases.
-     * @return An iterable range to use to visit top-level bases.
-     */
-    [[nodiscard]] meta_range<meta_base> base() const ENTT_NOEXCEPT {
-        return node->base;
-    }
-
-    /**
-     * @brief Returns the base associated with a given identifier.
-     * @param id Unique identifier.
-     * @return The base associated with the given identifier, if any.
-     */
-    [[nodiscard]] meta_base base(const id_type id) const {
-        return internal::find_if<&node_type::base>([id](const auto *curr) {
-            return curr->type()->id == id;
-        }, node);
-    }
-
     /**
      * @brief Returns a range to use to visit top-level constructors.
      * @return An iterable range to use to visit top-level constructors.
@@ -1577,16 +1520,6 @@ bool meta_any::set(const id_type id, Type &&value) {
 }
 
 
-[[nodiscard]] inline meta_type meta_base::parent() const ENTT_NOEXCEPT {
-    return node->parent;
-}
-
-
-[[nodiscard]] inline meta_type meta_base::type() const ENTT_NOEXCEPT {
-    return node->type();
-}
-
-
 [[nodiscard]] inline meta_type meta_ctor::parent() const ENTT_NOEXCEPT {
     return node->parent;
 }

+ 0 - 1
test/CMakeLists.txt

@@ -187,7 +187,6 @@ SETUP_BASIC_TEST(locator entt/locator/locator.cpp)
 # Test meta
 
 SETUP_BASIC_TEST(meta_any entt/meta/meta_any.cpp)
-SETUP_BASIC_TEST(meta_base entt/meta/meta_base.cpp)
 SETUP_BASIC_TEST(meta_container entt/meta/meta_container.cpp)
 SETUP_BASIC_TEST(meta_ctor entt/meta/meta_ctor.cpp)
 SETUP_BASIC_TEST(meta_data entt/meta/meta_data.cpp)

+ 0 - 29
test/entt/meta/meta_base.cpp

@@ -1,29 +0,0 @@
-#include <gtest/gtest.h>
-#include <entt/core/hashed_string.hpp>
-#include <entt/meta/factory.hpp>
-#include <entt/meta/meta.hpp>
-#include <entt/meta/resolve.hpp>
-
-struct base_t {};
-struct derived_t: base_t {};
-
-struct MetaBase: ::testing::Test {
-    static void SetUpTestCase() {
-        using namespace entt::literals;
-
-        entt::meta<base_t>().type("base"_hs);
-        entt::meta<derived_t>().type("derived"_hs).base<base_t>();
-    }
-};
-
-TEST_F(MetaBase, Functionalities) {
-    using namespace entt::literals;
-
-    auto base = entt::resolve<derived_t>().base("base"_hs);
-    derived_t derived{};
-
-    ASSERT_TRUE(base);
-    ASSERT_EQ(base.parent(), entt::resolve("derived"_hs));
-    ASSERT_EQ(base.type(), entt::resolve<base_t>());
-    ASSERT_EQ(base.cast(&derived), static_cast<base_t *>(&derived));
-}

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

@@ -251,21 +251,6 @@ TEST_F(MetaType, RemoveExtent) {
     ASSERT_EQ(entt::resolve<derived_t>().remove_extent(), entt::resolve<derived_t>());
 }
 
-TEST_F(MetaType, Base) {
-    using namespace entt::literals;
-
-    auto type = entt::resolve<derived_t>();
-    bool iterate = false;
-
-    for(auto curr: type.base()) {
-        ASSERT_EQ(curr.type(), entt::resolve<base_t>());
-        iterate = true;
-    }
-
-    ASSERT_TRUE(iterate);
-    ASSERT_EQ(type.base("base"_hs).type(), entt::resolve<base_t>());
-}
-
 TEST_F(MetaType, Ctor) {
     auto type = entt::resolve<clazz_t>();
     int counter{};