Browse Source

meta: internal changes and cleanup

Michele Caini 4 years ago
parent
commit
efa98379b0
3 changed files with 13 additions and 26 deletions
  1. 3 3
      src/entt/meta/factory.hpp
  2. 9 2
      src/entt/meta/meta.hpp
  3. 1 21
      src/entt/meta/node.hpp

+ 3 - 3
src/entt/meta/factory.hpp

@@ -272,7 +272,7 @@ public:
         static internal::meta_conv_node node{
         static internal::meta_conv_node node{
             nullptr,
             nullptr,
             internal::meta_node<conv_type>::resolve(),
             internal::meta_node<conv_type>::resolve(),
-            [](const void *instance) -> meta_any { return forward_as_meta(static_cast<const Type *>(instance)->*Candidate)(); }
+            [](const meta_any &instance) -> meta_any { return forward_as_meta(static_cast<const Type *>(instance.data())->*Candidate)(); }
             // tricks clang-format
             // tricks clang-format
         };
         };
 
 
@@ -288,7 +288,7 @@ public:
         static internal::meta_conv_node node{
         static internal::meta_conv_node node{
             nullptr,
             nullptr,
             internal::meta_node<conv_type>::resolve(),
             internal::meta_node<conv_type>::resolve(),
-            [](const void *instance) -> meta_any { return forward_as_meta(Candidate(*static_cast<const Type *>(instance))); }
+            [](const meta_any &instance) -> meta_any { return forward_as_meta(Candidate(*static_cast<const Type *>(instance.data()))); }
             // tricks clang-format
             // tricks clang-format
         };
         };
 
 
@@ -312,7 +312,7 @@ public:
         static internal::meta_conv_node node{
         static internal::meta_conv_node node{
             nullptr,
             nullptr,
             internal::meta_node<std::remove_const_t<std::remove_reference_t<To>>>::resolve(),
             internal::meta_node<std::remove_const_t<std::remove_reference_t<To>>>::resolve(),
-            [](const void *instance) -> meta_any { return forward_as_meta(static_cast<To>(*static_cast<const Type *>(instance))); }
+            [](const meta_any &instance) -> meta_any { return forward_as_meta(static_cast<To>(*static_cast<const Type *>(instance.data()))); }
             // tricks clang-format
             // tricks clang-format
         };
         };
 
 

+ 9 - 2
src/entt/meta/meta.hpp

@@ -971,7 +971,14 @@ class meta_type {
                 for(size_type next{}; next < sz && next == (direct + ext) && args[next]; ++next) {
                 for(size_type next{}; next < sz && next == (direct + ext) && args[next]; ++next) {
                     const auto type = args[next].type();
                     const auto type = args[next].type();
                     const auto other = curr->arg(next);
                     const auto other = curr->arg(next);
-                    type.info() == other.info() ? ++direct : (ext += internal::can_cast_or_convert(type.node, other.node));
+
+                    if(const auto &info = other.info(); info == type.info()) {
+                        ++direct;
+                    } else {
+                        ext += internal::find_by<&node_type::base>(info, type.node)
+                               || internal::find_by<&node_type::conv>(info, type.node)
+                               || (type.node->conversion_helper && other.node->conversion_helper);
+                    }
                 }
                 }
 
 
                 if((direct + ext) == sz) {
                 if((direct + ext) == sz) {
@@ -1381,7 +1388,7 @@ bool meta_any::set(const id_type id, Type &&value) {
     if(const auto &info = type.info(); (node && *node->info == info) || internal::find_by<&internal::meta_type_node::base>(info, node)) {
     if(const auto &info = type.info(); (node && *node->info == info) || internal::find_by<&internal::meta_type_node::base>(info, node)) {
         return as_ref();
         return as_ref();
     } else if(const auto *const conv = internal::find_by<&internal::meta_type_node::conv>(info, node); conv) {
     } else if(const auto *const conv = internal::find_by<&internal::meta_type_node::conv>(info, node); conv) {
-        return conv->conv(storage.data());
+        return conv->conv(*this);
     } else if(node && node->conversion_helper && (type.is_arithmetic() || type.is_enum())) {
     } else if(node && node->conversion_helper && (type.is_arithmetic() || type.is_enum())) {
         // exploits the fact that arithmetic types and enums are also default constructible
         // exploits the fact that arithmetic types and enums are also default constructible
         auto other = type.construct();
         auto other = type.construct();

+ 1 - 21
src/entt/meta/node.hpp

@@ -57,7 +57,7 @@ struct meta_base_node {
 struct meta_conv_node {
 struct meta_conv_node {
     meta_conv_node *next;
     meta_conv_node *next;
     meta_type_node *const type;
     meta_type_node *const type;
-    meta_any (*const conv)(const void *);
+    meta_any (*const conv)(const meta_any &);
 };
 };
 
 
 struct meta_ctor_node {
 struct meta_ctor_node {
@@ -227,26 +227,6 @@ template<auto Member, typename Type>
     return nullptr;
     return nullptr;
 }
 }
 
 
-[[nodiscard]] inline bool can_cast_or_convert(const internal::meta_type_node *type, const internal::meta_type_node *other) ENTT_NOEXCEPT {
-    if(type->info == other->info) {
-        return true;
-    }
-
-    for(const auto *curr = type->conv; curr; curr = curr->next) {
-        if(curr->type->info == other->info) {
-            return true;
-        }
-    }
-
-    for(const auto *curr = type->base; curr; curr = curr->next) {
-        if(can_cast_or_convert(curr->type, other)) {
-            return true;
-        }
-    }
-
-    return (type->conversion_helper && other->conversion_helper);
-}
-
 } // namespace internal
 } // namespace internal
 
 
 /**
 /**