File indexing completed on 2024-04-21 15:02:58

0001 /***************************************************************************
0002  * metafunction.h
0003  * This file is part of the KDE project
0004  * copyright (C)2005-2006 Ian Reinhart Geiser <geiseri@kde.org>
0005  * copyright (C)2005-2006 Matt Broadstone     <mbroadst@gmail.com>
0006  * copyright (C)2005-2006 Richard J. Moore    <rich@kde.org>
0007  * copyright (C)2005-2006 Erik L. Bunce       <kde@bunce.us>
0008  * copyright (C)2005-2007 by Sebastian Sauer  <mail@dipe.org>
0009  *
0010  * This program is free software; you can redistribute it and/or
0011  * modify it under the terms of the GNU Library General Public
0012  * License as published by the Free Software Foundation; either
0013  * version 2 of the License, or (at your option) any later version.
0014  * This program is distributed in the hope that it will be useful,
0015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017  * Library General Public License for more details.
0018  * You should have received a copy of the GNU Library General Public License
0019  * along with this program; see the file COPYING.  If not, write to
0020  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0021  * Boston, MA 02110-1301, USA.
0022  ***************************************************************************/
0023 
0024 #ifndef KROSS_METAFUNCTION_H
0025 #define KROSS_METAFUNCTION_H
0026 
0027 #include <kross/core/krosscore_export.h>
0028 #include <QObject>
0029 #include <QPointer>
0030 
0031 namespace Kross
0032 {
0033 
0034 /**
0035  * The MetaFunction class implements a QObject to provide an adaptor
0036  * between Qt signals+slots and scripting functions.
0037  *
0038  * For example the Kross::PythonFunction and the Kross::RubyFunction
0039  * classes located in kdebindings inherit this class to connect a
0040  * QObject signal together with a callable python or ruby method.
0041  */
0042 class KROSSCORE_EXPORT MetaFunction : public QObject
0043 {
0044 public:
0045 
0046     /**
0047     * Constructor.
0048     *
0049     * \param sender The QObject instance that sends the signal.
0050     * \param signal The signature of the signal the QObject emits.
0051     */
0052     MetaFunction(QObject *sender, const QByteArray &signal);
0053 
0054     /**
0055     * Destructor.
0056     */
0057     ~MetaFunction() override;
0058 
0059     /**
0060     * The static \a QMetaObject instance that provides the
0061     * QMeta-information for this QObject class.
0062     */
0063     QMetaObject staticMetaObject;
0064 
0065     /**
0066     * \return the dynamic build \a QMetaObject instance
0067     * for this QObject instance.
0068     */
0069     const QMetaObject *metaObject() const override;
0070 
0071     /**
0072     * Try to cast this QObject instance into the class with
0073     * name \p _clname and return the casted pointer or NULL
0074     * if casting failed.
0075     */
0076     void *qt_metacast(const char *_clname) override;
0077 
0078     /**
0079     * This method got called if a method this QObject instance
0080     * defines should be invoked.
0081     */
0082     int qt_metacall(QMetaObject::Call _c, int _id, void **_a) override = 0;
0083 
0084 protected:
0085     /// The sender QObject.
0086     QPointer<QObject> m_sender;
0087     /// The signature.
0088     QByteArray m_signature;
0089 
0090 private:
0091     class Private;
0092     Private *const d;
0093 
0094     static void writeString(
0095         char *out, int i, const QByteArray &str,
0096         const int offsetOfStringdataMember, int &stringdataOffset);
0097     static QList<QByteArray> parameterTypeNamesFromSignature(const char *signature);
0098 };
0099 
0100 }
0101 
0102 #endif