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 QXTBOUNDFUNCTION_H
26 #define QXTBOUNDFUNCTION_H
29 #include <QMetaObject>
30 #include <QGenericArgument>
31 #include <qxtmetaobject.h>
35 class QxtBoundFunction : public QObject
40 inline QxtNullable<T> invoke(QXT_PROTO_10ARGS(QVariant))
42 if (QThread::currentThread() == parent()->thread())
43 return invoke<T>(Qt::DirectConnection, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
44 #if QT_VERSION >= 0x040300
45 return invoke<T>(Qt::BlockingQueuedConnection, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
47 qWarning() << "QxtBoundFunction::invoke: Cannot return a value using a queued connection";
53 QxtNullable<T> invoke(Qt::ConnectionType type, QXT_PROTO_10ARGS(QVariant))
55 if (type == Qt::QueuedConnection)
57 qWarning() << "QxtBoundFunction::invoke: Cannot return a value using a queued connection";
61 // I know this is a totally ugly function call
62 if (invoke(type, QGenericReturnArgument(qVariantFromValue<T>(*reinterpret_cast<T*>(0)).typeName(), reinterpret_cast<void*>(&retval)),
63 p1, p2, p3, p4, p5, p6, p7, p8, p9, p10))
73 inline bool invoke(QXT_PROTO_10ARGS(QVariant))
75 return invoke(Qt::AutoConnection, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
77 bool invoke(Qt::ConnectionType, QXT_PROTO_10ARGS(QVariant));
79 inline bool invoke(QXT_PROTO_10ARGS(QGenericArgument))
81 return invoke(Qt::AutoConnection, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
83 inline bool invoke(Qt::ConnectionType type, QXT_PROTO_10ARGS(QGenericArgument)) {
84 return invoke(type, QGenericReturnArgument(), p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
87 inline bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QVariant))
89 return invoke(Qt::AutoConnection, returnValue, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
91 bool invoke(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QVariant));
93 inline bool invoke(QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument))
95 return invoke(Qt::AutoConnection, returnValue, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
97 bool invoke(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument));
100 QxtBoundFunction(QObject* parent = 0);
101 virtual bool invokeImpl(Qt::ConnectionType type, QGenericReturnArgument returnValue, QXT_PROTO_10ARGS(QGenericArgument)) = 0;