1 /************************************************************************
3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
22 #ifndef QC_OBJECT_FACTORY_H
23 #define QC_OBJECT_FACTORY_H
25 #include "QObjectProxy.h"
28 #include <PyrObject.h>
30 #include <QMetaObject>
35 class QcAbstractFactory
;
37 typedef QHash
<QString
,QcAbstractFactory
*> QcFactoryHash
;
39 namespace QtCollider
{
40 QcFactoryHash
& factories ();
43 class QcAbstractFactory
46 QcAbstractFactory( const char *className
) {
47 qcDebugMsg( 2, QString("Declaring class '%1'").arg(className
) );
48 QtCollider::factories().insert( className
, this );
50 virtual const QMetaObject
*metaObject() = 0;
51 virtual QObjectProxy
*newInstance( PyrObject
*, QList
<QVariant
> & arguments
) = 0;
55 template <class QOBJECT
> class QcObjectFactory
: public QcAbstractFactory
58 QcObjectFactory() : QcAbstractFactory( QOBJECT::staticMetaObject
.className() ) {}
60 const QMetaObject
*metaObject() {
61 return &QOBJECT::staticMetaObject
;
64 virtual QObjectProxy
*newInstance( PyrObject
*scObject
, QList
<QVariant
> & arguments
) {
65 QOBJECT
*qobject
= new QOBJECT();
66 QObject
*qo
= qobject
; // template parameter type-safety
68 QObjectProxy
*proxy
= new QObjectProxy ( qobject
, scObject
);
70 initialize( proxy
, qobject
, arguments
);
76 virtual void initialize( QObjectProxy
*, QOBJECT
*, QList
<QVariant
> & arguments
) {};
81 #endif //QC_OBJECT_FACTORY_H