Skip to main content

MnaRegistryLoader

Namespace: MNALIB  ·  Library: MNA Library

#include <mna/mna_registry_loader.h>

class MNALIB::MnaRegistryLoader

Loads MNA operation schemas from declarative JSON registry manifests files.

Registry files follow the mna-registry.json format with "mna_registry_version", "provider", and "ops" array. The loader supports a master manifest plus drop-in files from a mna-registry.d/ directory.

Reads MNA op-schema manifests and feeds them into MnaOpRegistry, with drop-in directory merge support.

src/examples/ex_mna/main.cpp
MnaOpRegistry& registry = MnaOpRegistry::instance();
const int nLoaded = MnaRegistryLoader::loadFile(registryFile.fileName(), registry); // schemas only
registry.registerOpFunc("ex_constant", [](const QVariantMap&, const QVariantMap& attrs) -> QVariantMap {
return {{"out", attrs.value("value").toDouble()}};
});
registry.registerOpFunc("ex_affine", [](const QVariantMap& inputs, const QVariantMap& attrs) -> QVariantMap {
return {{"out", attrs.value("gain", 1.0).toDouble() * inputs.value("in").toDouble() + attrs.value("offset", 0.0).toDouble()}};
});

Static Methods​

loadFile(path, registry)​

Load a single registry manifest file and register all ops.

Parameters:

  • path : const QString & Path to the JSON manifest file.

  • registry : MnaOpRegistry & Registry to populate.

Returns:

  • int — Number of ops successfully loaded, or -1 on file error.

loadDirectory(registryDir, registry)​

Load the master manifest plus all drop-in files from a directory.

Loads mna-registry.json first, then all *.json files from mna-registry.d/ in alphabetical order. Later files override earlier entries for the same op type.

Parameters:

  • registryDir : const QString & Directory containing mna-registry.json.

  • registry : MnaOpRegistry & Registry to populate.

Returns:

  • int — Total number of ops loaded across all files.

saveFile(path, provider, registry)​

Serialize current registry schemas to a JSON manifest file.

Parameters:

  • path : const QString & Output file path.

  • provider : const QString & Provider name for the manifest header.

  • registry : const MnaOpRegistry & Registry to serialize.

Returns:

  • bool — True if writing succeeded.

Example​

Used in examples​

ex_mna​

MNA library: register operations, build and run a graph, bind parameters and save a project.

src/examples/ex_mna/main.cpp, line 102
MnaOpRegistry& registry = MnaOpRegistry::instance();
const int nLoaded = MnaRegistryLoader::loadFile(registryFile.fileName(), registry); // schemas only
registry.registerOpFunc("ex_constant", [](const QVariantMap&, const QVariantMap& attrs) -> QVariantMap {
return {{"out", attrs.value("value").toDouble()}};
});
registry.registerOpFunc("ex_affine", [](const QVariantMap& inputs, const QVariantMap& attrs) -> QVariantMap {
return {{"out", attrs.value("gain", 1.0).toDouble() * inputs.value("in").toDouble() + attrs.value("offset", 0.0).toDouble()}};
});
ok &= expect(nLoaded == 2 && registry.hasOp("ex_affine") && registry.schema("ex_affine").inputPorts.size() == 1 && registry.missingOps({"ex_constant", "ex_affine", "ex_unknown"}) == QStringList({"ex_unknown"}),
"MnaRegistryLoader loads 2 ops; missingOps reports the unknown one");

Authors of this file​