From 4dafefe46a72ba47468b13d011f8299055081b0f Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 22 Oct 2021 23:59:54 +0800 Subject: *LuaBind --- Runtime/Lua/LuaBind/signal/bind.h | 510 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 510 insertions(+) create mode 100644 Runtime/Lua/LuaBind/signal/bind.h (limited to 'Runtime/Lua/LuaBind/signal/bind.h') diff --git a/Runtime/Lua/LuaBind/signal/bind.h b/Runtime/Lua/LuaBind/signal/bind.h new file mode 100644 index 0000000..e29896b --- /dev/null +++ b/Runtime/Lua/LuaBind/signal/bind.h @@ -0,0 +1,510 @@ +// Aseprite Base Library +// Copyright (c) 2001-2013 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +#ifndef BASE_BIND_H_INCLUDED +#define BASE_BIND_H_INCLUDED +#pragma once + +// BindAdapter0_fun +template +class BindAdapter0_fun +{ + F f; +public: + BindAdapter0_fun(const F& f) : f(f) { } + + R operator()() { return f(); } + + template + R operator()(const A1& a1) { return f(); } + + template + R operator()(const A1& a1, const A2& a2) { return f(); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(); } +}; + +template +class BindAdapter0_fun +{ + F f; +public: + BindAdapter0_fun(const F& f) : f(f) { } + + void operator()() { f(); } + + template + void operator()(const A1& a1) { f(); } + + template + void operator()(const A1& a1, const A2& a2) { f(); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3) { f(); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(); } +}; + +template +BindAdapter0_fun +Bind(const F& f) +{ + return BindAdapter0_fun(f); +} + +// BindAdapter0_mem +template +class BindAdapter0_mem +{ + R (T::*m)(); + T* t; +public: + template + BindAdapter0_mem(R (T::*m)(), T2* t) : m(m), t(t) { } + + R operator()() { return (t->*m)(); } + + template + R operator()(const A1& a1) { return (t->*m)(); } + + template + R operator()(const A1& a1, const A2& a2) { return (t->*m)(); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(); } +}; + +template +class BindAdapter0_mem +{ + void (T::*m)(); + T* t; +public: + template + BindAdapter0_mem(void (T::*m)(), T2* t) : m(m), t(t) { } + + void operator()() { (t->*m)(); } + + template + void operator()(const A1& a1) { (t->*m)(); } + + template + void operator()(const A1& a1, const A2& a2) { (t->*m)(); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(); } +}; + +template +BindAdapter0_mem +Bind(R (T::*m)(), T2* t) +{ + return BindAdapter0_mem(m, t); +} + +// BindAdapter1_fun +template +class BindAdapter1_fun +{ + F f; + X1 x1; +public: + BindAdapter1_fun(const F& f, X1 x1) : f(f), x1(x1) { } + + R operator()() { return f(x1); } + + template + R operator()(const A1& a1) { return f(x1); } + + template + R operator()(const A1& a1, const A2& a2) { return f(x1); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1); } +}; + +template +class BindAdapter1_fun +{ + F f; + X1 x1; +public: + BindAdapter1_fun(const F& f, X1 x1) : f(f), x1(x1) { } + + void operator()() { f(x1); } + + template + void operator()(const A1& a1) { f(x1); } + + template + void operator()(const A1& a1, const A2& a2) { f(x1); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1); } +}; + +template +BindAdapter1_fun +Bind(const F& f, X1 x1) +{ + return BindAdapter1_fun(f, x1); +} + +// BindAdapter1_mem +template +class BindAdapter1_mem +{ + R (T::*m)(B1); + T* t; + X1 x1; +public: + template + BindAdapter1_mem(R (T::*m)(B1), T2* t, X1 x1) : m(m), t(t), x1(x1) { } + + R operator()() { return (t->*m)(x1); } + + template + R operator()(const A1& a1) { return (t->*m)(x1); } + + template + R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1); } +}; + +template +class BindAdapter1_mem +{ + void (T::*m)(B1); + T* t; + X1 x1; +public: + template + BindAdapter1_mem(void (T::*m)(B1), T2* t, X1 x1) : m(m), t(t), x1(x1) { } + + void operator()() { (t->*m)(x1); } + + template + void operator()(const A1& a1) { (t->*m)(x1); } + + template + void operator()(const A1& a1, const A2& a2) { (t->*m)(x1); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1); } +}; + +template +BindAdapter1_mem +Bind(R (T::*m)(B1), T2* t, X1 x1) +{ + return BindAdapter1_mem(m, t, x1); +} + +// BindAdapter2_fun +template +class BindAdapter2_fun +{ + F f; + X1 x1; + X2 x2; +public: + BindAdapter2_fun(const F& f, X1 x1, X2 x2) : f(f), x1(x1), x2(x2) { } + + R operator()() { return f(x1, x2); } + + template + R operator()(const A1& a1) { return f(x1, x2); } + + template + R operator()(const A1& a1, const A2& a2) { return f(x1, x2); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1, x2); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1, x2); } +}; + +template +class BindAdapter2_fun +{ + F f; + X1 x1; + X2 x2; +public: + BindAdapter2_fun(const F& f, X1 x1, X2 x2) : f(f), x1(x1), x2(x2) { } + + void operator()() { f(x1, x2); } + + template + void operator()(const A1& a1) { f(x1, x2); } + + template + void operator()(const A1& a1, const A2& a2) { f(x1, x2); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1, x2); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1, x2); } +}; + +template +BindAdapter2_fun +Bind(const F& f, X1 x1, X2 x2) +{ + return BindAdapter2_fun(f, x1, x2); +} + +// BindAdapter2_mem +template +class BindAdapter2_mem +{ + R (T::*m)(B1, B2); + T* t; + X1 x1; + X2 x2; +public: + template + BindAdapter2_mem(R (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { } + + R operator()() { return (t->*m)(x1, x2); } + + template + R operator()(const A1& a1) { return (t->*m)(x1, x2); } + + template + R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1, x2); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1, x2); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1, x2); } +}; + +template +class BindAdapter2_mem +{ + void (T::*m)(B1, B2); + T* t; + X1 x1; + X2 x2; +public: + template + BindAdapter2_mem(void (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { } + + void operator()() { (t->*m)(x1, x2); } + + template + void operator()(const A1& a1) { (t->*m)(x1, x2); } + + template + void operator()(const A1& a1, const A2& a2) { (t->*m)(x1, x2); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1, x2); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1, x2); } +}; + +template +BindAdapter2_mem +Bind(R (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) +{ + return BindAdapter2_mem(m, t, x1, x2); +} + +// BindAdapter3_fun +template +class BindAdapter3_fun +{ + F f; + X1 x1; + X2 x2; + X3 x3; +public: + BindAdapter3_fun(const F& f, X1 x1, X2 x2, X3 x3) : f(f), x1(x1), x2(x2), x3(x3) { } + + R operator()() { return f(x1, x2, x3); } + + template + R operator()(const A1& a1) { return f(x1, x2, x3); } + + template + R operator()(const A1& a1, const A2& a2) { return f(x1, x2, x3); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1, x2, x3); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1, x2, x3); } +}; + +template +class BindAdapter3_fun +{ + F f; + X1 x1; + X2 x2; + X3 x3; +public: + BindAdapter3_fun(const F& f, X1 x1, X2 x2, X3 x3) : f(f), x1(x1), x2(x2), x3(x3) { } + + void operator()() { f(x1, x2, x3); } + + template + void operator()(const A1& a1) { f(x1, x2, x3); } + + template + void operator()(const A1& a1, const A2& a2) { f(x1, x2, x3); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1, x2, x3); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1, x2, x3); } +}; + +template +BindAdapter3_fun +Bind(const F& f, X1 x1, X2 x2, X3 x3) +{ + return BindAdapter3_fun(f, x1, x2, x3); +} + +// BindAdapter3_mem +template +class BindAdapter3_mem +{ + R (T::*m)(B1, B2, B3); + T* t; + X1 x1; + X2 x2; + X3 x3; +public: + template + BindAdapter3_mem(R (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2, X3 x3) : m(m), t(t), x1(x1), x2(x2), x3(x3) { } + + R operator()() { return (t->*m)(x1, x2, x3); } + + template + R operator()(const A1& a1) { return (t->*m)(x1, x2, x3); } + + template + R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1, x2, x3); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1, x2, x3); } + + template + R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1, x2, x3); } +}; + +template +class BindAdapter3_mem +{ + void (T::*m)(B1, B2, B3); + T* t; + X1 x1; + X2 x2; + X3 x3; +public: + template + BindAdapter3_mem(void (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { } + + void operator()() { (t->*m)(x1, x2, x3); } + + template + void operator()(const A1& a1) { (t->*m)(x1, x2, x3); } + + template + void operator()(const A1& a1, const A2& a2) { (t->*m)(x1, x2, x3); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1, x2, x3); } + + template + void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1, x2, x3); } +}; + +template +BindAdapter3_mem +Bind(R (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2) +{ + return BindAdapter3_mem(m, t, x1, x2); +} + +// Helper class to holds references as pointers (to avoid copying the +// original object). +template +class RefWrapper +{ + T* ptr; +public: + RefWrapper(T& ref) : ptr(&ref) { } + operator T&() const { return *ptr; } +}; + +// Creates RefWrappers, useful to wrap arguments that have to be +// passed as a reference when you use Bind. +template +RefWrapper Ref(T& ref) +{ + return RefWrapper(ref); +} + +#endif -- cgit v1.1-26-g67d0