+void FunctionalBlock::createPatterns() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::createPatterns()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ \r
+ cout << "create patterns for block " << qPrintable(name) << endl;\r
+ if (evaluator == NULL) evaluator = new ArithmeticEvaluator();\r
+ if (! isGeneratorBlock()) {\r
+ try {\r
+ createDelta();\r
+ createConsumptionPattern(); \r
+ createProductionCounter();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e); // rethrow e\r
+ }\r
+ }\r
+ try {\r
+ createProductionPattern();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ } \r
+}\r
+\r
+void FunctionalBlock::createDelta() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::createDelta()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif \r
+ \r
+ QString deltaStr = implementation->getDelta(); \r
+ cout << "delta for " << qPrintable(name) << " = " << qPrintable(deltaStr) << endl;\r
+ if (deltaStr.isEmpty()) {\r
+ delta = -1;\r
+ return;\r
+ }\r
+ \r
+ // look for parameter names \r
+ double result = 0;\r
+ try {\r
+ result = evaluateExpression(deltaStr);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ delta = result;\r
+ cout << "delta = " << delta << endl;\r
+}\r
+\r
+void FunctionalBlock::createConsumptionPattern() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::createConsumptionPattern()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ \r
+ lengthCP = -1; \r
+ QHash<QString,QString> consPattern = implementation->getConsumptionPattern(); \r
+ \r
+ foreach(AbstractInterface* iface, getControlInputs()) { \r
+ FunctionalInterface* connIface = AI_TO_FUN(iface);\r
+ QString refName = connIface->getReference()->getName(); \r
+ if (! consPattern.contains(refName)) {\r
+ throw(Exception(NO_IFACE_CP));\r
+ cerr << "no consumption pattern for reference interface " << qPrintable(refName) << endl;\r
+ }\r
+ QList<char>* pattern = NULL;\r
+ try {\r
+ pattern = expandPattern(consPattern.value(refName));\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ consumptionPattern.insert(connIface,pattern);\r
+ if (lengthCP == -1) {\r
+ lengthCP = pattern->size();\r
+ }\r
+ else {\r
+ if (pattern->size() != lengthCP) {\r
+ throw(Exception(INVALID_IFACE_CP_LENGTH));\r
+ }\r
+ }\r
+ } \r
+}\r
+\r
+void FunctionalBlock::createProductionPattern() throw(Exception){ \r
+ static QString fctName = "FunctionalBlock::createProductionPattern()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ \r
+ lengthPP = -1; \r
+ QHash<QString,QString> prodPattern = implementation->getProductionPattern(); \r
+ \r
+ foreach(AbstractInterface* iface, getControlOutputs()) { \r
+ FunctionalInterface* connIface = AI_TO_FUN(iface);\r
+ QString refName = connIface->getReference()->getName(); \r
+ if (! prodPattern.contains(refName)) {\r
+ throw(Exception(NO_IFACE_PP)); \r
+ }\r
+ QList<char>* pattern = NULL;\r
+ try {\r
+ pattern = expandPattern(prodPattern.value(refName));\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ productionPattern.insert(connIface,pattern);\r
+ if (lengthPP == -1) {\r
+ lengthPP = pattern->size();\r
+ }\r
+ else {\r
+ if (pattern->size() != lengthPP) {\r
+ throw(Exception(INVALID_IFACE_PP_LENGTH));\r
+ }\r
+ }\r
+ } \r
+}\r
+\r
+void FunctionalBlock::createProductionCounter() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::createProductionCounter()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ \r
+ QStringList counterParts = implementation->getProductionCounter().split(",");\r
+ foreach(QString s, counterParts) {\r
+ cout << "cont part = " << qPrintable(s) << endl;\r
+ bool ok;\r
+ double val = s.toDouble(&ok);\r
+ if (ok) {\r
+ productionCounter.append(val);\r
+ }\r
+ else if (s.at(0) == '{') {\r
+ s.remove(0,1);\r
+ s.chop(1);\r
+ QStringList gen = s.split(":");\r
+ if (gen.size() != 3) {\r
+ throw(Exception(INVALID_IFACE_PC));\r
+ }\r
+ int start = 0;\r
+ int nb = 0;\r
+ int step = 0;\r
+ for(int i=0;i<3;i++) { \r
+ double result = 0.0;\r
+ try {\r
+ result = evaluateExpression(gen.at(i));\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ if (i==0) start = result;\r
+ else if (i==1) nb = result;\r
+ else if (i==2) step = result;\r
+ }\r
+ for(int j=0;j<nb;j++) {\r
+ productionCounter.append(start+j*step);\r
+ }\r
+ }\r
+ else { \r
+ double result = 0.0;\r
+ try {\r
+ result = evaluateExpression(s);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ productionCounter.append(result); \r
+ }\r
+ }\r
+ foreach(int val, productionCounter) {\r
+ cout << val << ",";\r
+ }\r
+ cout << endl;\r
+}\r
+\r
+QList<char>* FunctionalBlock::expandPattern(const QString& patternIn) throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::expandPattern()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ \r
+ QList<char> lst;\r
+ QString p = patternIn;\r
+ p.append(')');\r
+ int offset = 0; \r
+ QList<char>* patternOut = new QList<char>();\r
+ try {\r
+ expandPatternRecur(p,&offset, patternOut); \r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+\r
+ return patternOut;\r