We now have a current svn snapshot of libqxt in our contrib dir, and
[quassel.git] / src / contrib / libqxt-2007-10-24 / src / core / qxtmetaobject.h
1 /****************************************************************************
2 **
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
4 **
5 ** This file is part of the QxtCore module of the Qt eXTension library
6 **
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
9 ** IBM.
10 **
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.
15 **
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.
20 **
21 ** <http://libqxt.sourceforge.net>  <foundation@libqxt.org>
22 **
23 ****************************************************************************/
24 #ifndef QXTMETAOBJECT_H
25 #define QXTMETAOBJECT_H
26
27 #include <QMetaObject>
28 #include <QVariant>
29 #include <QGenericArgument>
30 #include <typeinfo>
31 #include "qxtnullable.h"
32 class QByteArray;
33 class QxtBoundArgument;
34 class QxtBoundFunction;
35
36 #define QXT_PROTO_10ARGS(T) T p1 = T(), T p2 = T(), T p3 = T(), T p4 = T(), T p5 = T(), T p6 = T(), T p7 = T(), T p8 = T(), T p9 = T(), T p10 = T()
37 #define QXT_PROTO_9ARGS(T) T p2 = T(), T p3 = T(), T p4 = T(), T p5 = T(), T p6 = T(), T p7 = T(), T p8 = T(), T p9 = T(), T p10 = T()
38 #define QXT_IMPL_10ARGS(T) T p1, T p2, T p3, T p4, T p5, T p6, T p7, T p8, T p9, T p10
39
40 class QxtGenericFunctionPointer {
41 template<typename FUNCTION>
42 friend QxtGenericFunctionPointer qxtFuncPtr(FUNCTION funcPtr);
43 public:
44     QxtGenericFunctionPointer(const QxtGenericFunctionPointer& other) {
45         funcPtr = other.funcPtr;
46         typeName = other.typeName;
47     }
48
49     typedef void(voidFunc)();
50     voidFunc* funcPtr;
51     QByteArray typeName;
52
53 private:
54     QxtGenericFunctionPointer(voidFunc* ptr, const QByteArray& typeIdName) {
55         funcPtr = ptr;
56         typeName = typeIdName;
57     }
58 };
59
60 template<typename FUNCTION>
61 QxtGenericFunctionPointer qxtFuncPtr(FUNCTION funcPtr) {
62     return QxtGenericFunctionPointer(reinterpret_cast<QxtGenericFunctionPointer::voidFunc*>(funcPtr), typeid(funcPtr).name());
63 }
64
65 namespace QxtMetaObject
66 {
67 QXT_CORE_EXPORT QByteArray methodName(const char* method);
68 QXT_CORE_EXPORT QByteArray methodSignature(const char* method);
69
70 QXT_CORE_EXPORT bool isSignalOrSlot (const char* method);
71
72 QXT_CORE_EXPORT QxtBoundFunction* bind(QObject* recv, const char* invokable, QXT_PROTO_10ARGS(QGenericArgument));
73 QXT_CORE_EXPORT QxtBoundFunction* bind(QObject* recv, const char* invokable, QVariant p1, QXT_PROTO_9ARGS(QVariant));
74 QXT_CORE_EXPORT bool connect(QObject* sender, const char* signal, QxtBoundFunction* slot,
75                              Qt::ConnectionType type = Qt::AutoConnection);
76 }
77
78 /**
79  * \relates QxtMetaObject
80  * \sa QxtMetaObject::bind
81  * Refers to the n'th parameter of QxtBoundFunction::invoke() or a signal connected to
82  * a QxtBoundFunction.
83  */
84 #define QXT_BIND(n) QGenericArgument("QxtBoundArgument", reinterpret_cast<void*>(n))
85
86 #endif // QXTMETAOBJECT_H