v2.0.0
Loading...
Searching...
No Matches
mna_op_registry.cpp
Go to the documentation of this file.
1//=============================================================================================================
34
35//=============================================================================================================
36// INCLUDES
37//=============================================================================================================
38
39#include "mna_op_registry.h"
40#include "mna_registry_loader.h"
41
42//=============================================================================================================
43// QT INCLUDES
44//=============================================================================================================
45
46#include <QCoreApplication>
47#include <QDir>
48#include <QFile>
49
50//=============================================================================================================
51// USED NAMESPACES
52//=============================================================================================================
53
54using namespace MNALIB;
55
56//=============================================================================================================
57// DEFINE MEMBER METHODS
58//=============================================================================================================
59
60MnaOpRegistry::MnaOpRegistry()
61{
63}
64
65//=============================================================================================================
66
68{
69 static MnaOpRegistry registry;
70 return registry;
71}
72
73//=============================================================================================================
74
76{
77 m_schemas.insert(schema.opType, schema);
78}
79
80//=============================================================================================================
81
82bool MnaOpRegistry::hasOp(const QString& opType) const
83{
84 return m_schemas.contains(opType);
85}
86
87//=============================================================================================================
88
89MnaOpSchema MnaOpRegistry::schema(const QString& opType) const
90{
91 return m_schemas.value(opType);
92}
93
94//=============================================================================================================
95
97{
98 return m_schemas.keys();
99}
100
101//=============================================================================================================
102
103void MnaOpRegistry::registerOpFunc(const QString& opType, OpFunc func)
104{
105 m_funcs.insert(opType, func);
106}
107
108//=============================================================================================================
109
111{
112 return m_funcs.value(opType);
113}
114
115//=============================================================================================================
116
118{
119 // Search for resources/mna/ directory, walking up from the application dir
120 const QString relPath = QStringLiteral("resources/mna");
121
122 QDir dir(QCoreApplication::applicationDirPath());
123 for (int i = 0; i < 6; ++i) {
124 QString candidate = dir.absoluteFilePath(relPath);
125 if (QDir(candidate).exists()) {
126 return MnaRegistryLoader::loadDirectory(candidate, *this);
127 }
128 dir.cdUp();
129 }
130
131 // Try from current working directory
132 if (QDir(relPath).exists())
133 return MnaRegistryLoader::loadDirectory(QDir::currentPath() + QStringLiteral("/") + relPath, *this);
134
135 qWarning() << "MnaOpRegistry: Could not find resources/mna/ registry directory";
136 return 0;
137}
138
139//=============================================================================================================
140
141QStringList MnaOpRegistry::missingOps(const QStringList& pipelineTools) const
142{
143 QStringList missing;
144 for (const QString& tool : pipelineTools) {
145 if (!m_schemas.contains(tool))
146 missing.append(tool);
147 }
148 return missing;
149}
MnaOpRegistry class declaration — singleton catalog of operation schemas.
MnaRegistryLoader class declaration — loads MNA op schemas from JSON manifests.
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)