소스 검색

meta: make meta_data_node fully context aware

Michele Caini 3 년 전
부모
커밋
e5c6559836
4개의 변경된 파일11개의 추가작업 그리고 7개의 파일을 삭제
  1. 1 1
      src/entt/meta/factory.hpp
  2. 4 2
      src/entt/meta/meta.hpp
  3. 2 2
      src/entt/meta/node.hpp
  4. 4 2
      src/entt/meta/utility.hpp

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

@@ -106,7 +106,7 @@ class meta_factory {
                 Setter::size,
                 &internal::resolve<std::remove_cv_t<std::remove_reference_t<data_type>>>,
                 &meta_arg<type_list<type_list_element_t<type_list_element_t<Index, args_type>::size != 1u, type_list_element_t<Index, args_type>>...>>,
-                +[](meta_handle instance, meta_any value) { return (meta_setter<Type, value_list_element_v<Index, Setter>>(*instance.operator->(), value.as_ref()) || ...); },
+                +[](meta_handle instance, meta_any value, const meta_ctx &ctx) { return (meta_setter<Type, value_list_element_v<Index, Setter>>(*instance.operator->(), value.as_ref(), ctx) || ...); },
                 &meta_getter<Type, Getter, Policy>});
 
         bucket = &elem.prop;

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

@@ -731,7 +731,8 @@ struct meta_data {
      */
     template<typename Type>
     bool set(meta_handle instance, Type &&value) const {
-        return node->set && node->set(std::move(instance), std::forward<Type>(value));
+        auto &&ctx_TODO = locator<meta_ctx>::value_or();
+        return node->set && node->set(std::move(instance), std::forward<Type>(value), ctx_TODO);
     }
 
     /**
@@ -744,7 +745,8 @@ struct meta_data {
      * @return A wrapper containing the value of the underlying variable.
      */
     [[nodiscard]] meta_any get(meta_handle instance) const {
-        return node->get(std::move(instance));
+        auto &&ctx_TODO = locator<meta_ctx>::value_or();
+        return node->get(std::move(instance), ctx_TODO);
     }
 
     /**

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

@@ -81,8 +81,8 @@ struct meta_data_node {
     size_type arity{0u};
     meta_type_node (*type)(const meta_context &) noexcept {};
     meta_type (*arg)(const size_type, const meta_ctx &) noexcept {};
-    bool (*set)(meta_handle, meta_any){};
-    meta_any (*get)(meta_handle){};
+    bool (*set)(meta_handle, meta_any, const meta_ctx &){};
+    meta_any (*get)(meta_handle, const meta_ctx &){};
     dense_map<id_type, meta_prop_node, identity> prop{};
 };
 

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

@@ -187,10 +187,11 @@ template<typename Type>
  * @tparam Data The actual variable to set.
  * @param instance An opaque instance of the underlying type, if required.
  * @param value Parameter to use to set the variable.
+ * @param ctx The context from which to search for meta types.
  * @return True in case of success, false otherwise.
  */
 template<typename Type, auto Data>
-[[nodiscard]] bool meta_setter([[maybe_unused]] meta_handle instance, [[maybe_unused]] meta_any value) {
+[[nodiscard]] bool meta_setter([[maybe_unused]] meta_handle instance, [[maybe_unused]] meta_any value, const meta_ctx &ctx/*_TODO*/ = locator<meta_ctx>::value_or()) {
     if constexpr(!std::is_same_v<decltype(Data), Type> && !std::is_same_v<decltype(Data), std::nullptr_t>) {
         if constexpr(std::is_member_function_pointer_v<decltype(Data)> || std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>>) {
             using descriptor = meta_function_helper_t<Type, decltype(Data)>;
@@ -230,10 +231,11 @@ template<typename Type, auto Data>
  * @tparam Data The actual variable to get.
  * @tparam Policy Optional policy (no policy set by default).
  * @param instance An opaque instance of the underlying type, if required.
+ * @param ctx The context from which to search for meta types.
  * @return A meta any containing the value of the underlying variable.
  */
 template<typename Type, auto Data, typename Policy = as_is_t>
-[[nodiscard]] meta_any meta_getter([[maybe_unused]] meta_handle instance) {
+[[nodiscard]] meta_any meta_getter([[maybe_unused]] meta_handle instance, const meta_ctx &ctx/*_TODO*/ = locator<meta_ctx>::value_or()) {
     if constexpr(std::is_member_pointer_v<decltype(Data)> || std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>>) {
         if constexpr(!std::is_array_v<std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<decltype(Data), Type &>>>>) {
             if constexpr(std::is_invocable_v<decltype(Data), Type &>) {