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

46 lines
1.0 KiB
C
Raw Normal View History

2019-12-04 15:51:46 +08:00
#ifndef CONTEXT_MANAGER_H
#define CONTEXT_MANAGER_H
#include <QAtomicInt>
#include <QDebug>
#include <QMap>
#include "context.h"
class ContextManager
{
private:
static ContextManager *local_instance;
ContextManager() {
qDebug() << "ContextManager constructor";
}
~ContextManager() {
qDebug() << "ContextManager destructor";
}
QAtomicInt *counter = new QAtomicInt();
QMap<int, Context*> *contextMap = new QMap<int, Context*>();
public:
static ContextManager *getInstance() {
static ContextManager locla_s;
return &locla_s;
}
2019-12-13 17:45:27 +08:00
Context *createContext(QString *script, QString *source) {
2019-12-04 15:51:46 +08:00
int contextId = counter->fetchAndAddOrdered(1);
2019-12-13 17:45:27 +08:00
Context *context = new Context(contextId, source);
2019-12-04 15:51:46 +08:00
contextMap->insert(contextId, context);
context->driver->createContext(contextId, script);
return context;
}
2019-12-13 17:45:27 +08:00
Context *getContext(int contextId) {
return contextMap->take(contextId);
}
2019-12-04 15:51:46 +08:00
};
#endif // CONTEXT_MANAGER_H