MnaOpRegistry
Namespace: MNALIB · Library: MNA Library
#include <mna/mna_op_registry.h>
class MNALIB::MnaOpRegistry
Singleton catalog of all registered operation schemas.
Process-wide lookup from opType to MnaOpSchema and implementation function.
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()}};
});
Public Methods
registerOp(schema)
Register an operation schema.
Parameters:
- schema : const MnaOpSchema & Schema to store; replaces any existing schema with the same opType.
hasOp(opType)
Check if an operation type is registered.
Parameters:
- opType : const QString & Operation type name to look up.
Returns:
- bool — true if a schema is registered for opType, false otherwise.
schema(opType)
Get the schema for an operation type.
Parameters:
- opType : const QString & Operation type name to look up.
Returns:
- MnaOpSchema — The registered schema, or a default-constructed schema if opType is unknown.
registeredOps()
List all registered operation types.
Returns:
- QStringList — Names of all operation types that have a registered schema.
registerOpFunc(opType, func)
Register an implementation function for an operation type.
Parameters:
-
opType : const QString & Operation type name the function implements.
-
func : OpFunc Callback mapping inputs and attributes to outputs; replaces any existing one.
opFunc(opType)
Get the implementation function for an operation type.
Parameters:
- opType : const QString & Operation type name to look up.
Returns:
- OpFunc — The registered callback, or an empty
OpFuncif none is registered.
loadRegistryFiles()
Load registry files from the standard resources/mna/ directory.
Searches upward from the application directory to find resources/mna/, then loads mna-registry.json and all drop-in files from mna-registry.d/.
Returns:
- int — Number of ops loaded, or 0 if no registry directory was found.
missingOps(pipelineTools)
Return op types referenced in a project that have no registered schema.
Parameters:
- pipelineTools : const QStringList & The MNA project to check.
Returns:
- QStringList — List of op type strings with no registered schema.
Static Methods
instance()
Access the singleton instance.
Returns:
- MnaOpRegistry & — Reference to the process-wide registry.
Example
- Full source:
src/examples/ex_mna/main.cpp - Build target:
ex_mna(runs under CTest)
Used in examples
ex_mna
MNA library: register operations, build and run a graph, bind parameters and save a project.
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
- Christoph Dinh <christoph.dinh@mne-cpp.org>