BlockParameter* getParameterFromName(QString name);\r
\r
// patterns\r
+ virtual bool checkInputPatternCompatibility() = 0;\r
virtual bool computeOutputPattern(int nbExec = -1) = 0;\r
\r
protected:\r
else {\r
implementation = reference->getImplementations().at(0);\r
}\r
+ lengthAP = -1;\r
+ lengthCP = -1;\r
+ lengthIP = -1;\r
+ lengthOP = -1;\r
+ lengthPP = -1;\r
+ delta = -1;\r
}\r
\r
\r
}\r
\r
void FunctionalBlock::createInputPattern() {\r
+ static QString fctName = "FunctionalBlock::createInputPattern())";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ \r
lengthIP = -1;\r
foreach(AbstractInterface* iface, getControlInputs()) { \r
ConnectedInterface* connIface = AI_TO_CON(iface);\r
}\r
}\r
}\r
- \r
+ // turn all X into 0\r
+ QMapIterator<AbstractInterface*,QList<char>* > iterA(admittance);\r
+ while (iterA.hasNext()) {\r
+ iterA.next();\r
+ QList<char>* pattern = iterA.value();\r
+ for(int i=0;i<pattern->size();i++) {\r
+ if (pattern->at(i) == -1) pattern->replace(i,0);\r
+ }\r
+ }\r
return true;\r
}\r
\r
ok = createAdmittance(nbExec);\r
if (!ok) return false;\r
\r
+ int clock = 0; // index in IP \r
+ int i = 0; // index in AP\r
+ while (clock < lengthIP) {\r
+ if (samePatterns(inputPattern,clock,admittance,i)) {\r
+ clock++;\r
+ i++;\r
+ }\r
+ else {\r
+ if (isValidDataGroup(admittance,i)) {\r
+ \r
+ }\r
+ else {\r
+ // IP and AP are not equal and AP is a valid group -> not compatible\r
+ return false;\r
+ }\r
+ \r
+ } \r
+ }\r
return true;\r
}\r
\r
return true;\r
}\r
\r
+bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {\r
+ \r
+ if (patternSrc.size() != patternDest.size()) return false;\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);\r
+ QMapIterator<AbstractInterface*, QList<char>* > iterDest(patternDest);\r
+ while (iterSrc.hasNext()) {\r
+ iterSrc.next();\r
+ iterDest.next(); \r
+ QList<char>* srcPat = iterSrc.value();\r
+ QList<char>* destPat = iterDest.value();\r
+ if (srcCol >= srcPat->size()) return false;\r
+ if (destCol >= destPat->size()) return false;\r
+ if (srcPat->at(srcCol) != destPat->at(destCol)) return false; \r
+ }\r
+ return true;\r
+}\r
+\r
bool FunctionalBlock::canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol) {\r
if (patternSrc.size() != patternDest.size()) return false;\r
QMapIterator<AbstractInterface*, QList<char>* > iterSrc(patternSrc);\r
QString getReferenceHashMd5();\r
\r
// patterns\r
- bool createPatterns();\r
+ bool createPatterns(); // called in Graph, before checking compatibility and computing output pattern\r
+ bool checkInputPatternCompatibility();\r
+ bool computeOutputPattern(int nbExec = -1);\r
+ \r
+private: \r
+ // patterns\r
bool createDelta();\r
bool createConsumptionPattern(); // initialize a QList<char> for each interface from patterns defined in implementation\r
bool createProductionPattern(); // initialize a QList<char> for each interface from patterns defined in implementation\r
void createInputPattern();\r
void clearInputPattern();\r
int getNumberOfExecution(); // compute number of block execution from inputPattern and delta\r
- bool checkInputPatternCompatibility();\r
- bool computeOutputPattern(int nbExec = -1);\r
\r
-private: \r
- // patterns \r
double evaluateExpression(const QString& expression, bool* ok);\r
QList<char>* expandPattern(const QString& patternIn, bool* ok);\r
void expandPatternRecur(const QString& patternIn, int* offset, bool* ok, QList<char> *patternOut);\r
+ /*!\r
+ * \brief samePatterns\r
+ * \param patternSrc the pattern that must be tested with patternDest (is patternDest == patternDest) \r
+ * \param srcCol the column index within patternSrc\r
+ * \param patternDest the pattern that must be tested with patternSrc\r
+ * \param destCol the column index within patternDest \r
+ * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)\r
+ leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.\r
+ */\r
+ bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);\r
/*!\r
* \brief canCombinePatterns\r
* \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc) \r
if (p != NULL) params.removeAll(p);
}
-void GroupBlock::initInputPattern() {
+void GroupBlock::createInputPattern() {
foreach(AbstractInterface* iface, getControlInputs()) {
ConnectedInterface* connIface = AI_TO_CON(iface);
QList<char>* pattern = new QList<char>(*(connIface->getConnectedFrom()->getOutputPattern()));
}
}
+bool GroupBlock::checkInputPatternCompatibility() {
+ return true;
+}
+
bool GroupBlock::computeOutputPattern(int nbExec) {
static QString fctName = "GroupBlock::computeOutputPattern()";
cout << "computing output pattern of group " << qPrintable(name) << endl;
bool canCompute = true;
+ bool compatible = true;
// get the input pattern on each inputs
- initInputPattern();
+ createInputPattern();
cout << "Input pattern OK" << endl;
// find blocks that are connected to that inputs and generators
while (!fifo.isEmpty()) {
AbstractBlock* block = fifo.takeFirst();
- if (block->getPatternComputed()) continue; // block has laready been processed
-
+ if (block->getPatternComputed()) continue; // block has already been processed
+
+ compatible = block->checkInputPatternCompatibility();
+ if (!compatible) {
+ cout << qPrintable(block->getName()) << " is not compatible with his input pattern" << endl;
+ break;
+ }
canCompute = block->computeOutputPattern();
if (!canCompute) {
cout << "cannot finalize output pattern computation of " << qPrintable(block->getName()) << endl;
// public attributes
static int counter;
+ bool checkInputPatternCompatibility();
bool computeOutputPattern(int nbExec = -1);
private:
*/
/*!
- * \brief initInputPattern
+ * \brief createInputPattern
* Since input GroupInterface are just tunnels to input interfaces of inner blocks, they must
* have an output pattern that can be provided to inner interfaces. That outpu pattern is just
* found by taking the output pattern of the connectedFrom interface.
*/
- void initInputPattern();
+ void createInputPattern();
bool topGroup;
return in;
}
+bool ReferenceBlock::checkInputPatternCompatibility() {
+ return false;
+}
+
bool ReferenceBlock::computeOutputPattern(int nbExec) {
// does strictly nothing
return false;
private:
// patterns
+ bool checkInputPatternCompatibility();
bool computeOutputPattern(int nbExec = -1);
};
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 3.2.1, 2017-05-19T16:37:01. -->
+<!-- Written by QtCreator 3.2.1, 2017-05-22T09:28:13. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>