--- gvpe/src/callback.h 2006/01/14 11:21:12 1.9 +++ gvpe/src/callback.h 2018/11/18 00:02:56 1.16 @@ -1,373 +1,75 @@ -// THIS IS A GENERATED FILE: RUN callback.pl to regenerate it -// THIS IS A GENERATED FILE: callback.pl is part of the GVPE -// THIS IS A GENERATED FILE: distribution. - /* - callback.h -- C++ callback mechanism - Copyright (C) 2003-2006 Marc Lehmann - - This file is part of GVPE. - - GVPE is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with gvpe; if not, write to the Free Software - Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * callback.h -- C++ callback mechanism + * Copyright (C) 2003-2018 Marc Lehmann + * + * This file is part of GVPE. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + * + * Additional permission under GNU GPL version 3 section 7 + * + * If you modify this Program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a modified + * version of that library), containing parts covered by the terms of the + * OpenSSL or SSLeay licenses, the licensors of this Program grant you + * additional permission to convey the resulting work. Corresponding + * Source for a non-source form of such a combination shall include the + * source code for the parts of OpenSSL used as well as that of the + * covered work. */ #ifndef CALLBACK_H__ #define CALLBACK_H__ -template -class callback0 { - struct object { }; - - void *obj; - R (object::*meth)(); - - /* a proxy is a kind of recipe on how to call a specific class method */ - struct proxy_base { - virtual R call (void *obj, R (object::*meth)()) const = 0; - }; - template - struct proxy : proxy_base { - virtual R call (void *obj, R (object::*meth)()) const - { - return (R)((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (); - } - }; - - proxy_base *prxy; - -public: - template - explicit callback0 (O1 *object, R (O2::*method)()) - { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; - } - - R call() const - { - return prxy->call (obj, meth); - } - - R operator ()() const - { - return call (); - } -}; - -template -class callback1 { - struct object { }; - - void *obj; - R (object::*meth)(A1); - - /* a proxy is a kind of recipe on how to call a specific class method */ - struct proxy_base { - virtual R call (void *obj, R (object::*meth)(A1), A1 a1) const = 0; - }; - template - struct proxy : proxy_base { - virtual R call (void *obj, R (object::*meth)(A1), A1 a1) const - { - return (R)((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (a1); - } - }; - - proxy_base *prxy; - -public: - template - explicit callback1 (O1 *object, R (O2::*method)(A1)) - { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; - } - - R call(A1 a1) const - { - return prxy->call (obj, meth, a1); - } - - R operator ()(A1 a1) const - { - return call (a1); - } -}; +#define CALLBACK_H_VERSION 4 -template -class callback2 { - struct object { }; - - void *obj; - R (object::*meth)(A1, A2); - - /* a proxy is a kind of recipe on how to call a specific class method */ - struct proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2), A1 a1, A2 a2) const = 0; - }; - template - struct proxy : proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2), A1 a1, A2 a2) const - { - return (R)((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (a1, a2); - } - }; - - proxy_base *prxy; - -public: - template - explicit callback2 (O1 *object, R (O2::*method)(A1, A2)) - { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; - } - - R call(A1 a1, A2 a2) const - { - return prxy->call (obj, meth, a1, a2); - } - - R operator ()(A1 a1, A2 a2) const - { - return call (a1, a2); - } -}; - -template -class callback3 { - struct object { }; - - void *obj; - R (object::*meth)(A1, A2, A3); - - /* a proxy is a kind of recipe on how to call a specific class method */ - struct proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2, A3), A1 a1, A2 a2, A3 a3) const = 0; - }; - template - struct proxy : proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2, A3), A1 a1, A2 a2, A3 a3) const - { - return (R)((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (a1, a2, a3); - } - }; - - proxy_base *prxy; - -public: - template - explicit callback3 (O1 *object, R (O2::*method)(A1, A2, A3)) - { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; - } - - R call(A1 a1, A2 a2, A3 a3) const - { - return prxy->call (obj, meth, a1, a2, a3); - } - - R operator ()(A1 a1, A2 a2, A3 a3) const - { - return call (a1, a2, a3); - } -}; - -template -class callback4 { - struct object { }; - - void *obj; - R (object::*meth)(A1, A2, A3, A4); - - /* a proxy is a kind of recipe on how to call a specific class method */ - struct proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4), A1 a1, A2 a2, A3 a3, A4 a4) const = 0; - }; - template - struct proxy : proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4), A1 a1, A2 a2, A3 a3, A4 a4) const - { - return (R)((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (a1, a2, a3, a4); - } - }; - - proxy_base *prxy; - -public: - template - explicit callback4 (O1 *object, R (O2::*method)(A1, A2, A3, A4)) - { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; - } - - R call(A1 a1, A2 a2, A3 a3, A4 a4) const - { - return prxy->call (obj, meth, a1, a2, a3, a4); - } - - R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const - { - return call (a1, a2, a3, a4); - } -}; - -template -class callback5 { - struct object { }; - - void *obj; - R (object::*meth)(A1, A2, A3, A4, A5); - - /* a proxy is a kind of recipe on how to call a specific class method */ - struct proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const = 0; - }; - template - struct proxy : proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const - { - return (R)((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (a1, a2, a3, a4, a5); - } - }; - - proxy_base *prxy; - -public: - template - explicit callback5 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5)) - { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; - } - - R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const - { - return prxy->call (obj, meth, a1, a2, a3, a4, a5); - } - - R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const - { - return call (a1, a2, a3, a4, a5); - } -}; - -template -class callback6 { - struct object { }; - - void *obj; - R (object::*meth)(A1, A2, A3, A4, A5, A6); - - /* a proxy is a kind of recipe on how to call a specific class method */ - struct proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const = 0; - }; - template - struct proxy : proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const - { - return (R)((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (a1, a2, a3, a4, a5, a6); - } - }; - - proxy_base *prxy; - -public: - template - explicit callback6 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6)) - { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; - } - - R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const - { - return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6); - } - - R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const - { - return call (a1, a2, a3, a4, a5, a6); - } -}; +template +struct callback; -template -class callback7 { - struct object { }; - - void *obj; - R (object::*meth)(A1, A2, A3, A4, A5, A6, A7); - - /* a proxy is a kind of recipe on how to call a specific class method */ - struct proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const = 0; - }; - template - struct proxy : proxy_base { - virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const - { - return (R)((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (a1, a2, a3, a4, a5, a6, a7); - } - }; - - proxy_base *prxy; - -public: - template - explicit callback7 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7)) - { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; - } - - R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const - { - return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6, a7); - } - - R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const - { - return call (a1, a2, a3, a4, a5, a6, a7); - } +template +struct callback +{ + typedef R (*ptr_type)(void *self, Args...); + + template + void set (K *object) + { + self = object; + func = thunk; + } + + R call (Args... args) const + { + return func (self, args...); + } + + R operator ()(Args... args) const + { + return call (args...); + } + +private: + + void *self; + ptr_type func; + + template + static R thunk (void *self, Args... args) + { + klass *obj = static_cast(self); + return (obj->*method) (args...); + } }; #endif