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).arg(static_cast<int>(sp.dataKind)));
64 valid = false;
65 }
66 break;
67 }
68 }
69 if (!found) {
70 if (errors)
71 errors->append(QString("Missing required input port '%1'").arg(sp.name));
72 valid = false;
73 }
74 }
75
76 // Check required output ports
77 for (const MnaOpSchemaPort& sp : outputPorts) {
78 if (!sp.required)
79 continue;
80 bool found = false;
81 for (const MnaPort& np : node.outputs) {
82 if (np.name == sp.name) {
83 found = true;
84 break;
85 }
86 }
87 if (!found) {
88 if (errors)
89 errors->append(QString("Missing required output port '%1'").arg(sp.name));
90 valid = false;
91 }
92 }
93
94 // Check required attributes
95 for (const MnaOpSchemaAttr& sa : attributes) {
96 if (!sa.required)
97 continue;
98 if (!node.attributes.contains(sa.name)) {
99 if (errors)
100 errors->append(QString("Missing required attribute '%1'").arg(sa.name));
101 valid = false;
102 }
103 }
104
105 return valid;
106}
One operation in an MNA graph — opType, typed I/O ports, attributes, execution mode (Batch / Stream /...
Declarative contract for an MNA operation — expected input/output ports, attributes,...
MNE Analysis Container Format (mna/mnx).
Single executable step in an MNA pipeline graph, with attributes, typed ports, exec mode,...
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.
Named, typed port on an MNA graph node with upstream link and optional real-time stream binding.
Definition mna_port.h:63
QString name
Port name (unique within a node).
Definition mna_port.h:64
MnaDataKind dataKind
Data kind flowing through this port.
Definition mna_port.h:65