PageRenderTime 261ms CodeModel.GetById 71ms app.highlight 127ms RepoModel.GetById 55ms app.codeStats 0ms

/thirdparty/qxt/qxtweb-standalone/qxtweb/qxtboundcfunction.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 633 lines | 508 code | 57 blank | 68 comment | 16 complexity | 968fedbacad19249c0db6f9a2f966855 MD5 | raw file
  1/****************************************************************************
  2 **
  3 ** Copyright (C) Qxt Foundation. Some rights reserved.
  4 **
  5 ** This file is part of the QxtCore module of the Qxt library.
  6 **
  7 ** This library is free software; you can redistribute it and/or modify it
  8 ** under the terms of the Common Public License, version 1.0, as published
  9 ** by IBM, and/or under the terms of the GNU Lesser General Public License,
 10 ** version 2.1, as published by the Free Software Foundation.
 11 **
 12 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
 13 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
 14 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
 15 ** FITNESS FOR A PARTICULAR PURPOSE.
 16 **
 17 ** You should have received a copy of the CPL and the LGPL along with this
 18 ** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
 19 ** included with the source distribution for more information.
 20 ** If you did not receive a copy of the licenses, contact the Qxt Foundation.
 21 **
 22 ** <http://libqxt.org>  <foundation@libqxt.org>
 23 **
 24 ****************************************************************************/
 25
 26#ifndef QXTBOUNDCFUNCTION_H
 27#define QXTBOUNDCFUNCTION_H
 28
 29#include <qxtboundfunctionbase.h>
 30#include <qxtmetatype.h>
 31#include <qxtglobal.h>
 32#include <QtDebug>
 33
 34#ifndef QXT_DOXYGEN_RUN
 35
 36#define QXT_RETURN(fp) *reinterpret_cast<RETURN*>(returnValue.data()) = (*reinterpret_cast<FUNCTION>(fp))
 37#define QXT_INVOKE(fp) (*reinterpret_cast<FUNCTION>(fp))
 38#define QXT_PARAM(i) *reinterpret_cast<T ## i *>(p ## i .data())
 39
 40template < typename RETURN, typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void,
 41typename T6 = void, typename T7 = void, typename T8 = void, typename T9 = void, typename T10 = void >
 42class /*QXT_CORE_EXPORT*/ qxt_cfunction_return : public QxtGenericFunctionPointer
 43{
 44public:
 45    typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10);
 46    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
 47    {
 48        QXT_10_UNUSED;
 49        QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8), QXT_PARAM(9), QXT_PARAM(10));
 50        return true;
 51    }
 52private:
 53    qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
 54};
 55
 56template <typename RETURN>
 57class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, void, void, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
 58{
 59public:
 60    typedef RETURN(*FUNCTION)();
 61    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
 62    {
 63        QXT_10_UNUSED;
 64        QXT_RETURN(funcPtr)();
 65        return true;
 66    }
 67private:
 68    qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
 69};
 70
 71template <typename RETURN, typename T1>
 72class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, void, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
 73{
 74public:
 75    typedef RETURN(*FUNCTION)(T1);
 76    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
 77    {
 78        QXT_10_UNUSED;
 79        QXT_RETURN(funcPtr)(QXT_PARAM(1));
 80        return true;
 81    }
 82private:
 83    qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
 84};
 85
 86template <typename RETURN, typename T1, typename T2>
 87class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
 88{
 89public:
 90    typedef RETURN(*FUNCTION)(T1, T2);
 91    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
 92    {
 93        QXT_10_UNUSED;
 94        QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2));
 95        return true;
 96    }
 97private:
 98    qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
 99};
