1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef EXTENSIONSYSTEM_INVOKER_H
34 #define EXTENSIONSYSTEM_INVOKER_H
36 #include "extensionsystem_global.h"
38 #include <QtCore/QMetaMethod>
39 #include <QtCore/QMetaObject>
40 #include <QtCore/QMetaType>
41 #include <QtCore/QVarLengthArray>
43 namespace ExtensionSystem {
45 class EXTENSIONSYSTEM_EXPORT InvokerBase
51 bool wasSuccessful() const;
53 template <class T> void addArgument(const T &t)
55 arg[lastArg++] = QGenericArgument(typeName<T>(), &t);
58 template <class T> void setReturnValue(T &t)
61 ret = QGenericReturnArgument(typeName<T>(), &t);
64 void invoke(QObject *target, const char *slot);
67 InvokerBase(const InvokerBase &); // Unimplemented.
68 template <class T> const char *typeName()
70 return QMetaType::typeName(qMetaTypeId<T>());
73 QGenericArgument arg[10];
74 QGenericReturnArgument ret;
75 QVarLengthArray<char, 512> sig;
82 template <class Result>
83 class Invoker : public InvokerBase
86 Invoker(QObject *target, const char *slot)
88 InvokerBase::invoke(target, slot);
92 Invoker(QObject *target, const char *slot, const T0 &t0)
94 setReturnValue(result);
96 InvokerBase::invoke(target, slot);
99 template <class T0, class T1>
100 Invoker(QObject *target, const char *slot, const T0 &t0, const T1 &t1)
102 setReturnValue(result);
105 InvokerBase::invoke(target, slot);
108 template <class T0, class T1, class T2>
109 Invoker(QObject *target, const char *slot, const T0 &t0,
110 const T1 &t1, const T2 &t2)
112 setReturnValue(result);
116 InvokerBase::invoke(target, slot);
119 operator Result() const { return result; }
125 template<> class Invoker<void> : public InvokerBase
128 Invoker(QObject *target, const char *slot)
130 InvokerBase::invoke(target, slot);
134 Invoker(QObject *target, const char *slot, const T0 &t0)
137 InvokerBase::invoke(target, slot);
140 template <class T0, class T1>
141 Invoker(QObject *target, const char *slot, const T0 &t0, const T1 &t1)
145 InvokerBase::invoke(target, slot);
148 template <class T0, class T1, class T2>
149 Invoker(QObject *target, const char *slot, const T0 &t0,
150 const T1 &t1, const T2 &t2)
155 InvokerBase::invoke(target, slot);
159 template <class Result>
160 Result invokeHelper(InvokerBase &in, QObject *target, const char *slot)
163 in.setReturnValue(result);
164 in.invoke(target, slot);
169 inline void invokeHelper<void>(InvokerBase &in, QObject *target, const char *slot)
171 in.invoke(target, slot);
174 template<class Result>
175 Result invoke(QObject *target, const char *slot)
178 return invokeHelper<Result>(in, target, slot);
181 template<class Result, class T0>
182 Result invoke(QObject *target, const char *slot, const T0 &t0)
186 return invokeHelper<Result>(in, target, slot);
189 template<class Result, class T0, class T1>
190 Result invoke(QObject *target, const char *slot, const T0 &t0, const T1 &t1)
195 return invokeHelper<Result>(in, target, slot);
198 template<class Result, class T0, class T1, class T2>
199 Result invoke(QObject *target, const char *slot,
200 const T0 &t0, const T1 &t1, const T2 &t2)
206 return invokeHelper<Result>(in, target, slot);
209 } // namespace ExtensionSystem
211 #endif // EXTENSIONSYSTEM_INVOKER_H