| 12 |
|
#define SLOW_SCRIPT_TIME 0.1 // if a user script takes more than 0.1 seconds to execute give a warning. |
| 13 |
|
#define CUSTOM_FILES_PER_THREAD 2 |
| 14 |
|
|
| 15 |
+ |
// Uses a singleton implementation (based on here: http://www.yolinux.com/TUTORIALS/C++Singleton.html) |
| 16 |
+ |
// which allows each thread to keep one script engine without always create/destruct them |
| 17 |
|
class XmlCustomCode |
| 18 |
|
{ |
| 19 |
|
public: |
| 20 |
< |
XmlCustomCode(); |
| 20 |
> |
static XmlCustomCode* getInstance(); |
| 21 |
|
void executeCustomCode(const QString &jsString, const QVector<QString> &filesToProcess, const bool backupsEnabled, const bool verboseEnabled); |
| 22 |
|
private: |
| 23 |
+ |
static XmlCustomCode* uniqueInstance; |
| 24 |
|
const int numThreads; |
| 25 |
< |
static QVector<QScriptEngine*> scriptEngines; // allows each thread to keep one script engine without always create/destruct them |
| 26 |
< |
static QVector<QScriptValue*> jsFunctions; |
| 27 |
< |
static QVector<QScriptValue*> getXmlDataFunctions; |
| 28 |
< |
static QVector<QScriptValue*> setXmlDataFunctions; |
| 25 |
> |
QVector<QScriptEngine*> scriptEngines; |
| 26 |
> |
QVector<QScriptValue*> jsFunctions; |
| 27 |
> |
QVector<QScriptValue*> getXmlDataFunctions; |
| 28 |
> |
QVector<QScriptValue*> setXmlDataFunctions; |
| 29 |
> |
|
| 30 |
> |
XmlCustomCode(); // constructor is private (use getInstance) |
| 31 |
> |
XmlCustomCode(XmlCustomCode const&); // copy constructor is private |
| 32 |
> |
XmlCustomCode& operator=(XmlCustomCode const&); // assignment operator is private |
| 33 |
|
|
| 34 |
|
void displayJsException(QScriptEngine &engine, QScriptValue &engineResult); |
| 35 |
|
|