39 lines
1.0 KiB
C
39 lines
1.0 KiB
C
|
|
#pragma once
|
||
|
|
#include <TestProject/RNG/model/IModel.h>
|
||
|
|
#include <nlohmann/json.hpp>
|
||
|
|
#include <functional>
|
||
|
|
#include <map>
|
||
|
|
#include <memory>
|
||
|
|
#include <string>
|
||
|
|
#include <vector>
|
||
|
|
using json = nlohmann::json;
|
||
|
|
|
||
|
|
class ModelRegistry {
|
||
|
|
public:
|
||
|
|
using Ctor = std::function<std::unique_ptr<IModel>(const json& params, float defaultVal)>;
|
||
|
|
|
||
|
|
static ModelRegistry& instance();
|
||
|
|
|
||
|
|
void loadModels(const std::string& jsonPath);
|
||
|
|
|
||
|
|
IModel* getOrCreate(const std::string& tables1Spec, float defaultVal,
|
||
|
|
const std::string& instanceKey = "");
|
||
|
|
|
||
|
|
std::vector<IModel*> findByModelName(const std::string& modelName);
|
||
|
|
|
||
|
|
void registerMode(const std::string& mode, Ctor ctor);
|
||
|
|
|
||
|
|
private:
|
||
|
|
ModelRegistry();
|
||
|
|
std::unique_ptr<IModel> createModel(const std::string& modelName, float defaultVal);
|
||
|
|
|
||
|
|
struct ModelDef {
|
||
|
|
std::string mode;
|
||
|
|
json params;
|
||
|
|
};
|
||
|
|
std::map<std::string, ModelDef> modelTemplates;
|
||
|
|
std::map<std::string, std::unique_ptr<IModel>> instances;
|
||
|
|
std::map<std::string, std::vector<IModel*>> byModelName;
|
||
|
|
std::map<std::string, Ctor> factory;
|
||
|
|
};
|