code format & class prefix
This commit is contained in:
34
doric-Qt/doric/utils/DoricConstant.cpp
Normal file
34
doric-Qt/doric/utils/DoricConstant.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "DoricConstant.h"
|
||||
|
||||
const QString DoricConstant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.es5.js";
|
||||
const QString DoricConstant::DORIC_BUNDLE_LIB = "doric-lib.es5.js";
|
||||
const QString DoricConstant::DORIC_MODULE_LIB = "doric";
|
||||
|
||||
const QString DoricConstant::INJECT_ENVIRONMENT = "Environment";
|
||||
const QString DoricConstant::INJECT_LOG = "nativeLog";
|
||||
const QString DoricConstant::INJECT_EMPTY = "nativeEmpty";
|
||||
const QString DoricConstant::INJECT_REQUIRE = "nativeRequire";
|
||||
const QString DoricConstant::INJECT_TIMER_SET = "nativeSetTimer";
|
||||
const QString DoricConstant::INJECT_TIMER_CLEAR = "nativeClearTimer";
|
||||
const QString DoricConstant::INJECT_BRIDGE = "nativeBridge";
|
||||
|
||||
const QString DoricConstant::TEMPLATE_CONTEXT_CREATE =
|
||||
QString("Reflect.apply(") +
|
||||
"function(doric,context,Entry,require,exports){" + "\n" + "%s1" + "\n" +
|
||||
"},undefined,[" + "undefined," + "doric.jsObtainContext(\"%s2\")," +
|
||||
"doric.jsObtainEntry(\"%s3\")," + "doric.__require__" + ",{}" + "])";
|
||||
const QString DoricConstant::TEMPLATE_MODULE =
|
||||
QString("Reflect.apply(doric.jsRegisterModule,this,[") + "\"%s1\"," +
|
||||
"Reflect.apply(function(__module){" + "(function(module,exports,require){" +
|
||||
"\n" + "%s2" + "\n" + "})(__module,__module.exports,doric.__require__);" +
|
||||
"\nreturn __module.exports;" + "},this,[{exports:{}}])" + "])";
|
||||
const QString DoricConstant::TEMPLATE_CONTEXT_DESTROY =
|
||||
QString("doric.jsReleaseContext(\"%s\")");
|
||||
|
||||
const QString DoricConstant::GLOBAL_DORIC = "doric";
|
||||
const QString DoricConstant::DORIC_CONTEXT_INVOKE = "jsCallEntityMethod";
|
||||
const QString DoricConstant::DORIC_TIMER_CALLBACK = "jsCallbackTimer";
|
||||
|
||||
const QString DoricConstant::DORIC_ENTITY_INIT = "__init__";
|
||||
const QString DoricConstant::DORIC_ENTITY_CREATE = "__onCreate__";
|
||||
const QString DoricConstant::DORIC_ENTITY_BUILD = "__build__";
|
34
doric-Qt/doric/utils/DoricConstant.h
Normal file
34
doric-Qt/doric/utils/DoricConstant.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef CONSTANT_H
|
||||
#define CONSTANT_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class DoricConstant {
|
||||
|
||||
public:
|
||||
static const QString DORIC_BUNDLE_SANDBOX;
|
||||
static const QString DORIC_BUNDLE_LIB;
|
||||
static const QString DORIC_MODULE_LIB;
|
||||
|
||||
static const QString INJECT_ENVIRONMENT;
|
||||
static const QString INJECT_LOG;
|
||||
static const QString INJECT_EMPTY;
|
||||
static const QString INJECT_REQUIRE;
|
||||
static const QString INJECT_TIMER_SET;
|
||||
static const QString INJECT_TIMER_CLEAR;
|
||||
static const QString INJECT_BRIDGE;
|
||||
|
||||
static const QString TEMPLATE_CONTEXT_CREATE;
|
||||
static const QString TEMPLATE_MODULE;
|
||||
static const QString TEMPLATE_CONTEXT_DESTROY;
|
||||
|
||||
static const QString GLOBAL_DORIC;
|
||||
static const QString DORIC_CONTEXT_INVOKE;
|
||||
static const QString DORIC_TIMER_CALLBACK;
|
||||
|
||||
static const QString DORIC_ENTITY_CREATE;
|
||||
static const QString DORIC_ENTITY_INIT;
|
||||
static const QString DORIC_ENTITY_BUILD;
|
||||
};
|
||||
|
||||
#endif // CONSTANT_H
|
32
doric-Qt/doric/utils/DoricCountDownLatch.h
Normal file
32
doric-Qt/doric/utils/DoricCountDownLatch.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef COUNTDOWNLATCH_H
|
||||
#define COUNTDOWNLATCH_H
|
||||
|
||||
#include <QSemaphore>
|
||||
#include <climits>
|
||||
|
||||
class DoricCountDownLatch {
|
||||
Q_DISABLE_COPY(DoricCountDownLatch)
|
||||
QSemaphore m_sem{INT_MAX};
|
||||
|
||||
public:
|
||||
DoricCountDownLatch() {}
|
||||
~DoricCountDownLatch() {
|
||||
m_sem.acquire(INT_MAX);
|
||||
m_sem.release(INT_MAX);
|
||||
}
|
||||
class Locker {
|
||||
DoricCountDownLatch *sem;
|
||||
|
||||
public:
|
||||
Locker(const Locker &other) : sem{other.sem} { sem->m_sem.acquire(); }
|
||||
Locker(Locker &&other) : sem{other.sem} { other.sem = nullptr; }
|
||||
Locker(DoricCountDownLatch *sem) : sem{sem} { sem->m_sem.acquire(); }
|
||||
~Locker() {
|
||||
if (sem)
|
||||
sem->m_sem.release();
|
||||
}
|
||||
};
|
||||
Locker lock() { return Locker{this}; }
|
||||
};
|
||||
|
||||
#endif // COUNTDOWNLATCH_H
|
38
doric-Qt/doric/utils/DoricObjectFactory.h
Normal file
38
doric-Qt/doric/utils/DoricObjectFactory.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <QByteArray>
|
||||
#include <QHash>
|
||||
#include <QMetaObject>
|
||||
|
||||
#ifndef OBJECTFACTORY_H
|
||||
#define OBJECTFACTORY_H
|
||||
|
||||
class DoricObjectFactory {
|
||||
public:
|
||||
template <typename T> static void registerClass(QString name) {
|
||||
constructors().insert(name, &constructorHelper<T>);
|
||||
}
|
||||
|
||||
static bool acquireClass(QString name) {
|
||||
return constructors().keys().contains(name);
|
||||
}
|
||||
|
||||
static QObject *createObject(const QString &name, QObject *parent = NULL) {
|
||||
Constructor constructor = constructors().value(name);
|
||||
if (constructor == NULL)
|
||||
return NULL;
|
||||
return (*constructor)(parent);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef QObject *(*Constructor)(QObject *parent);
|
||||
|
||||
template <typename T> static QObject *constructorHelper(QObject *parent) {
|
||||
return new T(parent);
|
||||
}
|
||||
|
||||
static QHash<QString, Constructor> &constructors() {
|
||||
static QHash<QString, Constructor> instance;
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // OBJECTFACTORY_H
|
25
doric-Qt/doric/utils/DoricUtils.h
Normal file
25
doric-Qt/doric/utils/DoricUtils.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <QFile>
|
||||
#include <QResource>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
|
||||
class DoricUtils {
|
||||
public:
|
||||
static QString readAssetFile(QString preffix, QString assetName) {
|
||||
QResource resource(":" + preffix + "/" + assetName);
|
||||
QFile *file = new QFile(resource.fileName());
|
||||
file->open(QFile::ReadOnly | QFile::Text);
|
||||
QTextStream in(file);
|
||||
in.setCodec("UTF-8");
|
||||
QString content = in.readAll();
|
||||
file->close();
|
||||
delete file;
|
||||
|
||||
return content;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // UTILS_H
|
@@ -1,42 +0,0 @@
|
||||
#include "constant.h"
|
||||
|
||||
const QString Constant::DORIC_BUNDLE_SANDBOX = "doric-sandbox.es5.js";
|
||||
const QString Constant::DORIC_BUNDLE_LIB = "doric-lib.es5.js";
|
||||
const QString Constant::DORIC_MODULE_LIB = "doric";
|
||||
|
||||
const QString Constant::INJECT_ENVIRONMENT = "Environment";
|
||||
const QString Constant::INJECT_LOG = "nativeLog";
|
||||
const QString Constant::INJECT_EMPTY = "nativeEmpty";
|
||||
const QString Constant::INJECT_REQUIRE = "nativeRequire";
|
||||
const QString Constant::INJECT_TIMER_SET = "nativeSetTimer";
|
||||
const QString Constant::INJECT_TIMER_CLEAR = "nativeClearTimer";
|
||||
const QString Constant::INJECT_BRIDGE = "nativeBridge";
|
||||
|
||||
const QString Constant::TEMPLATE_CONTEXT_CREATE = QString("Reflect.apply(") +
|
||||
"function(doric,context,Entry,require,exports){" + "\n" +
|
||||
"%s1" + "\n" +
|
||||
"},undefined,[" +
|
||||
"undefined," +
|
||||
"doric.jsObtainContext(\"%s2\")," +
|
||||
"doric.jsObtainEntry(\"%s3\")," +
|
||||
"doric.__require__" +
|
||||
",{}" +
|
||||
"])";
|
||||
const QString Constant::TEMPLATE_MODULE = QString("Reflect.apply(doric.jsRegisterModule,this,[") +
|
||||
"\"%s1\"," +
|
||||
"Reflect.apply(function(__module){" +
|
||||
"(function(module,exports,require){" + "\n" +
|
||||
"%s2" + "\n" +
|
||||
"})(__module,__module.exports,doric.__require__);" +
|
||||
"\nreturn __module.exports;" +
|
||||
"},this,[{exports:{}}])" +
|
||||
"])";
|
||||
const QString Constant::TEMPLATE_CONTEXT_DESTROY = QString("doric.jsReleaseContext(\"%s\")");
|
||||
|
||||
const QString Constant::GLOBAL_DORIC = "doric";
|
||||
const QString Constant::DORIC_CONTEXT_INVOKE = "jsCallEntityMethod";
|
||||
const QString Constant::DORIC_TIMER_CALLBACK = "jsCallbackTimer";
|
||||
|
||||
const QString Constant::DORIC_ENTITY_INIT = "__init__";
|
||||
const QString Constant::DORIC_ENTITY_CREATE = "__onCreate__";
|
||||
const QString Constant::DORIC_ENTITY_BUILD = "__build__";
|
@@ -1,35 +0,0 @@
|
||||
#ifndef CONSTANT_H
|
||||
#define CONSTANT_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class Constant {
|
||||
|
||||
public:
|
||||
static const QString DORIC_BUNDLE_SANDBOX;
|
||||
static const QString DORIC_BUNDLE_LIB;
|
||||
static const QString DORIC_MODULE_LIB;
|
||||
|
||||
static const QString INJECT_ENVIRONMENT;
|
||||
static const QString INJECT_LOG;
|
||||
static const QString INJECT_EMPTY;
|
||||
static const QString INJECT_REQUIRE;
|
||||
static const QString INJECT_TIMER_SET;
|
||||
static const QString INJECT_TIMER_CLEAR;
|
||||
static const QString INJECT_BRIDGE;
|
||||
|
||||
static const QString TEMPLATE_CONTEXT_CREATE;
|
||||
static const QString TEMPLATE_MODULE;
|
||||
static const QString TEMPLATE_CONTEXT_DESTROY;
|
||||
|
||||
static const QString GLOBAL_DORIC;
|
||||
static const QString DORIC_CONTEXT_INVOKE;
|
||||
static const QString DORIC_TIMER_CALLBACK;
|
||||
|
||||
static const QString DORIC_ENTITY_CREATE;
|
||||
static const QString DORIC_ENTITY_INIT;
|
||||
static const QString DORIC_ENTITY_BUILD;
|
||||
};
|
||||
|
||||
|
||||
#endif // CONSTANT_H
|
@@ -1,27 +0,0 @@
|
||||
#ifndef COUNTDOWNLATCH_H
|
||||
#define COUNTDOWNLATCH_H
|
||||
|
||||
#include <climits>
|
||||
#include <QSemaphore>
|
||||
|
||||
class CountDownLatch {
|
||||
Q_DISABLE_COPY(CountDownLatch)
|
||||
QSemaphore m_sem{INT_MAX};
|
||||
public:
|
||||
CountDownLatch() {}
|
||||
~CountDownLatch() {
|
||||
m_sem.acquire(INT_MAX);
|
||||
m_sem.release(INT_MAX);
|
||||
}
|
||||
class Locker {
|
||||
CountDownLatch * sem;
|
||||
public:
|
||||
Locker(const Locker & other) : sem{other.sem} { sem->m_sem.acquire(); }
|
||||
Locker(Locker && other) : sem{other.sem} { other.sem = nullptr; }
|
||||
Locker(CountDownLatch * sem) : sem{sem} { sem->m_sem.acquire(); }
|
||||
~Locker() { if (sem) sem->m_sem.release(); }
|
||||
};
|
||||
Locker lock() { return Locker{this}; }
|
||||
};
|
||||
|
||||
#endif // COUNTDOWNLATCH_H
|
@@ -1,46 +0,0 @@
|
||||
#include <QByteArray>
|
||||
#include <QMetaObject>
|
||||
#include <QHash>
|
||||
|
||||
#ifndef OBJECTFACTORY_H
|
||||
#define OBJECTFACTORY_H
|
||||
|
||||
class ObjectFactory
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static void registerClass(QString name)
|
||||
{
|
||||
constructors().insert(name, &constructorHelper<T>);
|
||||
}
|
||||
|
||||
static bool acquireClass(QString name)
|
||||
{
|
||||
return constructors().keys().contains(name);
|
||||
}
|
||||
|
||||
static QObject* createObject(const QString& name, QObject* parent = NULL)
|
||||
{
|
||||
Constructor constructor = constructors().value(name);
|
||||
if ( constructor == NULL )
|
||||
return NULL;
|
||||
return (*constructor)(parent);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef QObject* (*Constructor)(QObject* parent);
|
||||
|
||||
template<typename T>
|
||||
static QObject* constructorHelper(QObject* parent)
|
||||
{
|
||||
return new T(parent);
|
||||
}
|
||||
|
||||
static QHash<QString, Constructor>& constructors()
|
||||
{
|
||||
static QHash<QString, Constructor> instance;
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // OBJECTFACTORY_H
|
@@ -1,26 +0,0 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <QString>
|
||||
#include <QResource>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
class Utils
|
||||
{
|
||||
public:
|
||||
static QString readAssetFile(QString preffix, QString assetName) {
|
||||
QResource resource(":" + preffix + "/" + assetName);
|
||||
QFile *file = new QFile(resource.fileName());
|
||||
file->open(QFile::ReadOnly | QFile::Text);
|
||||
QTextStream in(file);
|
||||
in.setCodec("UTF-8");
|
||||
QString content = in.readAll();
|
||||
file->close();
|
||||
delete file;
|
||||
|
||||
return content;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // UTILS_H
|
Reference in New Issue
Block a user