1 /****************************************************************************
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
5 ** This file is part of the QxtCore module of the Qt eXTension library
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
21 ** <http://libqxt.sourceforge.net> <foundation@libqxt.org>
23 ****************************************************************************/
25 #ifndef QXTBOUNDCFUNCTION_H
26 #define QXTBOUNDCFUNCTION_H
29 #include <QMetaObject>
30 #include <QGenericArgument>
31 #include <qxtmetaobject.h>
32 #include <qxtboundfunctionbase.h>
36 template <typename FUNCTION, int argc, typename RETURN = void>
37 class QxtBoundCFunction : public QxtBoundFunctionBase {
41 QxtBoundCFunction(QObject* parent, FUNCTION funcPointer, QGenericArgument* params[argc], QByteArray types[argc]) : QxtBoundFunctionBase(parent, params, types), funcPtr(funcPointer) {
42 // initializers only, thanks to template magic
45 virtual bool invokeImpl(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_IMPL_10ARGS(QGenericArgument)) {
46 return qxt_invoke_cfunction_return<FUNCTION, argc, RETURN>(funcPtr, returnValue, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
50 template <typename FUNCTION, int argc>
51 class QxtBoundCFunction<FUNCTION, argc, void> : public QxtBoundFunctionBase {
55 QxtBoundCFunction(QObject* parent, FUNCTION funcPointer, QGenericArgument* params[argc], QByteArray types[argc]) : QxtBoundFunctionBase(parent, params, types), funcPtr(funcPointer) {
56 // initializers only, thanks to template magic
59 virtual bool invokeImpl(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_IMPL_10ARGS(QGenericArgument)) {
60 return qxt_invoke_cfunction<FUNCTION, argc>(funcPtr, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
64 QGenericArgument* qbcfP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
65 QByteArray types[10] = { "", "", "", "", "", "", "", "", "", "" };
67 void testFunction(int a) { a++; return; }
68 template < typename FP > QxtBoundFunction* testBind(FP fn) { return new QxtBoundCFunction<FP, 1>(0, fn, qbcfP, types); }
69 QxtBoundCFunction<void(*)(int), 1> qbcf(0, testFunction, qbcfP, types);
70 QxtBoundFunction* qbf = testBind(testFunction);