Browse Source

meta: rollback recent changes and use only basic context types internally

Michele Caini 1 year ago
parent
commit
0b97fa5036
3 changed files with 9 additions and 12 deletions
  1. 0 1
      TODO
  2. 5 5
      src/entt/meta/meta.hpp
  3. 4 6
      src/entt/meta/node.hpp

+ 0 - 1
TODO

@@ -43,4 +43,3 @@ TODO:
 * any cdynamic to support const ownership construction
 * track meta context on meta elements
 * no context-less meta_any{} from meta objects if possible
-* auto-context in meta objects to avoid checks on contexts

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

@@ -438,7 +438,7 @@ public:
     template<typename Type>
     [[nodiscard]] const Type *try_cast() const {
         const auto &other = type_id<std::remove_cv_t<Type>>();
-        return static_cast<const Type *>(internal::try_cast(ctx, node, other, storage.data()));
+        return static_cast<const Type *>(internal::try_cast(internal::meta_context::from(*ctx), node, other, storage.data()));
     }
 
     /*! @copydoc try_cast */
@@ -448,7 +448,7 @@ public:
             return std::as_const(*this).try_cast<std::remove_const_t<Type>>();
         } else {
             const auto &other = type_id<Type>();
-            return static_cast<Type *>(const_cast<void *>(internal::try_cast(ctx, node, other, storage.data())));
+            return static_cast<Type *>(const_cast<void *>(internal::try_cast(internal::meta_context::from(*ctx), node, other, storage.data())));
         }
     }
 
@@ -1302,7 +1302,7 @@ public:
      */
     [[nodiscard]] bool can_cast(const meta_type &other) const noexcept {
         // casting this is UB in all cases but we aren't going to use the resulting pointer, so...
-        return other && (internal::try_cast(ctx, node, *other.node.info, this) != nullptr);
+        return other && (internal::try_cast(internal::meta_context::from(*ctx), node, *other.node.info, this) != nullptr);
     }
 
     /**
@@ -1311,7 +1311,7 @@ public:
      * @return True if the conversion is allowed, false otherwise.
      */
     [[nodiscard]] bool can_convert(const meta_type &other) const noexcept {
-        return (internal::try_convert(ctx, node, other.info(), other.is_arithmetic() || other.is_enum(), nullptr, [](const void *, auto &&...args) { return ((static_cast<void>(args), 1) + ... + 0u); }) != 0u);
+        return (internal::try_convert(internal::meta_context::from(*ctx), node, other.info(), other.is_arithmetic() || other.is_enum(), nullptr, [](const void *, auto &&...args) { return ((static_cast<void>(args), 1) + ... + 0u); }) != 0u);
     }
 
     /**
@@ -1546,7 +1546,7 @@ bool meta_any::set(const id_type id, Type &&value) {
 }
 
 [[nodiscard]] inline meta_any meta_any::allow_cast(const meta_type &type) const {
-    return internal::try_convert(ctx, node, type.info(), type.is_arithmetic() || type.is_enum(), storage.data(), [this, &type]([[maybe_unused]] const void *instance, [[maybe_unused]] auto &&...args) {
+    return internal::try_convert(internal::meta_context::from(*ctx), node, type.info(), type.is_arithmetic() || type.is_enum(), storage.data(), [this, &type]([[maybe_unused]] const void *instance, [[maybe_unused]] auto &&...args) {
         if constexpr((std::is_same_v<std::remove_const_t<std::remove_reference_t<decltype(args)>>, internal::meta_type_node> || ...)) {
             return (args.from_void(*ctx, nullptr, instance), ...);
         } else if constexpr((std::is_same_v<std::remove_const_t<std::remove_reference_t<decltype(args)>>, internal::meta_conv_node> || ...)) {

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

@@ -198,15 +198,14 @@ template<typename... Args>
     return value(context);
 }
 
-[[nodiscard]] inline const void *try_cast(const meta_ctx *context, const meta_type_node &from, const type_info &to, const void *instance) noexcept {
+[[nodiscard]] inline const void *try_cast(const meta_context &context, const meta_type_node &from, const type_info &to, const void *instance) noexcept {
     if((from.info != nullptr) && *from.info == to) {
         return instance;
     }
 
     if(from.details) {
         for(auto &&curr: from.details->base) {
-            ENTT_ASSERT(context != nullptr, "Null context not allowed");
-            if(const void *elem = try_cast(context, curr.resolve(meta_context::from(*context)), to, curr.cast(instance)); elem) {
+            if(const void *elem = try_cast(context, curr.resolve(context), to, curr.cast(instance)); elem) {
                 return elem;
             }
         }
@@ -216,7 +215,7 @@ template<typename... Args>
 }
 
 template<typename Func>
-[[nodiscard]] inline auto try_convert(const meta_ctx *context, const meta_type_node &from, const type_info &to, const bool arithmetic_or_enum, const void *instance, Func func) {
+[[nodiscard]] inline auto try_convert(const meta_context &context, const meta_type_node &from, const type_info &to, const bool arithmetic_or_enum, const void *instance, Func func) {
     if(from.info && *from.info == to) {
         return func(instance, from);
     }
@@ -229,8 +228,7 @@ template<typename Func>
         }
 
         for(auto &&curr: from.details->base) {
-            ENTT_ASSERT(context != nullptr, "Null context not allowed");
-            if(auto other = try_convert(context, curr.resolve(meta_context::from(*context)), to, arithmetic_or_enum, curr.cast(instance), func); other) {
+            if(auto other = try_convert(context, curr.resolve(context), to, arithmetic_or_enum, curr.cast(instance), func); other) {
                 return other;
             }
         }