dl::ModelRegistry
dl::ModelRegistry
A lightweight compile-time registry of available ModelBase subclasses, queryable by model ID and enumerable by the UI. More…
#include <ModelRegistry.hpp>
Public Types
| Name | |
|---|---|
| using std::function< std::unique_ptr< ModelBase >()> | FactoryFn |
Public Functions
| Name | |
|---|---|
| ModelRegistry & | instance() Get the singleton instance. |
| void | registerModel(std::string const & model_id, FactoryFn factory) Register a model factory by ID. |
| void | registerConfiguration(std::string const & model_id, ModelConfigurationEntry entry) Register optional configuration hooks for a model. |
| bool | hasConfiguration(std::string const & model_id) const Whether model_id has registered configuration hooks. |
| std::optional< ParameterSchema > | getConfigurationSchema(std::string const & model_id) const Query the parameter schema for a model’s configuration. |
| std::string | defaultConfigurationJson(std::string const & model_id) const Default configuration JSON for a model. |
| void | applyConfiguration(std::string const & model_id, ModelBase & model, std::string const & json) const Apply persisted configuration JSON to a live model instance. |
| bool | configurationComplete(std::string const & model_id, std::string const & json) const Whether persisted configuration JSON is complete for weight loading. |
| std::string | configurationFormJson(std::string const & model_id, std::string const & stored_json) const Convert stored configuration JSON to form JSON for AutoParamWidget. |
| std::string | configurationStoredJson(std::string const & model_id, std::string const & form_json, bool applied) const Convert form JSON to stored configuration JSON. |
| bool | unregisterModel(std::string const & model_id) Remove a previously registered model by ID. |
| std::vector< std::string > | availableModels() const Get a sorted list of all registered model IDs. |
| std::size_t | size() const Get the number of registered models. |
| bool | hasModel(std::string const & model_id) const Check if a model ID is registered. |
| std::unique_ptr< ModelBase > | create(std::string const & model_id) const Instantiate a model by ID. |
| std::optional< ModelInfo > | getModelInfo(std::string const & model_id) const Query aggregated metadata for a model without keeping the instance. |
| TensorSlotDescriptor const * | getInputSlot(std::string const & model_id, std::string const & slot_name) const Look up a specific input slot descriptor for a model. |
| TensorSlotDescriptor const * | getOutputSlot(std::string const & model_id, std::string const & slot_name) const Look up a specific output slot descriptor for a model. |
| std::optional< std::string > | registerFromJson(std::filesystem::path const & json_path, std::string * error_out =[nullptr]) Load a JSON model spec from a file and register the resulting RuntimeModel. |
| void | clear() Remove all registered models and clear the info cache. |
Detailed Description
class dl::ModelRegistry;A lightweight compile-time registry of available ModelBase subclasses, queryable by model ID and enumerable by the UI.
Models self-register via [registerModel()](/api_generated/Classes/classdl_1_1ModelRegistry.md#function-registermodel) at static-init time or explicitly during application startup. The UI queries [availableModels()](/api_generated/Classes/classdl_1_1ModelRegistry.md#function-availablemodels) to populate combo boxes and [getModelInfo()](/api_generated/Classes/classdl_1_1ModelRegistry.md#function-getmodelinfo) to display slot metadata without constructing the full model.
Thread-safe: all methods are protected by a mutex.
Usage:
// Registration (typically in the model's .cpp file):
DL_REGISTER_MODEL(MyModel)
// Or manually:
dl::ModelRegistry::instance().registerModel(
"my_model",
[] { return std::make_unique<MyModel>(); });
// Querying:
auto ids = dl::ModelRegistry::instance().availableModels();
auto info = dl::ModelRegistry::instance().getModelInfo("my_model");
auto model = dl::ModelRegistry::instance().create("my_model");Public Types Documentation
using FactoryFn
using dl::ModelRegistry::FactoryFn = std::function<std::unique_ptr<ModelBase>()>;Public Functions Documentation
function instance
static ModelRegistry & instance()Get the singleton instance.
function registerModel
void registerModel(
std::string const & model_id,
FactoryFn factory
)Register a model factory by ID.
If a model with the same ID is already registered, it is silently overwritten (useful for hot-reload / runtime JSON override).
function registerConfiguration
void registerConfiguration(
std::string const & model_id,
ModelConfigurationEntry entry
)Register optional configuration hooks for a model.
Precondition: A factory for model_id must already be registered.
function hasConfiguration
bool hasConfiguration(
std::string const & model_id
) constWhether model_id has registered configuration hooks.
function getConfigurationSchema
std::optional< ParameterSchema > getConfigurationSchema(
std::string const & model_id
) constQuery the parameter schema for a model’s configuration.
function defaultConfigurationJson
std::string defaultConfigurationJson(
std::string const & model_id
) constDefault configuration JSON for a model.
Return: "{}" when the model has no registered configuration.
function applyConfiguration
void applyConfiguration(
std::string const & model_id,
ModelBase & model,
std::string const & json
) constApply persisted configuration JSON to a live model instance.
function configurationComplete
bool configurationComplete(
std::string const & model_id,
std::string const & json
) constWhether persisted configuration JSON is complete for weight loading.
Return: true when the model has no configuration hooks.
function configurationFormJson
std::string configurationFormJson(
std::string const & model_id,
std::string const & stored_json
) constConvert stored configuration JSON to form JSON for AutoParamWidget.
function configurationStoredJson
std::string configurationStoredJson(
std::string const & model_id,
std::string const & form_json,
bool applied
) constConvert form JSON to stored configuration JSON.
function unregisterModel
bool unregisterModel(
std::string const & model_id
)Remove a previously registered model by ID.
Return: True if the model was found and removed.
function availableModels
std::vector< std::string > availableModels() constGet a sorted list of all registered model IDs.
function size
std::size_t size() constGet the number of registered models.
function hasModel
bool hasModel(
std::string const & model_id
) constCheck if a model ID is registered.
function create
std::unique_ptr< ModelBase > create(
std::string const & model_id
) constInstantiate a model by ID.
Return: nullptr if the ID is not registered.
function getModelInfo
std::optional< ModelInfo > getModelInfo(
std::string const & model_id
) constQuery aggregated metadata for a model without keeping the instance.
Return: std::nullopt if the model ID is not registered.
function getInputSlot
TensorSlotDescriptor const * getInputSlot(
std::string const & model_id,
std::string const & slot_name
) constLook up a specific input slot descriptor for a model.
Return: nullptr if the model or slot is not found.
function getOutputSlot
TensorSlotDescriptor const * getOutputSlot(
std::string const & model_id,
std::string const & slot_name
) constLook up a specific output slot descriptor for a model.
Return: nullptr if the model or slot is not found.
function registerFromJson
std::optional< std::string > registerFromJson(
std::filesystem::path const & json_path,
std::string * error_out =nullptr
)Load a JSON model spec from a file and register the resulting RuntimeModel.
On success, returns the model_id. On failure returns std::nullopt. If error_out is non-null, it receives the error message on failure.
function clear
void clear()Remove all registered models and clear the info cache.
Primarily useful for testing.
Updated on 2026-11-13 at 20:25:42 +0000