2020-12-01 14:00:49 +01:00
|
|
|
#ifndef DATABASE_MANAGER_H
|
|
|
|
#define DATABASE_MANAGER_H
|
|
|
|
|
2021-11-01 17:49:10 +01:00
|
|
|
#include "core/string.h"
|
|
|
|
|
2020-12-01 14:00:49 +01:00
|
|
|
#include <vector>
|
2020-12-01 14:47:24 +01:00
|
|
|
#include <map>
|
|
|
|
#include <functional>
|
2020-12-01 14:00:49 +01:00
|
|
|
|
2022-02-05 17:22:15 +01:00
|
|
|
#include "core/object.h"
|
|
|
|
|
2020-12-01 14:00:49 +01:00
|
|
|
#include "database.h"
|
|
|
|
|
2022-02-05 17:22:15 +01:00
|
|
|
class DatabaseManager : public Object {
|
|
|
|
RCPP_OBJECT(DatabaseManager, Object);
|
|
|
|
|
2020-12-01 14:00:49 +01:00
|
|
|
public:
|
|
|
|
std::vector<Database *> databases;
|
2021-05-01 21:53:21 +02:00
|
|
|
Database *ddb;
|
2020-12-01 14:00:49 +01:00
|
|
|
|
|
|
|
void load();
|
|
|
|
|
2020-12-01 14:47:24 +01:00
|
|
|
static DatabaseManager *get_singleton();
|
|
|
|
|
|
|
|
//note: not threadsafe, create these at the start of your program!
|
2021-11-01 17:49:10 +01:00
|
|
|
uint32_t create_database(const String &name);
|
2020-12-01 14:47:24 +01:00
|
|
|
|
2021-11-01 17:49:10 +01:00
|
|
|
static void _register_db_creation_func(const String &name, std::function<Database*()> func);
|
|
|
|
static void _unregister_db_creation_func(const String &name);
|
2020-12-01 14:47:24 +01:00
|
|
|
|
2021-11-01 17:49:10 +01:00
|
|
|
static Database *_create_database(const String &name);
|
2020-12-01 14:00:49 +01:00
|
|
|
|
|
|
|
DatabaseManager();
|
|
|
|
~DatabaseManager();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static DatabaseManager * _instance;
|
2020-12-01 14:47:24 +01:00
|
|
|
|
2021-11-01 17:49:10 +01:00
|
|
|
static std::map<String, std::function<Database *()> > _db_creation_func_map;
|
2020-12-01 14:00:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|