From 8d760ba54b99f48bb27451e483a8108ce2b7f07b Mon Sep 17 00:00:00 2001 From: AWE Henry Date: Sun, 2 Feb 2025 20:23:02 +0800 Subject: [PATCH] Cleanup & remove deprecated code 1. Remove unused or duplicate code 2. Remove deprecated APIs for generic wrapper 3. Formatting 4. Mark internal things as private --- include/asbind20/bind.hpp | 715 ++++++++--------------------------- include/asbind20/utility.hpp | 77 +--- test/shared_test_lib.cpp | 4 +- test/test_utility.cpp | 25 -- 4 files changed, 156 insertions(+), 665 deletions(-) diff --git a/include/asbind20/bind.hpp b/include/asbind20/bind.hpp index fb432d7..b8ddf33 100644 --- a/include/asbind20/bind.hpp +++ b/include/asbind20/bind.hpp @@ -31,7 +31,9 @@ class [[nodiscard]] namespace_ } namespace_( - AS_NAMESPACE_QUALIFIER asIScriptEngine* engine, const char* ns, bool nested = true + AS_NAMESPACE_QUALIFIER asIScriptEngine* engine, + const char* ns, + bool nested = true ) : m_engine(engine), m_prev(engine->GetDefaultNamespace()) { @@ -692,20 +694,6 @@ class global final : public register_helper_base return *this; } - template < - native_function auto Function, - asECallConvTypes CallConv = asCALL_CDECL> - [[deprecated("Use the version with fp<>")]] - global& function(use_generic_t, const char* decl) - { - function( - decl, - to_asGENFUNC_t(fp, call_conv) - ); - - return *this; - } - template < auto Function, asECallConvTypes CallConv = asCALL_CDECL> @@ -725,36 +713,9 @@ class global final : public register_helper_base return *this; } - template < - native_function auto Function, - asECallConvTypes CallConv = asCALL_CDECL> - requires(!std::is_member_function_pointer_v>) - [[deprecated("Use the version with fp<>")]] - global& function(const char* decl) - { - if constexpr(ForceGeneric) - { - function(use_generic, decl); - } - else - { - [[maybe_unused]] - int r = 0; - r = m_engine->RegisterGlobalFunction( - decl, - to_asSFuncPtr(Function), - CallConv - ); - assert(r >= 0); - } - - return *this; - } - template < auto Function, AS_NAMESPACE_QUALIFIER asECallConvTypes CallConv = detail::deduce_function_callconv>()> - global& function( const char* decl, fp_wrapper_t, @@ -825,37 +786,6 @@ class global final : public register_helper_base return *this; } - template < - native_function auto Function, - typename T> - requires(std::is_member_function_pointer_v>) - [[deprecated("Use the version with fp<>")]] - global& function(use_generic_t, const char* decl, T& instance) - { - function( - decl, - to_asGENFUNC_t(fp, call_conv), - instance - ); - - return *this; - } - - template < - native_function auto Function, - typename T> - requires(std::is_member_function_pointer_v>) - [[deprecated("Use the version with fp<>")]] - global& function(const char* decl, T& instance) - { - if constexpr(ForceGeneric) - function(use_generic, decl, instance); - else - function(decl, Function, instance); - - return *this; - } - template < auto Function, typename T> @@ -920,7 +850,7 @@ class global final : public register_helper_base global& function( const char* decl, - asGENFUNC_t gfn, + AS_NAMESPACE_QUALIFIER asGENFUNC_t gfn, void* auxiliary = nullptr ) { @@ -929,7 +859,7 @@ class global final : public register_helper_base r = m_engine->RegisterGlobalFunction( decl, to_asSFuncPtr(gfn), - asCALL_GENERIC, + AS_NAMESPACE_QUALIFIER asCALL_GENERIC, auxiliary ); assert(r >= 0); @@ -1025,7 +955,9 @@ class global final : public register_helper_base [[maybe_unused]] int r = 0; r = m_engine->SetMessageCallback( - to_asSFuncPtr(fn), obj, asCALL_CDECL + to_asSFuncPtr(fn), + obj, + AS_NAMESPACE_QUALIFIER asCALL_CDECL ); assert(r >= 0); @@ -1039,39 +971,15 @@ class global final : public register_helper_base [[maybe_unused]] int r = 0; r = m_engine->SetMessageCallback( - to_asSFuncPtr(fn), (void*)std::addressof(obj), asCALL_THISCALL + to_asSFuncPtr(fn), + (void*)std::addressof(obj), + AS_NAMESPACE_QUALIFIER asCALL_THISCALL ); assert(r >= 0); return *this; } - /** - * Generic calling convention for message callback is not supported - */ - template - global& message_callback(use_generic_t, void* obj = nullptr) = delete; - template - global& message_callback(use_generic_t, T& obj) = delete; - - template - requires(!std::is_member_function_pointer_v>) - global& message_callback(void* obj = nullptr) - { - message_callback(Callback, obj); - - return *this; - } - - template - requires(std::is_member_function_pointer_v>) - global& message_callback(T& obj) - { - message_callback(Callback, obj); - - return *this; - } - /** * Generic calling convention for exception translator is not supported. */ @@ -1087,7 +995,9 @@ class global final : public register_helper_base [[maybe_unused]] int r = 0; r = m_engine->SetTranslateAppExceptionCallback( - to_asSFuncPtr(fn), obj, asCALL_CDECL + to_asSFuncPtr(fn), + obj, + AS_NAMESPACE_QUALIFIER asCALL_CDECL ); assert(r >= 0); @@ -1101,38 +1011,14 @@ class global final : public register_helper_base [[maybe_unused]] int r = 0; r = m_engine->SetTranslateAppExceptionCallback( - to_asSFuncPtr(fn), (void*)std::addressof(obj), asCALL_THISCALL + to_asSFuncPtr(fn), + (void*)std::addressof(obj), + AS_NAMESPACE_QUALIFIER asCALL_THISCALL ); assert(r >= 0); return *this; } - - /** - * Generic calling convention for exception translator is not supported - */ - template - global& exception_translator(use_generic_t, void* obj = nullptr) = delete; - template - global& exception_translator(use_generic_t, T& obj) = delete; - - template - requires(!std::is_member_function_pointer_v>) - global& exception_translator(void* obj = nullptr) - { - exception_translator(Callback, obj); - - return *this; - } - - template - requires(std::is_member_function_pointer_v>) - global& exception_translator(T& obj) - { - exception_translator(Callback, obj); - - return *this; - } }; global(asIScriptEngine*) -> global; @@ -1241,32 +1127,11 @@ class class_register_helper_base : public register_helper_base m_name, decl, to_asSFuncPtr(gfn), - asCALL_GENERIC + AS_NAMESPACE_QUALIFIER asCALL_GENERIC ); assert(r >= 0); } - template - void wrapped_method_impl(const char* decl) - { - if constexpr(ForceGeneric) - { - method_impl( - decl, - to_asGENFUNC_t(fp, call_conv), - call_conv - ); - } - else - { - method_impl( - decl, - Method, - call_conv - ); - } - } - void behaviour_impl( AS_NAMESPACE_QUALIFIER asEBehaviours beh, const char* decl, @@ -1307,50 +1172,6 @@ class class_register_helper_base : public register_helper_base assert(r >= 0); } - template - void wrapped_behaviour_impl(asEBehaviours beh, const char* decl) - { - [[maybe_unused]] - int r = 0; - if constexpr(ForceGeneric) - { - r = m_engine->RegisterObjectBehaviour( - m_name, - beh, - decl, - to_asSFuncPtr(to_asGENFUNC_t(fp, call_conv)), - asCALL_GENERIC - ); - } - else - { - r = m_engine->RegisterObjectBehaviour( - m_name, - beh, - decl, - to_asSFuncPtr(Behaviour), - CallConv - ); - } - assert(r >= 0); - } - - template - void method_auto_callconv(const char* decl, R (*fn)(Args...)) - { - method_impl( - decl, fn, call_conv()> - ); - } - - template - void behaviour_wrapper_impl(asEBehaviours beh, const char* decl, R (*fn)(Args...)) - { - behaviour_impl( - beh, decl, fn, call_conv()> - ); - } - void property_impl(const char* decl, std::size_t off) { [[maybe_unused]] @@ -1633,12 +1454,12 @@ class class_register_helper_base : public register_helper_base void opConv_impl_native(std::string_view ret, bool implicit) { auto wrapper = - wrappers::opConv{}(call_conv); + wrappers::opConv{}(call_conv); method_impl( decl_opConv(ret, implicit).c_str(), wrapper, - call_conv + call_conv ); } @@ -1651,7 +1472,7 @@ class class_register_helper_base : public register_helper_base method_impl( decl_opConv(ret, implicit).c_str(), wrapper, - call_conv + call_conv ); } @@ -1681,16 +1502,18 @@ class value_class final : public class_register_helper_base const char* name, AS_NAMESPACE_QUALIFIER asQWORD flags = 0 ) - : my_base(engine, name), - m_flags((AS_NAMESPACE_QUALIFIER asOBJ_VALUE) | flags | AS_NAMESPACE_QUALIFIER asGetTypeTraits()) + : my_base(engine, name) { - assert(!(m_flags & (AS_NAMESPACE_QUALIFIER asOBJ_REF))); + flags |= AS_NAMESPACE_QUALIFIER asOBJ_VALUE; + flags |= AS_NAMESPACE_QUALIFIER asGetTypeTraits(); - this->template register_object_type(m_flags); + assert(!(flags & (AS_NAMESPACE_QUALIFIER asOBJ_REF))); + + this->template register_object_type(flags); } template - static constexpr auto method_callconv() noexcept + static consteval auto method_callconv() noexcept -> AS_NAMESPACE_QUALIFIER asECallConvTypes { if constexpr(noncapturing_lambda) @@ -1700,7 +1523,7 @@ class value_class final : public class_register_helper_base } template - static constexpr auto method_callconv() noexcept + static consteval auto method_callconv() noexcept -> AS_NAMESPACE_QUALIFIER asECallConvTypes { return method_callconv>(); @@ -2029,7 +1852,7 @@ class value_class final : public class_register_helper_base value_class& destructor(use_generic_t) { - behaviour( + this->behaviour_impl( AS_NAMESPACE_QUALIFIER asBEHAVE_DESTRUCT, "void f()", +[](AS_NAMESPACE_QUALIFIER asIScriptGeneric* gen) -> void @@ -2048,7 +1871,7 @@ class value_class final : public class_register_helper_base destructor(use_generic); else { - behaviour( + this->behaviour_impl( AS_NAMESPACE_QUALIFIER asBEHAVE_DESTRUCT, "void f()", +[](Class* ptr) -> void @@ -2404,45 +2227,34 @@ class value_class final : public class_register_helper_base return *this; } - template - requires(std::is_member_function_pointer_v) - value_class& behaviour(asEBehaviours beh, const char* decl, Fn&& fn, call_conv_t = {}) requires(!ForceGeneric) - { - behaviour_impl(beh, decl, std::forward(fn), call_conv); - - return *this; - } - - template - requires(native_function && CallConv != asCALL_GENERIC) - value_class& behaviour(asEBehaviours beh, const char* decl, R (*fn)(Args...), call_conv_t) requires(!ForceGeneric) - { - this->behaviour_impl(beh, decl, fn, call_conv); - - return *this; - } - - value_class& behaviour(asEBehaviours beh, const char* decl, asGENFUNC_t gfn, call_conv_t = {}) + template < + native_function Fn, + AS_NAMESPACE_QUALIFIER asECallConvTypes CallConv> + requires(CallConv != AS_NAMESPACE_QUALIFIER asCALL_GENERIC) + value_class& method( + const char* decl, + Fn&& fn, + call_conv_t + ) requires(!ForceGeneric) { - this->behaviour_impl(beh, decl, gfn, call_conv); + this->method_impl(decl, std::forward(fn), call_conv); return *this; } template - requires(std::is_member_function_pointer_v) - value_class& method(const char* decl, Fn&& fn, call_conv_t = {}) requires(!ForceGeneric) - { - this->method_impl(decl, std::forward(fn), call_conv); - - return *this; - } - - template - requires(CallConv != asCALL_GENERIC) - value_class& method(const char* decl, Fn&& fn, call_conv_t) requires(!ForceGeneric) + value_class& method( + const char* decl, + Fn&& fn + ) requires(!ForceGeneric) { - this->method_impl(decl, std::forward(fn), call_conv); + constexpr AS_NAMESPACE_QUALIFIER asECallConvTypes conv = + method_callconv(); + this->method_impl( + decl, + fn, + call_conv + ); return *this; } @@ -2450,23 +2262,17 @@ class value_class final : public class_register_helper_base /** * @brief Register a generic function. */ - value_class& method(const char* decl, asGENFUNC_t gfn, call_conv_t = {}) - { - this->method_impl(decl, gfn, call_conv); - - return *this; - } - - /** - * @brief Register a function with generated generic wrapper. - */ - template < - native_function auto Method, - asECallConvTypes CallConv = detail::deduce_method_callconv()> - [[deprecated("Use the version with fp<>")]] - value_class& method(use_generic_t, const char* decl) + value_class& method( + const char* decl, + asGENFUNC_t gfn, + call_conv_t = {} + ) { - method(decl, to_asGENFUNC_t(fp, call_conv), call_conv); + this->method_impl( + decl, + gfn, + call_conv + ); return *this; } @@ -2484,7 +2290,7 @@ class value_class final : public class_register_helper_base this->method_impl( decl, to_asGENFUNC_t(fp, call_conv), - call_conv + call_conv ); return *this; @@ -2497,30 +2303,17 @@ class value_class final : public class_register_helper_base fp_wrapper_t ) { - constexpr asECallConvTypes conv = method_callconv(); + constexpr AS_NAMESPACE_QUALIFIER asECallConvTypes conv = + method_callconv(); this->method_impl( decl, to_asGENFUNC_t(fp, call_conv), - call_conv + call_conv ); return *this; } - template < - native_function auto Method, - asECallConvTypes CallConv = detail::deduce_method_callconv>()> - [[deprecated("Use the version with fp<>")]] - value_class& method(const char* decl) - { - if constexpr(ForceGeneric) - this->template method(use_generic, decl); - else - this->method(decl, Method, call_conv); - - return *this; - } - template < auto Method, asECallConvTypes CallConv> @@ -2544,7 +2337,8 @@ class value_class final : public class_register_helper_base fp_wrapper_t ) { - constexpr asECallConvTypes conv = method_callconv(); + constexpr AS_NAMESPACE_QUALIFIER asECallConvTypes conv = + method_callconv(); if constexpr(ForceGeneric) this->method(use_generic, decl, fp, call_conv); else @@ -2553,14 +2347,6 @@ class value_class final : public class_register_helper_base return *this; } - template - value_class& method(const char* decl, R (*fn)(Args...)) requires(!ForceGeneric) - { - this->template method_auto_callconv(decl, fn); - - return *this; - } - template < noncapturing_lambda Lambda, asECallConvTypes CallConv = detail::deduce_lambda_callconv()> @@ -2568,25 +2354,39 @@ class value_class final : public class_register_helper_base use_generic_t, const char* decl, const Lambda&, - call_conv_t = {} + call_conv_t ) { this->method_impl( decl, to_asGENFUNC_t(Lambda{}, call_conv), - call_conv + call_conv ); return *this; } + template + value_class& method( + use_generic_t, + const char* decl, + const Lambda& + ) + { + constexpr AS_NAMESPACE_QUALIFIER asECallConvTypes conv = + method_callconv(); + this->method(use_generic, decl, Lambda{}, call_conv); + + return *this; + } + template < noncapturing_lambda Lambda, - asECallConvTypes CallConv = detail::deduce_lambda_callconv()> + asECallConvTypes CallConv> value_class& method( const char* decl, const Lambda&, - call_conv_t = {} + call_conv_t ) { if constexpr(ForceGeneric) @@ -2596,6 +2396,19 @@ class value_class final : public class_register_helper_base return *this; } + template + value_class& method( + const char* decl, + const Lambda& + ) + { + constexpr AS_NAMESPACE_QUALIFIER asECallConvTypes conv = + method_callconv(); + this->method(decl, Lambda{}, call_conv); + + return *this; + } + value_class& property(const char* decl, std::size_t off) { this->property_impl(decl, off); @@ -2617,9 +2430,6 @@ class value_class final : public class_register_helper_base return *this; } - -private: - AS_NAMESPACE_QUALIFIER asQWORD m_flags; }; template @@ -2634,22 +2444,25 @@ class reference_class : public class_register_helper_base using class_type = Class; reference_class( - AS_NAMESPACE_QUALIFIER asIScriptEngine* engine, const char* name, AS_NAMESPACE_QUALIFIER asQWORD flags = 0 + AS_NAMESPACE_QUALIFIER asIScriptEngine* engine, + const char* name, + AS_NAMESPACE_QUALIFIER asQWORD flags = 0 ) - : my_base(engine, name), m_flags((AS_NAMESPACE_QUALIFIER asOBJ_REF) | flags) + : my_base(engine, name) { - assert(!(m_flags & (AS_NAMESPACE_QUALIFIER asOBJ_VALUE))); + flags |= AS_NAMESPACE_QUALIFIER asOBJ_REF; + assert(!(flags & (AS_NAMESPACE_QUALIFIER asOBJ_VALUE))); if constexpr(!Template) { - assert(!(m_flags & (AS_NAMESPACE_QUALIFIER asOBJ_TEMPLATE))); + assert(!(flags & (AS_NAMESPACE_QUALIFIER asOBJ_TEMPLATE))); } else { - m_flags |= (AS_NAMESPACE_QUALIFIER asOBJ_TEMPLATE); + flags |= AS_NAMESPACE_QUALIFIER asOBJ_TEMPLATE; } - this->template register_object_type(m_flags); + this->template register_object_type(flags); } template @@ -2669,31 +2482,10 @@ class reference_class : public class_register_helper_base return method_callconv>(); } - reference_class& behaviour(asEBehaviours beh, const char* decl, asGENFUNC_t gfn, call_conv_t) - { - this->behaviour_impl(beh, decl, gfn, call_conv); - - return *this; - } - - reference_class& behaviour(asEBehaviours beh, const char* decl, asGENFUNC_t gfn) - { - behaviour(beh, decl, gfn, call_conv); - - return *this; - } - - template - requires(CallConv != asCALL_GENERIC) - reference_class& behaviour(asEBehaviours beh, const char* decl, Fn&& fn, call_conv_t) requires(!ForceGeneric) - { - this->behaviour_impl(beh, decl, std::forward(fn), call_conv); - - return *this; - } - +private: static constexpr char decl_template_callback[] = "bool f(int&in,bool&out)"; +public: reference_class& template_callback(asGENFUNC_t gfn) requires(Template) { this->behaviour_impl( @@ -2707,7 +2499,6 @@ class reference_class : public class_register_helper_base } template - requires(!std::is_member_function_pointer_v>) reference_class& template_callback(Fn&& fn) requires(Template && !ForceGeneric) { this->behaviour_impl( @@ -2743,84 +2534,48 @@ class reference_class : public class_register_helper_base return *this; } - template - [[deprecated("Use the version with fp<>")]] - reference_class& template_callback(use_generic_t) requires(Template) - { - template_callback( - to_asGENFUNC_t(fp, call_conv) - ); - - return *this; - } - - template - [[deprecated("Use the version with fp<>")]] - reference_class& template_callback() requires(Template) - { - if constexpr(ForceGeneric) - template_callback(use_generic); - else - template_callback(Callback); - - return *this; - } - - template - requires(std::is_member_function_pointer_v>) - reference_class& method(const char* decl, Fn&& fn, call_conv_t = {}) requires(!ForceGeneric) - { - this->method_impl(decl, std::forward(fn), call_conv); - - return *this; - } - - template - requires(!std::is_member_function_pointer_v> && CallConv != asCALL_GENERIC) - reference_class& method(const char* decl, Fn&& fn, call_conv_t) requires(!ForceGeneric) + template < + native_function Fn, + asECallConvTypes CallConv> + requires(CallConv != AS_NAMESPACE_QUALIFIER asCALL_GENERIC) + reference_class& method( + const char* decl, + Fn&& fn, + call_conv_t + ) requires(!ForceGeneric) { this->method_impl(decl, std::forward(fn), call_conv); return *this; } - reference_class& method(const char* decl, asGENFUNC_t gfn, call_conv_t = {}) - { - this->method_impl(decl, gfn, call_conv); - - return *this; - } - - template - requires(native_function) - reference_class& method(const char* decl, R (*fn)(Args...)) requires(!ForceGeneric) - { - this->template method_auto_callconv(decl, fn); - - return *this; - } - - template < - native_function auto Function, - asECallConvTypes CallConv = detail::deduce_method_callconv>()> - [[deprecated("Use the version with fp<>")]] - reference_class& method(use_generic_t, const char* decl) + template + reference_class& method( + const char* decl, + Fn&& fn + ) requires(!ForceGeneric) { - method(decl, to_asGENFUNC_t(fp, call_conv), call_conv); - + constexpr AS_NAMESPACE_QUALIFIER asECallConvTypes conv = + method_callconv(); + this->method( + decl, + std::forward(fn), + call_conv + ); return *this; } - template < - native_function auto Function, - asECallConvTypes CallConv = detail::deduce_method_callconv>()> - [[deprecated("Use the version with fp<>")]] - reference_class& method(const char* decl) + reference_class& method( + const char* decl, + AS_NAMESPACE_QUALIFIER asGENFUNC_t gfn, + call_conv_t = {} + ) { - if constexpr(ForceGeneric) - this->template method(use_generic, decl); - else - this->method_impl(decl, Function, call_conv); + this->method_impl( + decl, + gfn, + call_conv + ); return *this; } @@ -2838,7 +2593,7 @@ class reference_class : public class_register_helper_base this->method_impl( decl, to_asGENFUNC_t(fp, call_conv), - call_conv + call_conv ); return *this; @@ -2873,7 +2628,7 @@ class reference_class : public class_register_helper_base this->method_impl( decl, to_asGENFUNC_t(fp, call_conv), - call_conv + call_conv ); return *this; @@ -2895,6 +2650,7 @@ class reference_class : public class_register_helper_base return *this; } +private: std::string decl_factory(std::string_view params) const { if constexpr(Template) @@ -2927,7 +2683,6 @@ class reference_class : public class_register_helper_base } } -private: template static consteval bool check_factory_args() { @@ -2953,7 +2708,7 @@ class reference_class : public class_register_helper_base reference_class& factory_function( std::string_view params, Class* (*fn)(Args...), - call_conv_t = {} + call_conv_t = {} ) requires(!ForceGeneric) { [[maybe_unused]] @@ -3442,11 +3197,11 @@ class reference_class : public class_register_helper_base } \ reference_class& func_name(AS_NAMESPACE_QUALIFIER asGENFUNC_t gfn) \ { \ - this->behaviour( \ + this->behaviour_impl( \ AS_NAMESPACE_QUALIFIER as_beh, \ as_decl, \ gfn, \ - call_conv \ + call_conv \ ); \ return *this; \ } \ @@ -3470,184 +3225,13 @@ class reference_class : public class_register_helper_base } ASBIND20_REFERENCE_CLASS_BEH(addref, asBEHAVE_ADDREF, "void f()") - - using addref_t = void (Class::*)(); - - template - [[deprecated("Use the version with fp<>")]] - reference_class& addref(use_generic_t) - { - addref(to_asGENFUNC_t(fp, call_conv)); - - return *this; - } - - template - [[deprecated("Use the version with fp<>")]] - reference_class& addref() - { - if constexpr(ForceGeneric) - addref(use_generic); - else - addref(AddRef); - - return *this; - } - ASBIND20_REFERENCE_CLASS_BEH(release, asBEHAVE_RELEASE, "void f()") - - using release_t = void (Class::*)(); - - template - [[deprecated("Use the version with fp<>")]] - reference_class& release(use_generic_t) - { - release(to_asGENFUNC_t(fp, call_conv)); - - return *this; - } - - template - [[deprecated("Use the version with fp<>")]] - reference_class& release() - { - if constexpr(ForceGeneric) - release(use_generic); - else - release(Release); - - return *this; - } - ASBIND20_REFERENCE_CLASS_BEH(get_refcount, asBEHAVE_GETREFCOUNT, "int f()") - - using get_refcount_t = int (Class::*)() const; - - template - [[deprecated("Use the version with fp<>")]] - reference_class& get_refcount(use_generic_t) - { - get_refcount(to_asGENFUNC_t(fp, call_conv)); - - return *this; - } - - template - [[deprecated("Use the version with fp<>")]] - reference_class& get_refcount() - { - if constexpr(ForceGeneric) - get_refcount(use_generic); - else - get_refcount(GetRefCount); - - return *this; - } - ASBIND20_REFERENCE_CLASS_BEH(set_gc_flag, asBEHAVE_SETGCFLAG, "void f()") - - using set_gc_flag_t = void (Class::*)(); - - template - [[deprecated("Use the version with fp<>")]] - reference_class& set_gc_flag(use_generic_t) - { - set_gc_flag(to_asGENFUNC_t(fp, call_conv)); - - return *this; - } - - template - [[deprecated("Use the version with fp<>")]] - reference_class& set_gc_flag() - { - if constexpr(ForceGeneric) - set_gc_flag(use_generic); - else - set_gc_flag(SetGCFlag); - - return *this; - } - ASBIND20_REFERENCE_CLASS_BEH(get_gc_flag, asBEHAVE_GETGCFLAG, "bool f()") - - using get_gc_flag_t = bool (Class::*)() const; - - template - [[deprecated("Use the version with fp<>")]] - reference_class& get_gc_flag(use_generic_t) - { - get_gc_flag(to_asGENFUNC_t(fp, call_conv)); - - return *this; - } - - template - [[deprecated("Use the version with fp<>")]] - reference_class& get_gc_flag() - { - if constexpr(ForceGeneric) - get_gc_flag(use_generic); - else - get_gc_flag(GetGCFlag); - - return *this; - } - ASBIND20_REFERENCE_CLASS_BEH(enum_refs, asBEHAVE_ENUMREFS, "void f(int&in)") - - using enum_refs_t = void (Class::*)(asIScriptEngine*); - - template - [[deprecated("Use the version with fp<>")]] - reference_class& enum_refs(use_generic_t) - { - enum_refs( - to_asGENFUNC_t(fp, call_conv) - ); - - return *this; - } - - template - [[deprecated("Use the version with fp<>")]] - reference_class& enum_refs() - { - if constexpr(ForceGeneric) - enum_refs(use_generic); - else - enum_refs(EnumRefs); - - return *this; - } - ASBIND20_REFERENCE_CLASS_BEH(release_refs, asBEHAVE_RELEASEREFS, "void f(int&in)") - using release_refs_t = void (Class::*)(asIScriptEngine*); - - template - [[deprecated("Use the version with fp<>")]] - reference_class& release_refs(use_generic_t) - { - release_refs( - to_asGENFUNC_t(fp, call_conv) - ); - - return *this; - } - - template - [[deprecated("Use the version with fp<>")]] - reference_class& release_refs() - { - if constexpr(ForceGeneric) - release_refs(use_generic); - else - release_refs(ReleaseRefs); - - return *this; - } - #undef ASBIND20_REFERENCE_CLASS_BEH reference_class& property(const char* decl, std::size_t off) @@ -3671,9 +3255,6 @@ class reference_class : public class_register_helper_base return *this; } - -private: - AS_NAMESPACE_QUALIFIER asQWORD m_flags; }; template @@ -3740,6 +3321,8 @@ requires(std::is_enum_v) class enum_ { public: + using enum_type = Enum; + enum_(AS_NAMESPACE_QUALIFIER asIScriptEngine* engine, const char* name) : m_engine(engine), m_name(name) { diff --git a/include/asbind20/utility.hpp b/include/asbind20/utility.hpp index 2a28c3b..af68131 100644 --- a/include/asbind20/utility.hpp +++ b/include/asbind20/utility.hpp @@ -208,75 +208,6 @@ asSFuncPtr to_asSFuncPtr(Func f) return asFunctionPtr(f); } -namespace detail -{ - template - constexpr T& refptr_helper_ref(T& ref) noexcept - { - return ref; - } - - template - constexpr void refptr_helper_ref(T&&) = delete; - - template - concept refptr_check_helper_ref = requires() { - refptr_helper_ref(std::declval()); - }; -} // namespace detail - -/** - * @brief Wrapper for interchanging between reference and pointer. Similar to the `std::reference_wrapper` - */ -template -class refptr_wrapper -{ -public: - using type = T; - - template - requires(detail::refptr_check_helper_ref && !std::same_as>) - constexpr refptr_wrapper(U&& ref) noexcept(noexcept(detail::refptr_helper_ref(std::forward(ref)))) - : m_ptr(std::addressof(detail::refptr_helper_ref(std::forward(ref)))) - {} - - constexpr refptr_wrapper(T* ptr) noexcept - : m_ptr(ptr) {} - - constexpr refptr_wrapper(const refptr_wrapper&) noexcept = default; - - constexpr refptr_wrapper& operator=(const refptr_wrapper&) noexcept = default; - - constexpr operator T&() const noexcept - { - return *m_ptr; - } - - constexpr operator T*() const noexcept - { - return m_ptr; - } - - constexpr T& get() const noexcept - { - return *m_ptr; - } - - constexpr T* get_ptr() const noexcept - { - return m_ptr; - } - -private: - T* m_ptr; -}; - -template -refptr_wrapper(T&) -> refptr_wrapper; - -template -refptr_wrapper(T*) -> refptr_wrapper; - template requires(!(TypeId & ~asTYPEID_MASK_SEQNBR)) struct primitive_type_of; @@ -1006,7 +937,9 @@ class script_engine handle_type m_engine; }; -inline script_engine make_script_engine(asDWORD version = ANGELSCRIPT_VERSION) +inline script_engine make_script_engine( + AS_NAMESPACE_QUALIFIER asDWORD version = ANGELSCRIPT_VERSION +) { return script_engine( AS_NAMESPACE_QUALIFIER asCreateScriptEngine(version) @@ -1243,7 +1176,7 @@ inline auto get_default_constructor(asITypeInfo* ti) AS_NAMESPACE_QUALIFIER asEBehaviours beh; AS_NAMESPACE_QUALIFIER asIScriptFunction* func = ti->GetBehaviourByIndex(i, &beh); - if(beh == asBEHAVE_CONSTRUCT) + if(beh == AS_NAMESPACE_QUALIFIER asBEHAVE_CONSTRUCT) { if(func->GetParamCount() == 0) return func; @@ -1282,7 +1215,7 @@ inline std::strong_ordering translate_opCmp(int cmp) noexcept */ inline void set_script_exception(const char* info) { - asIScriptContext* ctx = current_context(); + AS_NAMESPACE_QUALIFIER asIScriptContext* ctx = current_context(); if(ctx) ctx->SetException(info); } diff --git a/test/shared_test_lib.cpp b/test/shared_test_lib.cpp index 63b8859..8c87a17 100644 --- a/test/shared_test_lib.cpp +++ b/test/shared_test_lib.cpp @@ -64,8 +64,8 @@ void asbind_test_suite::SetUp() m_engine = asbind20::make_script_engine(); asbind20::global g(m_engine); g - .message_callback<&asbind_test_suite::msg_callback>(*this) - .exception_translator<&asbind_test_suite::ex_translator>(*this); + .message_callback(&asbind_test_suite::msg_callback ,* this) + .exception_translator(&asbind_test_suite::ex_translator, *this); m_engine->SetEngineProperty(asEP_USE_CHARACTER_LITERALS, true); diff --git a/test/test_utility.cpp b/test/test_utility.cpp index 08a0a67..a77f99c 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -35,31 +35,6 @@ consteval bool test_concepts() static_assert(test_concepts()); -TEST(utility, refptr_wrapper) -{ - using asbind20::refptr_wrapper; - - { - int val = 42; - refptr_wrapper r(val); - - static_assert(std::same_as); - - EXPECT_EQ(r.get(), 42); - - [](int& v) - { - EXPECT_EQ(v, 42); - }(r); - - [&val](int* v) - { - EXPECT_EQ(*v, 42); - EXPECT_EQ(&val, v); - }(r); - } -} - namespace test_utility { int f1()