100
101template <typename RETURN, typename T1, typename T2, typename T3>
102class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
103{
104public:
105    typedef RETURN(*FUNCTION)(T1, T2, T3);
106    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
107    {
108        QXT_10_UNUSED;
109        QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3));
110        return true;
111    }
112private:
113    qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
114};
115
116template <typename RETURN, typename T1, typename T2, typename T3, typename T4>
117class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, void, void, void, void, void, void> : public QxtGenericFunctionPointer
118{
119public:
120    typedef RETURN(*FUNCTION)(T1, T2, T3, T4);
121    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
122    {
123        QXT_10_UNUSED;
124        QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4));
125        return true;
126    }
127private:
128    qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
129};
130
131template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5>
132class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, void, void, void, void, void> : public QxtGenericFunctionPointer
133{
134public:
135    typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5);
136    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
137    {
138        QXT_10_UNUSED;
139        QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5));
140        return true;
141    }
142private:
143    qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
144};
145
146template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
147class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, void, void, void, void> : public QxtGenericFunctionPointer
148{
149public:
150    typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5, T6);
151    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
152    {
153        QXT_10_UNUSED;
154        QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6));
155        return true;
156    }
157private:
158    qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
159};
160
161template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
162class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, T7, void, void, void> : public QxtGenericFunctionPointer
163{
164public:
165    typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7);
166    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
167    {
168        QXT_10_UNUSED;
169        QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7));
170        return true;
171    }
172};
173
174template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
175class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, void, void> : public QxtGenericFunctionPointer
176{
177public:
178    typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8);
179    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
180    {
181        QXT_10_UNUSED;
182        QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8));
183        return true;
184    }
185private:
186    qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
187};
188
189template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
190class /*QXT_CORE_EXPORT*/ qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, void> : public QxtGenericFunctionPointer
191{
192public:
193    typedef RETURN(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8, T9);
194    bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
195    {
196        QXT_10_UNUSED;
197        QXT_RETURN(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8), QXT_PARAM(9));
198        return true;
199    }
200private:
201    qxt_cfunction_return(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
202};
203
204template < typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void,
205typename T6 = void, typename T7 = void, typename T8 = void, typename T9 = void, typename T10 = void >
206class /*QXT_CORE_EXPORT*/ qxt_cfunction : public QxtGenericFunctionPointer
207{
208public:
209    typedef void(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10);
210    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
211    {
212        QXT_10_UNUSED;
213        QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8), QXT_PARAM(9), QXT_PARAM(10));
214        return true;
215    }
216private:
217    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
218};
219
220template <>
221class /*QXT_CORE_EXPORT*/ qxt_cfunction<void, void, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
222{
223public:
224    typedef void(*FUNCTION)();
225    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
226    {
227        QXT_10_UNUSED;
228        QXT_INVOKE(funcPtr)();
229        return true;
230    }
231private:
232    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
233};
234
235template <typename T1>
236class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, void, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
237{
238public:
239    typedef void(*FUNCTION)(T1);
240    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
241    {
242        QXT_10_UNUSED;
243        QXT_INVOKE(funcPtr)(QXT_PARAM(1));
244        return true;
245    }
246private:
247    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
248};
249
250template <typename T1, typename T2>
251class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, void, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
252{
253public:
254    typedef void(*FUNCTION)(T1, T2);
255    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
256    {
257        QXT_10_UNUSED;
258        QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2));
259        return true;
260    }
261private:
262    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
263};
264
265template <typename T1, typename T2, typename T3>
266class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, void, void, void, void, void, void, void> : public QxtGenericFunctionPointer
267{
268public:
269    typedef void(*FUNCTION)(T1, T2, T3);
270    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
271    {
272        QXT_10_UNUSED;
273        QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3));
274        return true;
275    }
276private:
277    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
278};
279
280template <typename T1, typename T2, typename T3, typename T4>
281class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, void, void, void, void, void, void> : public QxtGenericFunctionPointer
282{
283public:
284    typedef void(*FUNCTION)(T1, T2, T3, T4);
285    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
286    {
287        QXT_10_UNUSED;
288        QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4));
289        return true;
290    }
291private:
292    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
293};
294
295template <typename T1, typename T2, typename T3, typename T4, typename T5>
296class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, T5, void, void, void, void, void> : public QxtGenericFunctionPointer
297{
298public:
299    typedef void(*FUNCTION)(T1, T2, T3, T4, T5);
300    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
301    {
302        QXT_10_UNUSED;
303        QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5));
304        return true;
305    }
306private:
307    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
308};
309
310template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
311class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, T5, T6, void, void, void, void> : public QxtGenericFunctionPointer
312{
313public:
314    typedef void(*FUNCTION)(T1, T2, T3, T4, T5, T6);
315    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
316    {
317        QXT_10_UNUSED;
318        QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6));
319        return true;
320    }
321private:
322    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
323};
324
325template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
326class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, T5, T6, T7, void, void, void> : public QxtGenericFunctionPointer
327{
328public:
329    typedef void(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7);
330    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
331    {
332        QXT_10_UNUSED;
333        QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7));
334        return true;
335    }
336private:
337    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
338};
339
340template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
341class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, T5, T6, T7, T8, void, void> : public QxtGenericFunctionPointer
342{
343public:
344    typedef void(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8);
345    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
346    {
347        QXT_10_UNUSED;
348        QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8));
349        return true;
350    }
351private:
352    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
353};
354
355template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
356class /*QXT_CORE_EXPORT*/ qxt_cfunction<T1, T2, T3, T4, T5, T6, T7, T8, T9, void> : public QxtGenericFunctionPointer
357{
358public:
359    typedef void(*FUNCTION)(T1, T2, T3, T4, T5, T6, T7, T8, T9);
360    bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
361    {
362        QXT_10_UNUSED;
363        QXT_INVOKE(funcPtr)(QXT_PARAM(1), QXT_PARAM(2), QXT_PARAM(3), QXT_PARAM(4), QXT_PARAM(5), QXT_PARAM(6), QXT_PARAM(7), QXT_PARAM(8), QXT_PARAM(9));
364        return true;
365    }
366private:
367    qxt_cfunction(voidFunc* ptr, const QByteArray& typeIdName) : QxtGenericFunctionPointer(ptr, typeIdName) {}
368};
369
370template < typename RETURN = void, typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void,
371typename T6 = void, typename T7 = void, typename T8 = void, typename T9 = void, typename T10 = void >
372class /*QXT_CORE_EXPORT*/ QxtBoundCFunction : public QxtBoundFunctionBase
373{
374public:
375    QxtGenericFunctionPointer funcPtr;
376
377    QxtBoundCFunction(QObject* parent, QxtGenericFunctionPointer funcPointer, QGenericArgument* params[10], QByteArray types[10]) : QxtBoundFunctionBase(parent, params, types), funcPtr(funcPointer)
378    {
379        // initializers only, thanks to template magic
380    }
381
382    virtual bool invokeImpl(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_IMPL_10ARGS(QGenericArgument))
383    {
384        if (type != Qt::AutoConnection && type != Qt::DirectConnection)
385        {
386            qWarning() << "QxtBoundCFunction::invoke: Cannot invoke non-Qt functions using a queued connection";
387            return false;
388        }
389        return reinterpret_cast<qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>*>(&funcPtr)->invoke(returnValue, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
390    }
391};
392
393template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
394class /*QXT_CORE_EXPORT*/ QxtBoundCFunction<void, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : public QxtBoundFunctionBase
395{
396public:
397    QxtGenericFunctionPointer funcPtr;
398
399    QxtBoundCFunction(QObject* parent, QxtGenericFunctionPointer funcPointer, QGenericArgument* params[10], QByteArray types[10]) : QxtBoundFunctionBase(parent, params, types), funcPtr(funcPointer)
400    {
401        // initializers only, thanks to template magic
402    }
403
404    virtual bool invokeImpl(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_IMPL_10ARGS(QGenericArgument))
405    {
406        Q_UNUSED(returnValue);
407        if (type != Qt::AutoConnection && type != Qt::DirectConnection)
408        {
409            qWarning() << "QxtBoundCFunction::invoke: Cannot invoke non-Qt functions using a queued connection";
410            return false;
411        }
412        return reinterpret_cast<qxt_cfunction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>*>(&funcPtr)->invoke(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
413    }
414};
415
416#undef QXT_RETURN
417#undef QXT_INVOKE
418#undef QXT_PARAM
419#endif
420
421namespace QxtMetaObject
422{
423    /*!
424     * \relates QxtMetaObject
425     * \sa QxtMetaObject::connect
426     * \sa qxtFuncPtr
427     * \sa QxtBoundFunction
428     * \sa QXT_BIND
429     *
430     * Creates a binding to the provided C/C++ function using the provided parameter list.
431     * Use the qxtFuncPtr function to wrap a bare function pointer for use in this function.
432     * Use the Q_ARG macro to specify constant parameters, or use the QXT_BIND macro to
433     * relay a parameter from a connected signal or passed via the QxtBoundFunction::invoke()
434     * method.
435     *
436     * The first template parameter must match the return type of the function, or
437     * void if the function does not return a value. The remaining template parameters must
438     * match the types of the function's parameters. If any type does not match, this
439     * function returns NULL.
440     *
441     * The returned QxtBoundFunction will not have a parent. Assigning a parent using
442     * QObject::setParent() is strongly recommended to avoid memory leaks.
443     */
444    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
445    QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QXT_IMPL_10ARGS(QGenericArgument))
446    {
447        // Make sure the template parameters make a function pointer equivalent to the one passed in
448        if (funcPointer.typeName != typeid(typename qxt_cfunction_return<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>::FUNCTION).name())
449        {
450            qWarning() << "QxtMetaObject::bind: parameter list mismatch, check template arguments";
451            return 0;
452        }
453
454        QGenericArgument* args[10] = { &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10 };
455        for (int i = 0; i < 10; i++)
456        {
457            if (args[i]->name() == 0) break;        // done
458            if (QByteArray(args[i]->name()) == "QxtBoundArgument")
459            {
460                Q_ASSERT_X((quintptr)(args[i]->data()) > 0 && (quintptr)(args[i]->data()) <= 10, "QXT_BIND", "invalid argument number");
461            }
462        }
463
464        QByteArray types[10];
465        types[0] = QxtMetaType<T1>::name();
466        types[1] = QxtMetaType<T2>::name();
467        types[2] = QxtMetaType<T3>::name();
468        types[3] = QxtMetaType<T4>::name();
469        types[4] = QxtMetaType<T5>::name();
470        types[5] = QxtMetaType<T6>::name();
471        types[6] = QxtMetaType<T7>::name();
472        types[7] = QxtMetaType<T8>::name();
473        types[8] = QxtMetaType<T9>::name();
474        types[9] = QxtMetaType<T10>::name();
475
476        return new QxtBoundCFunction<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(0, funcPointer, args, types);
477    }
478
479    /*!
480     * \relates QxtMetaObject
481     * \sa QxtMetaObject::connect
482     * \sa qxtFuncPtr
483     * \sa QxtBoundFunction
484     *
485     * Creates a binding to the provided C/C++ function using the provided parameter list.
486     * Use the qxtFuncPtr function to wrap a bare function pointer for use in this function.
487     * The type of each argument is deduced from the type of the QVariant. This function
488     * cannot bind positional arguments; see the overload using QGenericArgument.
489     *
490     * The first template parameter must match the return type of the function, or
491     * void if the function does not return a value. The remaining template parameters must
492     * match the types of the function's parameters. If any type does not match, this
493     * function returns NULL.
494     *
495     * The returned QxtBoundFunction will not have a parent. Assigning a parent using
496     * QObject::setParent() is strongly recommended to avoid memory leaks.
497     */
498    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
499    QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QXT_IMPL_10ARGS(QVariant))
500    {
501        QVariant* args[10] = { &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10 };
502        return QxtMetaObject::bind<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(funcPointer, QXT_VAR_ARG(1), QXT_VAR_ARG(2), QXT_VAR_ARG(3), QXT_VAR_ARG(4),
503                QXT_VAR_ARG(5), QXT_VAR_ARG(6), QXT_VAR_ARG(7), QXT_VAR_ARG(8), QXT_VAR_ARG(9), QXT_VAR_ARG(10));
504    }
505
506// The following overloads exist because C++ doesn't support default parameters in function templates
507#ifndef QXT_DOXYGEN_RUN
508    template <typename RETURN>
509    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer)
510    {
511        return bind<RETURN, void, void, void, void, void, void, void, void, void, void>(funcPointer,
512                QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
513    }
514
515    template <typename RETURN, typename T1>
516    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1)
517    {
518        return bind<RETURN, T1, void, void, void, void, void, void, void, void, void>(funcPointer,
519                p1, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
520    }
521
522    template <typename RETURN, typename T1, typename T2>
523    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2)
524    {
525        return bind<RETURN, T1, T2, void, void, void, void, void, void, void, void>(funcPointer,
526                p1, p2, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
527    }
528
529    template <typename RETURN, typename T1, typename T2, typename T3>
530    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3)
531    {
532        return bind<RETURN, T1, T2, T3, void, void, void, void, void, void, void>(funcPointer,
533                p1, p2, p3, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
534    }
535
536    template <typename RETURN, typename T1, typename T2, typename T3, typename T4>
537    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4)
538    {
539        return bind<RETURN, T1, T2, T3, T4, void, void, void, void, void, void>(funcPointer,
540                p1, p2, p3, p4, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
541    }
542
543    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5>
544    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4, QGenericArgument p5)
545    {
546        return bind<RETURN, T1, T2, T3, T4, T5, void, void, void, void, void>(funcPointer,
547                p1, p2, p3, p4, p5, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
548    }
549
550    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
551    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4, QGenericArgument p5, QGenericArgument p6)
552    {
553        return bind<RETURN, T1, T2, T3, T4, T5, T6, void, void, void, void>(funcPointer,
554                p1, p2, p3, p4, p5, p6, QGenericArgument(), QGenericArgument(), QGenericArgument(), QGenericArgument());
555    }
556
557    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
558    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4, QGenericArgument p5, QGenericArgument p6, QGenericArgument p7)
559    {
560        return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, void, void, void>(funcPointer,
561                p1, p2, p3, p4, p5, p6, p7, QGenericArgument(), QGenericArgument(), QGenericArgument());
562    }
563
564    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
565    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4, QGenericArgument p5,
566                                  QGenericArgument p6, QGenericArgument p7, QGenericArgument p8)
567    {
568        return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, void, void>(funcPointer, p1, p2, p3, p4, p5, p6, p7, p8, QGenericArgument(), QGenericArgument());
569    }
570
571    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
572    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QGenericArgument p1, QGenericArgument p2, QGenericArgument p3, QGenericArgument p4, QGenericArgument p5,
573                                  QGenericArgument p6, QGenericArgument p7, QGenericArgument p8, QGenericArgument p9)
574    {
575        return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, void>(funcPointer, p1, p2, p3, p4, p5, p6, p7, p8, p9, QGenericArgument());
576    }
577
578    template <typename RETURN, typename T1>
579    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1)
580    {
581        return bind<RETURN, T1, void, void, void, void, void, void, void, void, void>(funcPointer, p1, QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant());
582    }
583
584    template <typename RETURN, typename T1, typename T2>
585    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2)
586    {
587        return bind<RETURN, T1, T2, void, void, void, void, void, void, void, void>(funcPointer, p1, p2, QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant());
588    }
589
590    template <typename RETURN, typename T1, typename T2, typename T3>
591    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3)
592    {
593        return bind<RETURN, T1, T2, T3, void, void, void, void, void, void, void>(funcPointer, p1, p2, p3, QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant());
594    }
595
596    template <typename RETURN, typename T1, typename T2, typename T3, typename T4>
597    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4)
598    {
599        return bind<RETURN, T1, T2, T3, T4, void, void, void, void, void, void>(funcPointer, p1, p2, p3, p4, QVariant(), QVariant(), QVariant(), QVariant(), QVariant(), QVariant());
600    }
601
602    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5>
603    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4, QVariant p5)
604    {
605        return bind<RETURN, T1, T2, T3, T4, T5, void, void, void, void, void>(funcPointer, p1, p2, p3, p4, p5, QVariant(), QVariant(), QVariant(), QVariant(), QVariant());
606    }
607
608    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
609    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4, QVariant p5, QVariant p6)
610    {
611        return bind<RETURN, T1, T2, T3, T4, T5, T6, void, void, void, void>(funcPointer, p1, p2, p3, p4, p5, p6, QVariant(), QVariant(), QVariant(), QVariant());
612    }
613
614    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
615    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4, QVariant p5, QVariant p6, QVariant p7)
616    {
617        return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, void, void, void>(funcPointer, p1, p2, p3, p4, p5, p6, p7, QVariant(), QVariant(), QVariant());
618    }
619
620    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
621    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4, QVariant p5, QVariant p6, QVariant p7, QVariant p8)
622    {
623        return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, void, void>(funcPointer, p1, p2, p3, p4, p5, p6, p7, p8, QVariant(), QVariant());
624    }
625
626    template <typename RETURN, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
627    inline QxtBoundFunction* bind(QxtGenericFunctionPointer funcPointer, QVariant p1, QVariant p2, QVariant p3, QVariant p4, QVariant p5, QVariant p6, QVariant p7, QVariant p8, QVariant p9)
628    {
629        return bind<RETURN, T1, T2, T3, T4, T5, T6, T7, T8, T9, void>(funcPointer, p1, p2, p3, p4, p5, p6, p7, p8, p9, QVariant());
630    }
631#endif
632}
633#endif