Explorar el Código

meta: added meta_type::is_dereferenceable

Michele Caini hace 5 años
padre
commit
da212dc2a4
Se han modificado 3 ficheros con 16 adiciones y 1 borrados
  1. 2 0
      src/entt/meta/internal.hpp
  2. 8 0
      src/entt/meta/meta.hpp
  3. 6 1
      test/entt/meta/meta_type.cpp

+ 2 - 0
src/entt/meta/internal.hpp

@@ -116,6 +116,7 @@ struct meta_type_node {
     const bool is_function_pointer;
     const bool is_function_pointer;
     const bool is_member_object_pointer;
     const bool is_member_object_pointer;
     const bool is_member_function_pointer;
     const bool is_member_function_pointer;
+    const bool is_dereferenceable;
     const bool is_sequence_container;
     const bool is_sequence_container;
     const bool is_associative_container;
     const bool is_associative_container;
     const size_type rank;
     const size_type rank;
@@ -259,6 +260,7 @@ public:
             std::is_pointer_v<Type> && std::is_function_v<std::remove_pointer_t<Type>>,
             std::is_pointer_v<Type> && std::is_function_v<std::remove_pointer_t<Type>>,
             std::is_member_object_pointer_v<Type>,
             std::is_member_object_pointer_v<Type>,
             std::is_member_function_pointer_v<Type>,
             std::is_member_function_pointer_v<Type>,
+            is_dereferenceable_v<Type>,
             is_sequence_container_v<Type>,
             is_sequence_container_v<Type>,
             is_associative_container_v<Type>,
             is_associative_container_v<Type>,
             std::rank_v<Type>,
             std::rank_v<Type>,

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

@@ -1415,6 +1415,14 @@ public:
         return node->is_member_function_pointer;
         return node->is_member_function_pointer;
     }
     }
 
 
+    /**
+     * @brief Checks whether a type is dereferenceable or not.
+     * @return True if the underlying type is dereferenceable, false otherwise.
+     */
+    [[nodiscard]] bool is_dereferenceable() const ENTT_NOEXCEPT {
+        return node->is_dereferenceable;
+    }
+
     /**
     /**
      * @brief Checks whether a type refers to a sequence container or not.
      * @brief Checks whether a type refers to a sequence container or not.
      * @return True if the underlying type is a sequence container, false
      * @return True if the underlying type is a sequence container, false

+ 6 - 1
test/entt/meta/meta_type.cpp

@@ -1,5 +1,6 @@
-#include <vector>
 #include <map>
 #include <map>
+#include <memory>
+#include <vector>
 #include <gtest/gtest.h>
 #include <gtest/gtest.h>
 #include <entt/core/hashed_string.hpp>
 #include <entt/core/hashed_string.hpp>
 #include <entt/meta/factory.hpp>
 #include <entt/meta/factory.hpp>
@@ -162,6 +163,10 @@ TEST_F(MetaType, Traits) {
     ASSERT_TRUE(entt::resolve<decltype(&clazz_t::member)>().is_member_function_pointer());
     ASSERT_TRUE(entt::resolve<decltype(&clazz_t::member)>().is_member_function_pointer());
     ASSERT_FALSE(entt::resolve<decltype(&clazz_t::value)>().is_member_function_pointer());
     ASSERT_FALSE(entt::resolve<decltype(&clazz_t::value)>().is_member_function_pointer());
 
 
+    ASSERT_TRUE(entt::resolve<int *>().is_dereferenceable());
+    ASSERT_TRUE(entt::resolve<std::shared_ptr<int>>().is_dereferenceable());
+    ASSERT_FALSE(entt::resolve<int>().is_dereferenceable());
+
     ASSERT_TRUE(entt::resolve<std::vector<int>>().is_sequence_container());
     ASSERT_TRUE(entt::resolve<std::vector<int>>().is_sequence_container());
     ASSERT_FALSE((entt::resolve<std::map<int, char>>().is_sequence_container()));
     ASSERT_FALSE((entt::resolve<std::map<int, char>>().is_sequence_container()));