v2.0.0
Loading...
Searching...
No Matches
mna_op_schema.cpp
Go to the documentation of this file.
1//=============================================================================================================
23
24//=============================================================================================================
25// INCLUDES
26//=============================================================================================================
27
28#include "mna_op_schema.h"
29#include "mna_node.h"
30
31//=============================================================================================================
32// USED NAMESPACES
33//=============================================================================================================
34
35using namespace MNALIB;
36
37//=============================================================================================================
38// DEFINE MEMBER METHODS
39//=============================================================================================================
40
41bool MnaOpSchema::validate(const MnaNode& node, QStringList* errors) const
42{
43 bool valid = true;
44
45 // Check op type matches
46 if (node.opType != opType) {
47 if (errors)
48 errors->append(QString("Op type mismatch: expected '%1', got '%2'").arg(opType, node.opType));
49 return false;
50 }
51
52 // Check required input ports
53 for (const MnaOpSchemaPort& sp : inputPorts) {
54 if (!sp.required)
55 continue;
56 bool found = false;
57 for (const MnaPort& np : node.inputs) {
58 if (np.name == sp.name) {
59 found = true;
60 if (np.dataKind != sp.dataKind) {
61 if (errors)
62 errors->append(QString("Input port '%1': expected data kind '%2'")
63 .arg(sp.name)
64 .arg(static_cast<int>(sp.dataKind)));
65 valid = false;
66 }
67 break;
68 }
69 }
70 if (!found) {
71 if (errors)
72 errors->append(QString("Missing required input port '%1'").arg(sp.name));
73 valid = false;
74 }
75 }
76
77 // Check required output ports
78 for (const MnaOpSchemaPort& sp : outputPorts) {
79 if (!sp.required)
80 continue;
81 bool found = false;
82 for (const MnaPort& np : node.outputs) {
83 if (np.name == sp.name) {
84 found = true;
85 break;
86 }
87 }
88 if (!found) {
89 if (errors)
90 errors->append(QString("Missing required output port '%1'").arg(sp.name));
91 valid = false;
92 }
93 }
94
95 // Check required attributes
96 for (const MnaOpSchemaAttr& sa : attributes) {
97 if (!sa.required)
98 continue;
99 if (!node.attributes.contains(sa.name)) {
100 if (errors)
101 errors->append(QString("Missing required attribute '%1'").arg(sa.name));
102 valid = false;
103 }
104 }
105
106 return valid;
107}
Declarative contract for an MNA operation — expected input/output ports, attributes,...
One operation in an MNA graph — opType, typed I/O ports, attributes, execution mode (Batch / Stream /...
MNE Analysis Container Format (mna/mnx).
Single executable step in an MNA pipeline graph, with attributes, typed ports, exec mode,...
Definition mna_node.h:77
QList< MnaPort > inputs
Input ports.
Definition mna_node.h:82
QVariantMap attributes
Operation parameters.
Definition mna_node.h:80
QString opType
Operation type (looked up in MnaOpRegistry).
Definition mna_node.h:79
QList< MnaPort > outputs
Output ports.
Definition mna_node.h:83
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.
Named, typed port on an MNA graph node with upstream link and optional real-time stream binding.
Definition mna_port.h:65
QString name
Port name (unique within a node).
Definition mna_port.h:66
MnaDataKind dataKind
Data kind flowing through this port.
Definition mna_port.h:67