This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/doric/context_manager.h

42 lines
1003 B
C
Raw Normal View History

2021-01-28 17:06:40 +08:00
#ifndef CONTEXTMANAGER_H
#define CONTEXTMANAGER_H
2019-12-04 15:51:46 +08:00
#include <QDebug>
#include "context.h"
class ContextManager
{
private:
static ContextManager *local_instance;
2021-01-28 17:06:40 +08:00
ContextManager()
{
qDebug() << "ContextManager create";
2019-12-04 15:51:46 +08:00
}
2021-01-28 17:06:40 +08:00
~ContextManager()
{
qDebug() << "ContextManager destroy";
2019-12-04 15:51:46 +08:00
}
QAtomicInt *counter = new QAtomicInt();
2021-01-28 17:06:40 +08:00
QMap<QString, Context*> *contextMap = new QMap<QString, Context*>();
2019-12-04 15:51:46 +08:00
public:
2021-01-28 17:06:40 +08:00
static ContextManager *getInstance()
{
static ContextManager instance;
return &instance;
2019-12-04 15:51:46 +08:00
}
2021-01-28 17:06:40 +08:00
Context *createContext(QString script, QString source, QString extra) {
2019-12-04 15:51:46 +08:00
int contextId = counter->fetchAndAddOrdered(1);
2021-01-28 17:06:40 +08:00
Context *context = new Context(QString::number(contextId), source, extra);
contextMap->insert(QString::number(contextId), context);
2021-01-28 18:08:13 +08:00
context->getDriver()->createContext(QString::number(contextId), script, source);
2019-12-04 15:51:46 +08:00
return context;
}
};
2021-01-28 17:06:40 +08:00
#endif // CONTEXTMANAGER_H