1 #include "BlockImplementation.h"
\r
3 #include "FunctionalBlock.h"
\r
4 #include "ReferenceBlock.h"
\r
5 #include "ReferenceInterface.h"
\r
6 #include "FunctionalInterface.h"
\r
7 #include "BlockParameter.h"
\r
8 #include <QHashIterator>
\r
11 BlockImplementation::BlockImplementation(const QString& _xmlFile) {
\r
13 productionCounter = "";
\r
16 evaluator = new ArithmeticEvaluator;
\r
17 evaluator->setVariableMarkers("@$");
\r
22 BlockImplementation::BlockImplementation(const QString& _xmlFile, const QString &_referenceXml, const QString &_referenceMd5) {
\r
23 xmlFile = _xmlFile;
\r
24 productionCounter = "";
\r
26 referenceXml = _referenceXml;
\r
27 referenceMd5 = _referenceMd5;
\r
32 void BlockImplementation::loadPatterns(QDomElement& root) throw(Exception) {
\r
34 QDomNodeList patternNode = root.elementsByTagName("patterns");
\r
36 if (patternNode.isEmpty()) {
\r
37 cout << "impl has no patterns" << endl;
\r
41 QDomElement patternElt = patternNode.at(0).toElement();
\r
43 QDomElement eltDelta = patternElt.firstChildElement("delta");
\r
44 delta = eltDelta.attribute("value","none");
\r
45 if (delta == "none") throw(Exception(IMPLFILE_CORRUPTED));
\r
47 QDomElement eltCons = eltDelta.nextSiblingElement("consumption");
\r
49 QDomNodeList listNodeInput = eltCons.elementsByTagName("input");
\r
50 for(int i=0; i<listNodeInput.size(); i++) {
\r
51 QDomNode node = listNodeInput.at(i);
\r
52 QDomElement elt = node.toElement();
\r
53 QString nameStr = elt.attribute("name","none");
\r
54 if (nameStr == "none") throw(Exception(IMPLFILE_CORRUPTED));
\r
55 QString patternStr = elt.attribute("pattern","none");
\r
56 if (patternStr == "none") throw(Exception(IMPLFILE_CORRUPTED));
\r
57 consumptionPattern.insert(nameStr,patternStr);
\r
60 QDomElement eltProd = eltCons.nextSiblingElement("production");
\r
62 productionCounter = eltProd.attribute("counter","none");
\r
63 QDomNodeList listNodeOutput = eltProd.elementsByTagName("output");
\r
64 for(int i=0; i<listNodeOutput.size(); i++) {
\r
65 QDomNode node = listNodeOutput.at(i);
\r
66 QDomElement elt = node.toElement();
\r
67 QString nameStr = elt.attribute("name","none");
\r
68 if (nameStr == "none") throw(Exception(IMPLFILE_CORRUPTED));
\r
69 QString patternStr = elt.attribute("pattern","none");
\r
70 if (patternStr == "none") throw(Exception(IMPLFILE_CORRUPTED));
\r
71 productionPattern.insert(nameStr,patternStr);
\r
73 cout << "patterns summary:" << endl;
\r
74 QHashIterator<QString,QString> iterP(productionPattern);
\r
75 while (iterP.hasNext()) {
\r
77 cout << qPrintable(iterP.key()) << " -> " << qPrintable(iterP.value()) << endl;
\r
79 cout << "impls patterns read correctly" << endl;
\r
83 bool BlockImplementation::checkPatterns() {
\r
86 if (reference == NULL) {
\r
87 cout << "no ref. while checking patterns of implementation " << endl;
\r
91 AbstractInterface* iface;
\r
92 QHashIterator<QString,QString> iterI(consumptionPattern);
\r
93 while (iterI.hasNext()) {
\r
95 iface = reference->getIfaceFromName(iterI.key());
\r
96 if (iface == NULL) {
\r
97 cout << "cannot found an input ref. iface for impl. iface " << qPrintable(iterI.key()) << endl;
\r
101 QHashIterator<QString,QString> iterO(productionPattern);
\r
102 while (iterO.hasNext()) {
\r
104 iface = reference->getIfaceFromName(iterO.key());
\r
105 if (iface == NULL) {
\r
106 cout << "cannot found an output ref. iface for impl. iface " << qPrintable(iterI.key()) << endl;
\r
113 QDataStream& operator<<(QDataStream &out, const BlockImplementation &impl) {
\r
115 out.setVersion(QDataStream::Qt_5_0);
\r
117 QByteArray blockData;
\r
118 QDataStream toWrite(&blockData, QIODevice::WriteOnly);
\r
120 toWrite << impl.xmlFile;
\r
121 toWrite << impl.referenceXml;
\r
122 toWrite << impl.referenceMd5;
\r
123 toWrite << impl.resources;
\r
125 toWrite << impl.noPatterns;
\r
126 toWrite << impl.delta;
\r
127 toWrite << impl.consumptionPattern;
\r
128 toWrite << impl.productionPattern;
\r
129 toWrite << impl.productionCounter;
\r
136 QDataStream& operator>>(QDataStream &in, BlockImplementation &impl) {
\r
140 in.setVersion(QDataStream::Qt_5_0);
\r
144 in >> impl.xmlFile;
\r
145 in >> impl.referenceXml;
\r
146 in >> impl.referenceMd5;
\r
147 in >> impl.resources;
\r
148 // loading patterns
\r
149 in >> impl.noPatterns;
\r
151 in >> impl.consumptionPattern;
\r
152 in >> impl.productionPattern;
\r
153 in >> impl.productionCounter;
\r