WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZblFactory.cpp
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2014 Bob Dinitto
4  *
5  * Filename: ZblFactory.cpp
6  * Created on: 12/7/2014
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #include "ZblFactory.h"
26 #include "ZblSprockOb.h"
27 #include "ZblCog.h"
28 #include "ZblSprocket.h"
29 #include "ZblException.h"
30 
31 namespace Zbl
32 {
33 
35  int importVersionMajor,
36  int importVersionMinor,
37  QObject *parent) :
38  QObject(parent),
39  m_importVersionMajor(importVersionMajor),
40  m_importVersionMinor(importVersionMinor)
41 {
42 }
43 
44 
45 QObject* ZblFactory::createObject(const char * qmlName)
46 {
47  ZblSprockOb* sprocOb = m_objectFunctions.value(qmlName, NULL);
48 
49  if(!sprocOb)
50  throw ZblException(QString("ZblFactory::createObject FAILED: "
51  "nonexistent type: %1 -- did you import the Sprocket?").arg(qmlName));
52 
53  QObject* newOb = (sprocOb->newObjectFunction())(NULL);
54 
55  if(!newOb)
56  throw ZblException(QString("ZblFactory::createObject FAILED: "
57  "plugin's object constructor can't create type: %1").arg(qmlName));
58 
59  return newOb;
60 }
61 
62 } // Zbl
sprocketObjectMap m_objectFunctions
Maps QML type names to appropriate version-specific Sprocket object constructors. ...
Definition: ZblFactory.h:117
QObject * createObject(const char *qmlName)
Locates the Sprocket object's constructor for the specified QML type and calls it, returning the resulting object.
Definition: ZblFactory.cpp:45
Definition: ZAndGate.cpp:6
ZblFactory(int importVersionMajor, int importVersionMinor, QObject *parent=0)
Object constructor.
Definition: ZblFactory.cpp:34
Zuble's Qt Exception Object.
Definition: ZblException.h:45
sprocketObjectConstructor newObjectFunction() const
Definition: ZblSprockOb.h:79
This class acts as an object construction wrapper for objects defined in Zuble Sprocket plugins...
Definition: ZblSprockOb.h:42