diff options
-rw-r--r-- | core/variant/variant_call.cpp | 27 | ||||
-rw-r--r-- | core/variant/variant_internal.h | 22 | ||||
-rw-r--r-- | core/variant/variant_setget.cpp | 12 |
3 files changed, 37 insertions, 24 deletions
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index f6fe642493..13514b7b9f 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -42,27 +42,6 @@ typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args); typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args); -template <class T> -struct TypeAdjust { - _FORCE_INLINE_ static void adjust(Variant *r_ret) { - VariantTypeChanger<typename GetSimpleTypeT<T>::type_t>::change(r_ret); - } -}; - -template <> //do nothing for variant -struct TypeAdjust<Variant> { - _FORCE_INLINE_ static void adjust(Variant *r_ret) { - } -}; - -template <> //do nothing for variant -struct TypeAdjust<Object *> { - _FORCE_INLINE_ static void adjust(Variant *r_ret) { - VariantInternal::clear(r_ret); - *r_ret = (Object *)nullptr; - } -}; - template <class R, class T, class... P> static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals); @@ -124,12 +103,12 @@ static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_bas template <class R, class T, class... P> static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...), Variant *v) { - TypeAdjust<R>::adjust(v); + VariantTypeAdjust<R>::adjust(v); } template <class R, class T, class... P> static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...) const, Variant *v) { - TypeAdjust<R>::adjust(v); + VariantTypeAdjust<R>::adjust(v); } template <class T, class... P> @@ -144,7 +123,7 @@ static _FORCE_INLINE_ void vc_change_return_type(void (T::*method)(P...) const, template <class R, class... P> static _FORCE_INLINE_ void vc_change_return_type(R (*method)(P...), Variant *v) { - TypeAdjust<R>::adjust(v); + VariantTypeAdjust<R>::adjust(v); } template <class R, class T, class... P> diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 3ac7f32dec..3c3be44ef7 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -1128,4 +1128,26 @@ struct VariantTypeChanger { } }; +template <class T> +struct VariantTypeAdjust { + _FORCE_INLINE_ static void adjust(Variant *r_ret) { + VariantTypeChanger<typename GetSimpleTypeT<T>::type_t>::change(r_ret); + } +}; + +template <> +struct VariantTypeAdjust<Variant> { + _FORCE_INLINE_ static void adjust(Variant *r_ret) { + // Do nothing for variant. + } +}; + +template <> +struct VariantTypeAdjust<Object *> { + _FORCE_INLINE_ static void adjust(Variant *r_ret) { + VariantInternal::clear(r_ret); + *r_ret = (Object *)nullptr; + } +}; + #endif // VARIANT_INTERNAL_H diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index 05fe2b80d9..59dde707c7 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -44,6 +44,7 @@ *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ } \ static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ } \ static void ptr_get(const void *base, void *member) { \ @@ -74,6 +75,7 @@ *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ } \ static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ } \ static void ptr_get(const void *base, void *member) { \ @@ -107,6 +109,7 @@ *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ } \ static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ } \ static void ptr_get(const void *base, void *member) { \ @@ -137,6 +140,7 @@ *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ } \ static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ } \ static void ptr_get(const void *base, void *member) { \ @@ -170,6 +174,7 @@ *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ } \ static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ } \ static void ptr_get(const void *base, void *member) { \ @@ -200,6 +205,7 @@ *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ } \ static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ } \ static void ptr_get(const void *base, void *member) { \ @@ -233,6 +239,7 @@ *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \ } \ static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \ } \ static void ptr_get(const void *base, void *member) { \ @@ -617,6 +624,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { oob = true; \ return; \ } \ + VariantTypeAdjust<m_elem_type>::adjust(value); \ *VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ oob = false; \ } \ @@ -694,6 +702,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { oob = true; \ return; \ } \ + VariantTypeAdjust<m_elem_type>::adjust(value); \ *VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ oob = false; \ } \ @@ -768,6 +777,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { oob = true; \ return; \ } \ + VariantTypeAdjust<m_elem_type>::adjust(value); \ *VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ oob = false; \ } \ @@ -830,6 +840,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { oob = true; \ return; \ } \ + VariantTypeAdjust<m_elem_type>::adjust(value); \ *VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))m_accessor[index]; \ oob = false; \ } \ @@ -886,6 +897,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { oob = true; \ return; \ } \ + VariantTypeAdjust<m_elem_type>::adjust(value); \ *VariantGetInternalPtr<m_elem_type>::get_ptr(value) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_get(index); \ oob = false; \ } \ |