Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: quickinterpreter.h 1.1.4 edited 2006-02-23T15:39:57$ 00003 ** 00004 ** Copyright (C) 2001-2006 Trolltech AS. All rights reserved. 00005 ** 00006 ** This file is part of the Qt Script for Applications framework (QSA). 00007 ** 00008 ** This file may be distributed and/or modified under the terms of the 00009 ** GNU General Public License version 2 as published by the Free Software 00010 ** Foundation and appearing in the file LICENSE.GPL included in the 00011 ** packaging of this file. 00012 ** 00013 ** Licensees holding a valid Qt Script for Applications license may use 00014 ** this file in accordance with the Qt Script for Applications License 00015 ** Agreement provided with the Software. 00016 ** 00017 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00018 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00019 ** 00020 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00021 ** information about QSA Commercial License Agreements. 00022 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00023 ** 00024 ** Contact info@trolltech.com if any conditions of this licensing are 00025 ** not clear to you. 00026 ** 00027 *****************************************************************************/ 00028 00029 #ifndef QUICKINTERPRETER_H 00030 #define QUICKINTERPRETER_H 00031 00032 #ifndef QT_H 00033 #include <qobject.h> 00034 #include <qobjectlist.h> 00035 #include <qstringlist.h> 00036 #include <qvaluelist.h> 00037 #include <qptrvector.h> 00038 #include <qmap.h> 00039 #include "dlldefs.h" 00040 #include <qptrlist.h> 00041 #endif // QT_H 00042 00043 #include "quickdispatchobject.h" 00044 #include "qsengine.h" 00045 #include <qstypes.h> 00046 #include <qsargument.h> 00047 00048 #ifdef QSDEBUGGER 00049 class QuickDebugger; 00050 #endif 00051 class QuickDispatchObjectFactory; 00052 class QSWrapperClass; 00053 class QSPointerClass; 00054 class QSVariantClass; 00055 class QSMapClass; 00056 class QSPointClass; 00057 class QSSizeClass; 00058 class QSRectClass; 00059 class QSColorClass; 00060 class QSFontClass; 00061 class QSByteArrayClass; 00062 class QSPixmapClass; 00063 class QSApplicationClass; 00064 class QSWrapperShared; 00065 class QSPaletteClass; 00066 class QSColorGroupClass; 00067 00068 typedef QPtrList<QSWrapperShared> QSWrapperSharedList; 00069 00070 #if defined(Q_TEMPLATEDLL) 00071 // MOC_SKIP_BEGIN 00072 template class QUICKCORE_EXPORT QMap<int, QObject *>; 00073 template class QUICKCORE_EXPORT QMap<QString, QObject *>; 00074 template class QUICKCORE_EXPORT QMap<QString, bool>; 00075 template class QPtrList<QuickDispatchObjectFactory>; 00076 template class QUICKCORE_EXPORT QMap<QString, QPtrList<QuickDispatchObjectFactory> >; 00077 template class QUICKCORE_EXPORT QMap<QObject *, QSWrapperClass *>; 00078 //template class QUICKCORE_EXPORT QStringList; 00079 // MOC_SKIP_END 00080 #endif 00081 00082 #if defined( Q_TEMPLATEDLL ) && QT_VERSION<0x030200 00083 // MOC_SKIP_BEGIN 00084 // template class QUICKCORE_EXPORT QMap<QString, QString>; 00085 template class QUICKCORE_EXPORT QMap<int, QString>; 00086 // MOC_SKIP_END 00087 #endif 00088 00089 class QUICKCORE_EXPORT QuickInterpreter : public QSEngine 00090 { 00091 Q_OBJECT 00092 public: 00093 QuickInterpreter(bool deb = FALSE); 00094 virtual ~QuickInterpreter(); 00095 00096 void addTopLevelObject(QObject *o); 00097 void setTopLevelObjects(QObjectList *l); 00098 bool hasTopLevelParent(QObject *o); 00099 QStringList children() const { 00100 return kids; 00101 } 00102 QObjectList *topLevelObjects() const { 00103 return toplevel; 00104 } 00105 00106 bool checkSyntax(const QString &code); 00107 00108 QSArgument execute(QObject *_this, const QString &code, 00109 const QString &scriptName); 00110 QSArgument call(QObject *ctx, const QString &func, const QSList &args); 00111 QSArgument call(QSObject ctx, const QString &func, const QSList &args); 00112 QSArgument call(QObject *ctx, const QString &func, const QSArgumentList &args); 00113 00114 void clear(); 00115 void stop(); 00116 00117 bool hadError() const; 00118 00119 void warn(const QString &msg, int l); 00120 00121 #ifdef QSDEBUGGER 00122 QuickDebugger *debuggerEngine() const { 00123 return debugger; 00124 } 00125 #endif 00126 00127 struct Property { 00128 Property() {} 00129 Property(const QString &n, const QString &t) : name(n), type(t) {} 00130 QString name; 00131 QString type; 00132 bool operator==(const Property &p) const { 00133 return name == p.name && type == p.type; 00134 } 00135 }; 00136 00137 static void enableTimers(bool b); 00138 static bool timersEnabled(); 00139 00140 void reinit(); 00141 00142 void clearSourceIdMap(); 00143 void addSourceId(int id, QObject *o); 00144 QObject *objectOfSourceId(int id) const; 00145 int sourceIdOfObject(QObject *o) const; 00146 00147 QString nameOfSourceId(int id) const; 00148 int sourceIdOfName(const QString &name) const; 00149 00150 bool queryDispatchObjects(QObject *obj, QPtrVector<QObject> &result); 00151 bool queryDispatchObjects(const QCString &name, void *ptr, 00152 QPtrVector<QObject> &result); 00153 bool construct(const QString &className, const QValueList<QVariant> &args, 00154 QPtrVector<QObject> &result); 00155 00156 // use with caution 00157 static QuickInterpreter *fromEnv(QSEnv *e); 00158 00159 static void cleanType(QString &type); 00160 static void cleanTypeRev(QString &type); 00161 00162 void emitToggleDebugger(bool enable) { 00163 emit toggleDebugger(enable); 00164 } 00165 00166 QStringList staticGlobalObjects() const { 00167 return staticGlobals; 00168 } 00169 00170 QuickDispatchObjectFactory *dispatchObjectFactory() const { 00171 return factory; 00172 } 00173 00174 QSWrapperClass *wrapperClass() const { 00175 return wrpClass; 00176 } 00177 QSPointerClass *pointerClass() const { 00178 return ptrClass; 00179 } 00180 QSVariantClass *variantClass() const { 00181 return varClass; 00182 } 00183 QSMapClass *mapClass() const { 00184 return mpClass; 00185 } 00186 QSPointClass *pointClass() const { 00187 return pntClass; 00188 } 00189 QSSizeClass *sizeClass() const { 00190 return sizClass; 00191 } 00192 QSRectClass *rectClass() const { 00193 return rctClass; 00194 } 00195 QSColorClass *colorClass() const { 00196 return colClass; 00197 } 00198 QSFontClass *fontClass() const { 00199 return fntClass; 00200 } 00201 QSByteArrayClass *byteArrayClass() const { 00202 return baClass; 00203 } 00204 QSPixmapClass *pixmapClass() const { 00205 return pixClass; 00206 } 00207 QSApplicationClass *applicationClass() const { 00208 return appClass; 00209 } 00210 QSColorGroupClass *colorGroupClass() const { 00211 return colGrpClass; 00212 } 00213 QSPaletteClass *paletteClass() const { 00214 return palClass; 00215 } 00216 QSObject wrap(QObject *o); 00217 00218 QSArgument convertToArgument(const QSObject &object); 00219 00220 bool hasFunction(const QString &function) const; 00221 bool hasVariable(const QString &variable) const; 00222 bool hasClass(const QString &className) const; 00223 00224 QStringList functionsOf(QSObject &obj, bool includeSignature, 00225 bool includeNative = FALSE, 00226 bool includeMemberFunctions = FALSE) const; 00227 QStringList classes() const; 00228 QStringList classesOf(QSObject &obj) const; 00229 QStringList variablesOf(QSObject &obj, bool includeStatic = FALSE, 00230 bool includeCustom = FALSE, 00231 bool includeMemberVariables = FALSE) const; 00232 QSObject object(const QString &name) const; 00233 const QSClass *classOf(const QSObject &obj) const; 00234 00235 int uniqueId() const { 00236 return id; 00237 } 00238 int userDataId() const { 00239 return usrDataId; 00240 } 00241 00242 void setVariable(QObject *context, const QString &name, const QSArgument &value); 00243 QSArgument variable(QObject *context, const QString &name); 00244 00245 signals: 00246 void runtimeError(); 00247 void parseError(); 00248 void warning(const QString &msg, int line); 00249 void runProject(); 00250 void stopProject(); 00251 void queryGlobalFunctions(QStringList &funcs); 00252 void toggleDebugger(bool); 00253 00254 private slots: 00255 void topLevelDestroyed(QObject *o); 00256 00257 private: 00258 friend class QuickScriptObject; 00259 friend class QuickScript; 00260 #if defined(Q_DISABLE_COPY) 00261 QuickInterpreter(const QuickInterpreter &); 00262 QuickInterpreter &operator=(const QuickInterpreter &); 00263 #endif 00264 00265 void init(); 00266 void invalidateWrappers(); 00267 00268 uint shuttingDown: 1; 00269 #ifdef QSDEBUGGER 00270 QuickDebugger *debugger; 00271 #endif 00272 QObjectList *toplevel; 00273 QStringList kids; 00274 QMap<int, QObject *> sourceIdMap; 00275 QMap<int, QString> sourceIdNames; 00276 QStringList staticGlobals; 00277 00278 QSWrapperClass *wrpClass; 00279 QSPointerClass *ptrClass; 00280 QSVariantClass *varClass; 00281 QSMapClass *mpClass; 00282 QSPointClass *pntClass; 00283 QSSizeClass *sizClass; 00284 QSRectClass *rctClass; 00285 QSColorClass *colClass; 00286 QSColorGroupClass *colGrpClass; 00287 QSPaletteClass *palClass; 00288 QSFontClass *fntClass; 00289 QSByteArrayClass *baClass; 00290 QSPixmapClass *pixClass; 00291 QSApplicationClass *appClass; 00292 QSWrapperSharedList *wrapperShared; 00293 QuickDispatchObjectFactory *factory; 00294 00295 int id; 00296 int usrDataId; 00297 00298 }; 00299 00300 #endif