Browse Source

meta: refine meta_data_node, prepare to fix meta_data api

skypjack 2 weeks ago
parent
commit
2b9d0684e0
4 changed files with 24 additions and 13 deletions
  1. 1 0
      TODO
  2. 17 9
      src/entt/meta/factory.hpp
  3. 2 2
      src/entt/meta/meta.hpp
  4. 4 2
      src/entt/meta/node.hpp

+ 1 - 0
TODO

@@ -40,3 +40,4 @@ TODO:
 * remove meta invoke/set/get that take meta_any *const args
 * meta: support more args than expected on invoke
 * meta: try to route the meta object path to invoke in meta_setter
+* meta: meta_data set/get_arity and set/get_arg or similar

+ 17 - 9
src/entt/meta/factory.hpp

@@ -386,8 +386,10 @@ public:
                     /* this is never static */
                     stl::is_const_v<stl::remove_reference_t<data_type>> ? internal::meta_traits::is_const : internal::meta_traits::is_none,
                     1u,
-                    &internal::resolve<stl::remove_cvref_t<data_type>>,
+                    0u,
                     &meta_arg<type_list<stl::remove_cvref_t<data_type>>>,
+                    &meta_arg<type_list<>>,
+                    &internal::resolve<stl::remove_cvref_t<data_type>>,
                     &meta_setter<element_type, Data>,
                     &meta_getter<element_type, Data, Policy>});
         } else {
@@ -405,8 +407,10 @@ public:
                     name,
                     ((!stl::is_pointer_v<decltype(Data)> || stl::is_const_v<data_type>) ? internal::meta_traits::is_const : internal::meta_traits::is_none) | internal::meta_traits::is_static,
                     1u,
-                    &internal::resolve<stl::remove_cvref_t<data_type>>,
+                    0u,
                     &meta_arg<type_list<stl::remove_cvref_t<data_type>>>,
+                    &meta_arg<type_list<>>,
+                    &internal::resolve<stl::remove_cvref_t<data_type>>,
                     &meta_setter<element_type, Data>,
                     &meta_getter<element_type, Data, Policy>});
         }
@@ -451,8 +455,8 @@ public:
      */
     template<auto Setter, auto Getter, typename Policy = as_value_t>
     meta_factory data(const id_type id, const char *name = nullptr) noexcept {
-        using descriptor = meta_function_helper_t<element_type, decltype(Getter)>;
-        static_assert(Policy::template value<typename descriptor::return_type>, "Invalid return type for the given policy");
+        using getter = meta_function_helper_t<element_type, decltype(Getter)>;
+        static_assert(Policy::template value<typename getter::return_type>, "Invalid return type for the given policy");
 
         if constexpr(stl::is_same_v<decltype(Setter), stl::nullptr_t>) {
             base_type::data(
@@ -462,12 +466,14 @@ public:
                     /* this is never static */
                     internal::meta_traits::is_const,
                     0u,
-                    &internal::resolve<stl::remove_cvref_t<typename descriptor::return_type>>,
+                    getter::args_type::size,
                     &meta_arg<type_list<>>,
+                    &meta_arg<typename getter::args_type>,
+                    &internal::resolve<stl::remove_cvref_t<typename getter::return_type>>,
                     &meta_setter<element_type, Setter>,
                     &meta_getter<element_type, Getter, Policy>});
         } else {
-            using args_type = meta_function_helper_t<element_type, decltype(Setter)>::args_type;
+            using setter = meta_function_helper_t<element_type, decltype(Setter)>;
 
             base_type::data(
                 internal::meta_data_node{
@@ -475,9 +481,11 @@ public:
                     name,
                     /* this is never static nor const */
                     internal::meta_traits::is_none,
-                    1u,
-                    &internal::resolve<stl::remove_cvref_t<typename descriptor::return_type>>,
-                    &meta_arg<type_list<type_list_element_t<static_cast<stl::size_t>(args_type::size != 1u), args_type>>>,
+                    setter::args_type::size,
+                    getter::args_type::size,
+                    &meta_arg<typename setter::args_type>,
+                    &meta_arg<typename getter::args_type>,
+                    &internal::resolve<stl::remove_cvref_t<typename getter::return_type>>,
                     &meta_setter<element_type, Setter>,
                     &meta_getter<element_type, Getter, Policy>});
         }

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

@@ -844,7 +844,7 @@ struct meta_data: meta_object<internal::meta_data_node> {
      * @return The number of arguments accepted by the data member.
      */
     [[nodiscard]] size_type arity() const noexcept {
-        return node_or_assert().arity;
+        return node_or_assert().set_arity;
     }
 
     /**
@@ -1574,7 +1574,7 @@ inline bool meta_any::assign(meta_any &&other) {
 }
 
 [[nodiscard]] inline meta_type meta_data::arg(const size_type index) const noexcept {
-    return index < arity() ? node_or_assert().arg(*ctx, index) : meta_type{};
+    return index < arity() ? node_or_assert().set_arg(*ctx, index) : meta_type{};
 }
 
 [[nodiscard]] inline meta_type meta_func::ret() const noexcept {

+ 4 - 2
src/entt/meta/node.hpp

@@ -93,9 +93,11 @@ struct meta_data_node {
     id_type id{};
     const char *name{};
     meta_traits traits{meta_traits::is_none};
-    size_type arity{0u};
+    size_type set_arity{0u};
+    size_type get_arity{0u};
+    meta_type (*set_arg)(const meta_ctx &, const size_type) noexcept {};
+    meta_type (*get_arg)(const meta_ctx &, const size_type) noexcept {};
     const meta_type_node &(*type)(const meta_context &) noexcept {};
-    meta_type (*arg)(const meta_ctx &, const size_type) noexcept {};
     bool (*set)(meta_handle, meta_any *const){};
     meta_any (*get)(meta_handle, meta_any *const){};
     meta_custom_node custom{};