From cf1eb700702aec473db0a4794b1a6549ee10bb62 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 12 Jan 2012 20:46:15 +0100 Subject: Fix connection to const slots (or from const signals) Pointer to const member function have a different signature, and hence need their own traits code. Change-Id: Ie4b2434a412f412444fb07ef1388a37cab105ecd Reviewed-by: Stephen Kelly --- src/corelib/kernel/qobjectdefs_impl.h | 121 ++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) (limited to 'src/corelib/kernel/qobjectdefs_impl.h') diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h index 2c85b927bb..55a8904f76 100644 --- a/src/corelib/kernel/qobjectdefs_impl.h +++ b/src/corelib/kernel/qobjectdefs_impl.h @@ -126,6 +126,7 @@ namespace QtPrivate { */ #ifndef Q_COMPILER_VARIADIC_TEMPLATES template struct FunctionPointer { enum {ArgumentCount = -1}; }; + //Pointers to member functions template struct FunctionPointer { typedef Obj Object; @@ -225,6 +226,107 @@ namespace QtPrivate { } }; + //Pointers to const member functions + template struct FunctionPointer + { + typedef Obj Object; + typedef void Arguments; + typedef Ret ReturnType; + typedef Ret (Obj::*Function) () const; + enum {ArgumentCount = 0}; + template + static void call(Function f, Obj *o, void **arg) { (o->*f)(), ApplyReturnValue(arg[0]); } + }; + template struct FunctionPointer + { + typedef Obj Object; + typedef List Arguments; + typedef Ret ReturnType; + typedef Ret (Obj::*Function) (Arg1) const; + enum {ArgumentCount = 1}; + template + static void call(Function f, Obj *o, void **arg) { + (o->*f)((*reinterpret_cast::Type *>(arg[1]))), ApplyReturnValue(arg[0]); + } + }; + template struct FunctionPointer + { + typedef Obj Object; + typedef List > Arguments; + typedef Ret ReturnType; + typedef Ret (Obj::*Function) (Arg1, Arg2) const; + enum {ArgumentCount = 2}; + template + static void call(Function f, Obj *o, void **arg) { + (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), + *reinterpret_cast::Value>::Type *>(arg[2])), ApplyReturnValue(arg[0]); + } + }; + template struct FunctionPointer + { + typedef Obj Object; + typedef List > > Arguments; + typedef Ret ReturnType; + typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3) const; + enum {ArgumentCount = 3}; + template + static void call(Function f, Obj *o, void **arg) { + (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), + *reinterpret_cast::Value>::Type *>(arg[2]), + *reinterpret_cast::Value>::Type *>(arg[3])), ApplyReturnValue(arg[0]); + } + }; + template struct FunctionPointer + { + typedef Obj Object; + typedef List > > > Arguments; + typedef Ret ReturnType; + typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3, Arg4) const; + enum {ArgumentCount = 4}; + template + static void call(Function f, Obj *o, void **arg) { + (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), + *reinterpret_cast::Value>::Type *>(arg[2]), + *reinterpret_cast::Value>::Type *>(arg[3]), + *reinterpret_cast::Value>::Type *>(arg[4])), ApplyReturnValue(arg[0]); + } + }; + template struct FunctionPointer + { + typedef Obj Object; + typedef List > > > > Arguments; + typedef Ret ReturnType; + typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3, Arg4, Arg5) const; + enum {ArgumentCount = 5}; + template + static void call(Function f, Obj *o, void **arg) { + (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), + *reinterpret_cast::Value>::Type *>(arg[2]), + *reinterpret_cast::Value>::Type *>(arg[3]), + *reinterpret_cast::Value>::Type *>(arg[4]), + *reinterpret_cast::Value>::Type *>(arg[5])), ApplyReturnValue(arg[0]); + } + }; + template + struct FunctionPointer + { + typedef Obj Object; + typedef List > > > > > Arguments; + typedef Ret ReturnType; + typedef Ret (Obj::*Function) (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) const; + enum {ArgumentCount = 6}; + template + static void call(Function f, Obj *o, void **arg) { + (o->*f)( *reinterpret_cast::Value>::Type *>(arg[1]), + *reinterpret_cast::Value>::Type *>(arg[2]), + *reinterpret_cast::Value>::Type *>(arg[3]), + *reinterpret_cast::Value>::Type *>(arg[4]), + *reinterpret_cast::Value>::Type *>(arg[5]), + *reinterpret_cast::Value>::Type *>(arg[6])), ApplyReturnValue(arg[0]); + } + }; + + //Static functions template struct FunctionPointer { typedef void Arguments; @@ -315,6 +417,7 @@ namespace QtPrivate { } }; + //Functors template struct Functor; template struct Functor { @@ -401,6 +504,12 @@ namespace QtPrivate { (o->*f)((*reinterpret_cast::Type *>(arg[I+1]))...), ApplyReturnValue(arg[0]); } }; + template + struct FunctorCall, List, R, SlotRet (Obj::*)(SlotArgs...) const> { + static void call(SlotRet (Obj::*f)(SlotArgs...) const, Obj *o, void **arg) { + (o->*f)((*reinterpret_cast::Type *>(arg[I+1]))...), ApplyReturnValue(arg[0]); + } + }; template struct FunctionPointer { @@ -414,6 +523,18 @@ namespace QtPrivate { FunctorCall::Value, SignalArgs, R, Function>::call(f, o, arg); } }; + template struct FunctionPointer + { + typedef Obj Object; + typedef List Arguments; + typedef Ret ReturnType; + typedef Ret (Obj::*Function) (Args...) const; + enum {ArgumentCount = sizeof...(Args)}; + template + static void call(Function f, Obj *o, void **arg) { + FunctorCall::Value, SignalArgs, R, Function>::call(f, o, arg); + } + }; template struct FunctionPointer { -- cgit v1.2.3