v2.0.0
Loading...
Searching...
No Matches
mna_op_registry.cpp
Go to the documentation of this file.
1//=============================================================================================================
25
26//=============================================================================================================
27// INCLUDES
28//=============================================================================================================
29
30#include "mna_op_registry.h"
31#include "mna_registry_loader.h"
32
33//=============================================================================================================
34// QT INCLUDES
35//=============================================================================================================
36
37#include <QCoreApplication>
38#include <QDir>
39#include <QFile>
40
41//=============================================================================================================
42// USED NAMESPACES
43//=============================================================================================================
44
45using namespace MNALIB;
46
47//=============================================================================================================
48// DEFINE MEMBER METHODS
49//=============================================================================================================
50
51MnaOpRegistry::MnaOpRegistry()
52{
54}
55
56//=============================================================================================================
57
59{
60 static MnaOpRegistry registry;
61 return registry;
62}
63
64//=============================================================================================================
65
67{
68 m_schemas.insert(schema.opType, schema);
69}
70
71//=============================================================================================================
72
73bool MnaOpRegistry::hasOp(const QString& opType) const
74{
75 return m_schemas.contains(opType);
76}
77
78//=============================================================================================================
79
80MnaOpSchema MnaOpRegistry::schema(const QString& opType) const
81{
82 return m_schemas.value(opType);
83}
84
85//=============================================================================================================
86
88{
89 return m_schemas.keys();
90}
91
92//=============================================================================================================
93
94void MnaOpRegistry::registerOpFunc(const QString& opType, OpFunc func)
95{
96 m_funcs.insert(opType, func);
97}
98
99//=============================================================================================================
100
102{
103 return m_funcs.value(opType);
104}
105
106//=============================================================================================================
107
109{
110 // Search for resources/mna/ directory, walking up from the application dir
111 const QString relPath = QStringLiteral("resources/mna");
112
113 QDir dir(QCoreApplication::applicationDirPath());
114 for (int i = 0; i < 6; ++i) {
115 QString candidate = dir.absoluteFilePath(relPath);
116 if (QDir(candidate).exists()) {
117 return MnaRegistryLoader::loadDirectory(candidate, *this);
118 }
119 dir.cdUp();
120 }
121
122 // Try from current working directory
123 if (QDir(relPath).exists())
124 return MnaRegistryLoader::loadDirectory(QDir::currentPath() + QStringLiteral("/") + relPath, *this);
125
126 qWarning() << "MnaOpRegistry: Could not find resources/mna/ registry directory";
127 return 0;
128}
129
130//=============================================================================================================
131
132QStringList MnaOpRegistry::missingOps(const QStringList& pipelineTools) const
133{
134 QStringList missing;
135 for (const QString& tool : pipelineTools) {
136 if (!m_schemas.contains(tool))
137 missing.append(tool);
138 }
139 return missing;
140}
Declarative loader for MnaOpRegistry contents — ingests mna-registry.json manifests and overrides the...
Process-wide singleton catalog mapping opType strings to their MnaOpSchema and (for built-in ops) exe...
MNE Analysis Container Format (mna/mnx).
static MnaOpRegistry & instance()
OpFunc opFunc(const QString &opType) const
QStringList registeredOps() const
bool hasOp(const QString &opType) const
void registerOpFunc(const QString &opType, OpFunc func)
void registerOp(const MnaOpSchema &schema)
MnaOpSchema schema(const QString &opType) const
QStringList missingOps(const QStringList &pipelineTools) const
std::function< QVariantMap(const QVariantMap &inputs, const QVariantMap &attributes)> OpFunc
Operation implementation callback type.
Operation schema for graph validation.
static int loadDirectory(const QString &registryDir, MnaOpRegistry &registry)