From 649f04a48c94ee378ca1c2abc0f4bed4ffe4c15a Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 31 Oct 2018 20:14:19 +0200 Subject: [PATCH] Use variatic templates to simplify NoCopy allocator. --- include/sqrat/sqratAllocator.h | 514 +-------------------------------- 1 file changed, 9 insertions(+), 505 deletions(-) diff --git a/include/sqrat/sqratAllocator.h b/include/sqrat/sqratAllocator.h index abf5cc04..206ec4e4 100644 --- a/include/sqrat/sqratAllocator.h +++ b/include/sqrat/sqratAllocator.h @@ -496,516 +496,20 @@ public: return New(vm); } - template + template static SQInteger iNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - SetInstance(vm, 1, new C( - a1.value - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - SetInstance(vm, 1, new C( - a1.value, - a2.value - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - Var a5(vm, 6); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - a5.value - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - Var a5(vm, 6); - Var a6(vm, 7); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - a5.value, - a6.value - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - Var a5(vm, 6); - Var a6(vm, 7); - Var a7(vm, 8); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - a5.value, - a6.value, - a7.value - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - Var a5(vm, 6); - Var a6(vm, 7); - Var a7(vm, 8); - Var a8(vm, 9); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - a5.value, - a6.value, - a7.value, - a8.value - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - Var a5(vm, 6); - Var a6(vm, 7); - Var a7(vm, 8); - Var a8(vm, 9); - Var a9(vm, 10); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - a5.value, - a6.value, - a7.value, - a8.value, - a9.value - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - /// @endcond - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /// @cond DEV - /// following iNew functions are used only if constructors are bound via FmtCtor() in Sqrat::Class (safe to ignore) - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static SQInteger iFmtNew(HSQUIRRELVM vm) { - SQTRY() - - StackStrF fmt(vm, 2); - // Validate the format - if (SQ_FAILED(fmt.Proc(true))) { - return fmt.mRes; - } - - SetInstance(vm, 1, new C( - fmt - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); + try { + SetInstance(vm, 1, ArgFwd{}.Call(vm, 2, [](HSQUIRRELVM /*vm*/, A... a) -> C * { + return new C(a...); + })); + } catch (const Exception& e) { + return sq_throwerror(vm, e.what()); + } catch (...) { + return sq_throwerror(vm, _SC("unknown exception occured")); } return 0; } - template - static SQInteger iFmtNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - - StackStrF fmt(vm, 3); - // Validate the format - if (SQ_FAILED(fmt.Proc(true))) { - return fmt.mRes; - } - - SetInstance(vm, 1, new C( - a1.value, - fmt - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iFmtNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - - StackStrF fmt(vm, 4); - // Validate the format - if (SQ_FAILED(fmt.Proc(true))) { - return fmt.mRes; - } - - SetInstance(vm, 1, new C( - a1.value, - a2.value, - fmt - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iFmtNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - - StackStrF fmt(vm, 5); - // Validate the format - if (SQ_FAILED(fmt.Proc(true))) { - return fmt.mRes; - } - - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - fmt - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iFmtNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - - StackStrF fmt(vm, 6); - // Validate the format - if (SQ_FAILED(fmt.Proc(true))) { - return fmt.mRes; - } - - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - fmt - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iFmtNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - Var a5(vm, 6); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - - StackStrF fmt(vm, 7); - // Validate the format - if (SQ_FAILED(fmt.mRes)) { - return fmt.mRes; - } - - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - a5.value, - fmt - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iFmtNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - Var a5(vm, 6); - Var a6(vm, 7); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - - StackStrF fmt(vm, 8); - // Validate the format - if (SQ_FAILED(fmt.mRes)) { - return fmt.mRes; - } - - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - a5.value, - a6.value, - fmt - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iFmtNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - Var a5(vm, 6); - Var a6(vm, 7); - Var a7(vm, 8); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - - StackStrF fmt(vm, 9); - // Validate the format - if (SQ_FAILED(fmt.Proc(true))) { - return fmt.mRes; - } - - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - a5.value, - a6.value, - a7.value, - fmt - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iFmtNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - Var a5(vm, 6); - Var a6(vm, 7); - Var a7(vm, 8); - Var a8(vm, 9); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - - StackStrF fmt(vm, 10); - // Validate the format - if (SQ_FAILED(fmt.Proc(true))) { - return fmt.mRes; - } - - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - a5.value, - a6.value, - a7.value, - a8.value, - fmt - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } - template - static SQInteger iFmtNew(HSQUIRRELVM vm) { - SQTRY() - Var a1(vm, 2); - Var a2(vm, 3); - Var a3(vm, 4); - Var a4(vm, 5); - Var a5(vm, 6); - Var a6(vm, 7); - Var a7(vm, 8); - Var a8(vm, 9); - Var a9(vm, 10); - SQCATCH_NOEXCEPT(vm) { - return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm)); - } - - StackStrF fmt(vm, 11); - // Validate the format - if (SQ_FAILED(fmt.Proc(true))) { - return fmt.mRes; - } - - SetInstance(vm, 1, new C( - a1.value, - a2.value, - a3.value, - a4.value, - a5.value, - a6.value, - a7.value, - a8.value, - a9.value, - fmt - )); - SQCATCH(vm) { - return sq_throwerror(vm, SQWHAT(vm)); - } - return 0; - } /// @endcond /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////