eis/TestProject/RNG/model/ModelRegistry.h
Huamonarch b4bb27f1e5 feat: add ModelRegistry with JSON loading and composite model
Add CompositeModel for combining base+noise models, ModelRegistry singleton
with JSON-based model template loading, per-instance-key model isolation,
and inline CSV/valve pair/composite syntax parsing in createModel.
2026-05-13 15:20:51 +08:00

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;
};