v2.0.0
Loading...
Searching...
No Matches
mna_op_schema.cpp
Go to the documentation of this file.
1//=============================================================================================================
32
33//=============================================================================================================
34// INCLUDES
35//=============================================================================================================
36
37#include "mna_op_schema.h"
38#include "mna_node.h"
39
40//=============================================================================================================
41// USED NAMESPACES
42//=============================================================================================================
43
44using namespace MNALIB;
45
46//=============================================================================================================
47// DEFINE MEMBER METHODS
48//=============================================================================================================
49
50bool MnaOpSchema::validate(const MnaNode& node, QStringList* errors) const
51{
52 bool valid = true;
53
54 // Check op type matches
55 if (node.opType != opType) {
56 if (errors)
57 errors->append(QString("Op type mismatch: expected '%1', got '%2'").arg(opType, node.opType));
58 return false;
59 }
60
61 // Check required input ports
62 for (const MnaOpSchemaPort& sp : inputPorts) {
63 if (!sp.required)
64 continue;
65 bool found = false;
66 for (const MnaPort& np : node.inputs) {
67 if (np.name == sp.name) {
68 found = true;
69 if (np.dataKind != sp.dataKind) {
70 if (errors)
71 errors->append(QString("Input port '%1': expected data kind '%2'")
72 .arg(sp.name).arg(static_cast<int>(sp.dataKind)));
73 valid = false;
74 }
75 break;
76 }
77 }
78 if (!found) {
79 if (errors)
80 errors->append(QString("Missing required input port '%1'").arg(sp.name));
81 valid = false;
82 }
83 }
84
85 // Check required output ports
86 for (const MnaOpSchemaPort& sp : outputPorts) {
87 if (!sp.required)
88 continue;
89 bool found = false;
90 for (const MnaPort& np : node.outputs) {
91 if (np.name == sp.name) {
92 found = true;
93 break;
94 }
95 }
96 if (!found) {
97 if (errors)
98 errors->append(QString("Missing required output port '%1'").arg(sp.name));
99 valid = false;
100 }
101 }
102
103 // Check required attributes
104 for (const MnaOpSchemaAttr& sa : attributes) {
105 if (!sa.required)
106 continue;
107 if (!node.attributes.contains(sa.name)) {
108 if (errors)
109 errors->append(QString("Missing required attribute '%1'").arg(sa.name));
110 valid = false;
111 }
112 }
113
114 return valid;
115}
MnaOpSchema class declaration — contract for graph operations.
MnaNode struct declaration — one operation in the computational graph.
MNE Analysis Container Format (mna/mnx).
Graph node representing a processing step.
Definition mna_node.h:75
QList< MnaPort > inputs
Input ports.
Definition mna_node.h:80
QVariantMap attributes
Operation parameters.
Definition mna_node.h:78
QString opType
Operation type (looked up in MnaOpRegistry).
Definition mna_node.h:77
QList< MnaPort > outputs
Output ports.
Definition mna_node.h:81
QList< MnaOpSchemaPort > outputPorts
Expected output ports.
QList< MnaOpSchemaPort > inputPorts
Expected input ports.
QList< MnaOpSchemaAttr > attributes
Expected attributes.
bool validate(const MnaNode &node, QStringList *errors=nullptr) const
QString opType
Operation type string.
Graph port descriptor.
Definition mna_port.h:68
QString name
Port name (unique within a node).
Definition mna_port.h:69
MnaDataKind dataKind
Data kind flowing through this port.
Definition mna_port.h:70