sclang: use boost::regex for String: -matchRegexp and -findRegexp
[supercollider.git] / QtCollider / QcObjectFactory.h
blob0c9b8e0bd400337311c2a95e84fecab193320a9d
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"
26 #include "Common.h"
28 #include <PyrObject.h>
30 #include <QMetaObject>
31 #include <QObject>
32 #include <QWidget>
33 #include <QHash>
35 class QcAbstractFactory;
37 typedef QHash<QString,QcAbstractFactory*> QcFactoryHash;
39 namespace QtCollider {
40 QcFactoryHash & factories ();
43 class QcAbstractFactory
45 public:
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
57 public:
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 );
72 return proxy;
75 protected:
76 virtual void initialize( QObjectProxy *, QOBJECT *, QList<QVariant> & arguments ) {};
81 #endif //QC_OBJECT_FACTORY_H