lengthOP = -1;\r
lengthPP = -1;\r
delta = -1;\r
+ evaluator = NULL;\r
}\r
\r
+FunctionalBlock::~FunctionalBlock() {\r
+ if (evaluator != NULL) delete evaluator;\r
+}\r
\r
void FunctionalBlock::parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {\r
/*\r
return ((ReferenceBlock *)reference)->getHashMd5();\r
}\r
\r
-bool FunctionalBlock::createPatterns() {\r
+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
- evaluator = new ArithmeticEvaluator();\r
- bool ok = true; \r
+ if (evaluator == NULL) evaluator = new ArithmeticEvaluator();\r
if (! isGeneratorBlock()) {\r
- ok = ok & createDelta();\r
- if (ok) ok = ok & createConsumptionPattern(); \r
- if (ok) ok = ok & createProductionCounter();\r
+ try {\r
+ createDelta();\r
+ createConsumptionPattern(); \r
+ createProductionCounter();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e); // rethrow e\r
+ }\r
}\r
- if (ok) ok = ok & createProductionPattern();\r
- delete evaluator;\r
- return ok;\r
+ try {\r
+ createProductionPattern();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ } \r
}\r
\r
-bool FunctionalBlock::createDelta() {\r
+void FunctionalBlock::createDelta() throw(Exception) {\r
static QString fctName = "FunctionalBlock::createDelta()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
cout << "delta for " << qPrintable(name) << " = " << qPrintable(deltaStr) << endl;\r
if (deltaStr.isEmpty()) {\r
delta = -1;\r
- return true;\r
+ return;\r
}\r
\r
- // look for parameter names\r
- bool ok = true;\r
- double result = evaluateExpression(deltaStr, &ok);\r
- if (!ok) return false;\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
- return true;\r
}\r
\r
-bool FunctionalBlock::createConsumptionPattern() {\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
- bool ok = true; \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
- return false;\r
}\r
- QList<char>* pattern = expandPattern(consPattern.value(refName),&ok); \r
- if (!ok) return false;\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) return false;\r
+ if (pattern->size() != lengthCP) {\r
+ throw(Exception(INVALID_IFACE_CP_LENGTH));\r
+ }\r
}\r
- } \r
- return true;\r
+ } \r
}\r
\r
-bool FunctionalBlock::createProductionPattern() { \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
- bool ok = true; \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
- cerr << "no production pattern for reference interface " << qPrintable(refName) << endl;\r
- return false;\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
- QList<char>* pattern = expandPattern(prodPattern.value(refName),&ok);\r
- if (!ok) return false;\r
productionPattern.insert(connIface,pattern);\r
if (lengthPP == -1) {\r
lengthPP = pattern->size();\r
}\r
else {\r
- if (pattern->size() != lengthPP) return false;\r
+ if (pattern->size() != lengthPP) {\r
+ throw(Exception(INVALID_IFACE_PP_LENGTH));\r
+ }\r
}\r
- } \r
- return true;\r
+ } \r
}\r
\r
-bool FunctionalBlock::createProductionCounter() {\r
+void FunctionalBlock::createProductionCounter() throw(Exception) {\r
static QString fctName = "FunctionalBlock::createProductionCounter()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
s.remove(0,1);\r
s.chop(1);\r
QStringList gen = s.split(":");\r
- if (gen.size() != 3) return false;\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
- bool okVal;\r
- double result = evaluateExpression(gen.at(i),&okVal);\r
- if (!okVal) return false;\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
productionCounter.append(start+j*step);\r
}\r
}\r
- else {\r
- bool okVal;\r
- double result = evaluateExpression(s,&okVal);\r
- \r
- if (!okVal) return false;\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
cout << val << ",";\r
}\r
cout << endl;\r
- \r
- return true;\r
}\r
\r
-QList<char>* FunctionalBlock::expandPattern(const QString& patternIn, bool* ok) {\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
QList<char> lst;\r
QString p = patternIn;\r
p.append(')');\r
- int offset = 0;\r
+ int offset = 0; \r
QList<char>* patternOut = new QList<char>();\r
- expandPatternRecur(p,&offset,ok,patternOut); \r
+ try {\r
+ expandPatternRecur(p,&offset, patternOut); \r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+\r
return patternOut;\r
}\r
\r
-void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, bool *ok, QList<char>* patternOut) { \r
+void FunctionalBlock::expandPatternRecur(const QString& patternIn, int *offset, QList<char>* patternOut) throw(Exception) { \r
\r
while ((*offset < patternIn.size()) && (patternIn.at(*offset) != ')')) {\r
\r
QChar c = patternIn.at(*offset);\r
if (c == '(') {\r
*offset += 1;\r
- expandPatternRecur(patternIn,offset, ok, patternOut);\r
- if (!ok) {\r
- return;\r
+ try {\r
+ expandPatternRecur(patternIn,offset, patternOut);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
}\r
}\r
else if (c == '0') {\r
*offset += 1;\r
}\r
if (*offset == patternIn.size()) {\r
- *ok = false;\r
- return;\r
+ throw(Exception(INVALID_IFACE_PATTERN));\r
+ }\r
+ double repeat = 0;\r
+ try {\r
+ repeat = evaluateExpression(expr);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
}\r
- double repeat = evaluateExpression(expr,ok);\r
- if (!ok) {\r
- return; \r
- } \r
// repeat just the last value in currentGroup\r
char last = patternOut->last(); \r
//cout << "repeat last char " << repeat << " times : " << (int)last << endl;\r
*offset += 1;\r
}\r
if (*offset == patternIn.size()) {\r
- *ok = false;\r
- return;\r
+ throw(Exception(INVALID_IFACE_PATTERN));\r
}\r
- double repeat = evaluateExpression(expr,ok);\r
- if (!ok) {\r
- return; \r
+ double repeat = 0;\r
+ try {\r
+ repeat = evaluateExpression(expr);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
}\r
/*\r
cout << "repeat last group " << repeat << " times : ";\r
for(int i=1;i<(int)repeat;i++) {\r
patternOut->append(single);\r
} \r
- }\r
- //*offset += 1;\r
- return;\r
+ } \r
}\r
\r
-double FunctionalBlock::evaluateExpression(const QString& expression, bool* ok) {\r
+double FunctionalBlock::evaluateExpression(const QString& expression) throw(Exception) {\r
static QString fctName = "FunctionalBlock::evaluateExpression()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
- \r
- *ok = true;\r
+ \r
QHash<QString,double> vars;\r
evaluator->setExpression(expression);\r
QList<QString> varNames = evaluator->getVariableNames();\r
paramName.remove(0,1);\r
BlockParameter* param = reference->getParameterFromName(paramName); \r
if (param == NULL) {\r
- cerr << "found an unknown parameter in delta"<< endl;\r
- *ok = false;\r
- return 0.0;\r
+ throw(Exception(EVAL_PARAM_UNKNOWN));\r
}\r
bool okVal;\r
int val = param->getDoubleValue(&okVal);\r
if (!okVal) {\r
- cerr << "cannot obtain double value of paramter " << qPrintable(paramName) << endl;\r
- *ok = false;\r
- return 0.0;\r
+ throw(Exception(EVAL_PARAM_NOVALUE)); \r
}\r
vars.insert(name,(double)val); \r
}\r
\r
evaluator->setVariablesValue(vars);\r
- double result;\r
+ double result = 0.0;\r
try {\r
result = evaluator->evaluate();\r
}\r
catch(int index) {\r
cerr << "Error at index " << index << ": " << qPrintable(evaluator->getError()) << endl;\r
- *ok = false;\r
- return 0.0;\r
+ throw(Exception(EVAL_INVALID_EXPR));\r
}\r
return result;\r
}\r
\r
-void FunctionalBlock::createInputPattern() {\r
+void FunctionalBlock::createInputPattern() throw(Exception) {\r
static QString fctName = "FunctionalBlock::createInputPattern())";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
foreach(AbstractInterface* iface, getControlInputs()) { \r
ConnectedInterface* connIface = AI_TO_CON(iface);\r
QList<char>* out = connIface->getConnectedFrom()->getOutputPattern();\r
+ if (out->size() == 0) {\r
+ clearInputPattern();\r
+ throw(Exception(NO_IFACE_IP));\r
+ }\r
if (lengthIP == -1) {\r
lengthIP = out->size();\r
}\r
else {\r
if (out->size() < lengthIP) lengthIP = out->size();\r
}\r
- if (out->size() > 0) {\r
- QList<char>* in = new QList<char>(*out);\r
- foreach(char c, *in) {\r
- cout << (int)c;\r
- }\r
- cout << endl;\r
-\r
- inputPattern.insert(connIface,in);\r
+ \r
+ QList<char>* in = new QList<char>(*out);\r
+ foreach(char c, *in) {\r
+ cout << (int)c;\r
}\r
- else {\r
- inputPattern.insert(connIface,NULL);\r
- } \r
+ cout << endl; \r
+ inputPattern.insert(connIface,in); \r
}\r
- // remove null columns at the end of IP\r
+ // search the last valid group in IP,\r
while(! isValidDataGroup(inputPattern,lengthIP-1)) {\r
- removeDataGroup(inputPattern,lengthIP-1);\r
+ //removeDataGroup(inputPattern,lengthIP-1);\r
lengthIP -= 1;\r
}\r
}\r
\r
-bool FunctionalBlock::createAdmittance(int nbExec) {\r
+void FunctionalBlock::createAdmittance(int nbExec) throw(Exception) {\r
static QString fctName = "FunctionalBlock::createAdmittance()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
-#endif\r
- bool ok = true;\r
+#endif \r
// firstly, copy CP in AP\r
QMapIterator<AbstractInterface*,QList<char>* > iterC(consumptionPattern);\r
while (iterC.hasNext()) {\r
j -= 1;\r
}\r
else {\r
- cout << "AP and CP are not consistent" << endl;\r
- return false;\r
+ throw(INVALID_DELTA_CP); \r
}\r
}\r
}\r
cout << (int)(pattern->at(i));\r
}\r
cout << endl;\r
- }\r
- return true;\r
+ } \r
}\r
\r
-bool FunctionalBlock::checkInputPatternCompatibility() {\r
+void FunctionalBlock::checkInputPatternCompatibility() throw(Exception) {\r
static QString fctName = "FunctionalBlock::checkInputPatternCompatibility()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
#endif\r
- \r
- bool ok = true;\r
+ \r
// firstly, create input pattern\r
- createInputPattern(); \r
- // if some patterns are not available, end now, returning false\r
- if (lengthIP == 0) {\r
- clearInputPattern();\r
- return false;\r
+ try {\r
+ createInputPattern();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
}\r
- int nbExec = getNumberOfExecution();\r
+ int nbExec = createTriggers();\r
cout << qPrintable(name) << " will exec. " << nbExec << " times." << endl;\r
\r
- ok = createAdmittance(nbExec);\r
- \r
- if (!ok) {\r
+ try {\r
+ createAdmittance(nbExec);\r
+ }\r
+ catch(Exception e) {\r
cout << "cannot create admittance" << endl;\r
- return false;\r
+ throw(e);\r
}\r
\r
int clock = 0; // index in IP \r
while ((clock < lengthIP) && (! isValidDataGroup(inputPattern,clock))) clock++;\r
if (clock == lengthIP) {\r
cerr << "Abnormal case: end of IP has been reached without finding a valid group" << endl;\r
- return false;\r
+ throw(Exception(IP_END_NULLCOL)); \r
}\r
} \r
/* at that point 2 cases of compat : IP(clock) and AP(i) are equal valid group, or\r
*/\r
if (! samePatterns(inputPattern,clock,admittance,i)) {\r
cout << "AP(" << i << ") and IP(" << clock << ") are not equal" << endl;\r
- return false;\r
+ throw(Exception(IP_AP_NOTCOMPAT)); // IP and AP not compatible\r
}\r
clock++;\r
i++;\r
}\r
if (clock < lengthIP) {\r
- cerr << "Abnormal case: AP is to short" << endl;\r
- return false;\r
- }\r
- return true;\r
+ throw(Exception(AP_TOO_SHORT));\r
+ cerr << "Abnormal case: AP is to short" << endl; \r
+ } \r
}\r
\r
-bool FunctionalBlock::computeOutputPattern(int nbExec) {\r
+void FunctionalBlock::computeOutputPattern(int nbExec) throw(Exception) {\r
static QString fctName = "FunctionalBlock::computeOutputPattern()";\r
#ifdef DEBUG_FCTNAME\r
cout << "call to " << qPrintable(fctName) << endl;\r
// in case of inputPattern not created, do it\r
if (lengthIP <= 0) {\r
// collect the input patterns for each input \r
- createInputPattern(); \r
- // if some patterns are not available, end now, returning false\r
- if (lengthIP == 0) {\r
- clearInputPattern();\r
- return false;\r
+ try {\r
+ createInputPattern();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
}\r
cout << "input pattern array initialized with min. len " << lengthIP << endl;\r
}\r
\r
// clear input pattern\r
clearInputPattern();\r
- }\r
- return true;\r
+ } \r
}\r
\r
bool FunctionalBlock::samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol) {\r
lengthIP = -1;\r
}\r
\r
-int FunctionalBlock::getNumberOfExecution() {\r
+int FunctionalBlock::createTriggers() {\r
+ triggers.clear();\r
/* NB: this method returns the number of executions that have been started\r
but not necessary completed.\r
*/\r
- if (delta <= 0) return 0;\r
- int nbExec = 0;\r
+ if (delta <= 0) return 0; \r
int offset = 0;\r
// search for the first exec.\r
while ((offset < lengthIP) && (! isValidDataGroup(inputPattern,offset))) offset++;\r
if (offset == lengthIP) return 0;\r
- nbExec = 1;\r
+ triggers.append(offset); \r
int nbGroup = 0;\r
for(int i = offset;i<lengthIP;i++) {\r
if (isValidDataGroup(inputPattern,i)) nbGroup++;\r
if (nbGroup == delta+1) {\r
- nbExec += 1;\r
+ triggers.append(i);\r
nbGroup = 1;\r
}\r
} \r
- return nbExec; \r
+ return triggers.size();\r
}\r