1 #ifndef __FUNCTIONALBLOCK_H__
\r
2 #define __FUNCTIONALBLOCK_H__
\r
8 #include "AbstractBlock.h"
\r
10 class ReferenceBlock;
\r
12 #include "Exception.h"
\r
14 class BlockImplementation;
\r
15 class ArithmeticEvaluator;
\r
19 using namespace std;
\r
23 - NEVER forget to call populate() after creating an instance of GraphBlock.
\r
26 class FunctionalBlock : public AbstractBlock {
\r
29 FunctionalBlock(GroupBlock* _parent, ReferenceBlock* _reference) throw(Exception);
\r
32 inline ReferenceBlock* getReference() { return reference; }
\r
33 inline QList<int> getProductionCounter() { return productionCounter; }
\r
34 inline QMap<AbstractInterface*, QList<char>* > getConsumptionPattern() { return consumptionPattern; }
\r
35 inline QMap<AbstractInterface*, QList<char>* > getProductionPattern() { return productionPattern; }
\r
36 inline QMap<AbstractInterface*, QList<int>* > getAdmittanceDelays() { return admittanceDelays; }
\r
37 inline int getConsumptionPatternLength() { return lengthCP; }
\r
38 inline int getProductionPatternLength() { return lengthPP; }
\r
39 inline int getDelta() { return delta; }
\r
42 inline void setImplementation(BlockImplementation* impl) { implementation = impl; }
\r
43 inline void setProductionCounter(QList<int> pattern) { productionCounter = pattern; }
\r
44 inline void setDelta(int _delta) { delta = _delta; }
\r
48 bool isFunctionalBlock();
\r
49 bool isSourceBlock(); //! a source block has no parent and has no data inputs
\r
53 void populate(); // create parameters and interface from reference block
\r
54 void parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock*>* blocksToConfigure);
\r
56 QString getReferenceXmlFile();
\r
57 QString getReferenceHashMd5();
\r
60 void createPatterns() throw(Exception); // called in Graph, before checking compatibility and computing output pattern
\r
61 void checkInputPatternCompatibility() throw(Exception);
\r
62 void computeOutputPattern(int nbExec = -1) throw(Exception);
\r
63 void computeAdmittanceDelays() throw(Exception); // compute differences between IP and admittance
\r
67 void createDelta() throw(Exception);
\r
68 void createConsumptionPattern() throw(Exception); // initialize a QList<char> for each interface from patterns defined in implementation
\r
69 void createProductionPattern() throw(Exception); // initialize a QList<char> for each interface from patterns defined in implementation
\r
70 void createProductionCounter() throw(Exception); // initialize a QList<int> from counter defined in implementation
\r
71 void createAdmittance(int nbExec) throw(Exception); // initialize a QList<char> from consumption pattern and delta
\r
73 void clearConsumptionPattern();
\r
74 void clearProductionPattern();
\r
75 void createInputPattern() throw(Exception);
\r
76 void clearInputPattern();
\r
77 void clearAdmittanceDelays();
\r
78 int createTriggers(); // compute the clock cycle at which the block is triggered
\r
80 double evaluateExpression(const QString& expression) throw(Exception);
\r
81 QList<char>* expandPattern(const QString& patternIn) throw(Exception);
\r
82 QList<char> expandPatternRecur(const QString& patternIn, int* offset) throw(Exception);
\r
83 QString replaceExpressions(const QString& patternIn) throw(Exception);
\r
85 * \brief samePatterns
\r
86 * \param patternSrc the pattern that must be tested with patternDest (is patternDest == patternDest)
\r
87 * \param srcCol the column index within patternSrc
\r
88 * \param patternDest the pattern that must be tested with patternSrc
\r
89 * \param destCol the column index within patternDest
\r
90 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
91 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
93 bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
\r
94 bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, const QList<int>& srcCols, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
\r
96 * \brief canCombinePatterns
\r
97 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
98 * \param srcCol the column index within patternSrc
\r
99 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
100 * \param destCol the column index within patternDest
\r
101 * \return true if the combination is possible, and false else (e.g. when X1 must be combined with 11)
\r
102 * NB: if src/destCol are outside the range of the list, false is returned.
\r
104 bool canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
106 * \brief combinePatterns
\r
107 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
108 * \param srcCol the column index within patternSrc
\r
109 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
110 * \param destCol the column index within patternDest
\r
111 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
112 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
114 void combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
116 * \brief appendToPattern
\r
117 * \param patternSrc the pattern that must be appended to patternDest
\r
118 * \param srcCol the column index within patternSrc
\r
119 * \param patternDest the pattern that is modified by the append
\r
120 * \param nbCols the numer of columns to append
\r
121 * BEWARE: if nbCols is not consistent with the real length of src pattern, there may be less that nbCols
\r
122 * that will be appended
\r
124 void appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols);
\r
126 * \brief removeDataGroup
\r
127 * \param pattern the pattern for which a column is removed
\r
128 * \param offset the index of the column to remove
\r
130 void removeDataGroup(QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
132 * \brief isValidGroup
\r
133 * \param pattern the pattern to test
\r
134 * \param offset the column to test
\r
135 * isValidGroup checks if there is at least one 1 in the column offset of pattern.
\r
137 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
138 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, const QList<int> offsets);
\r
140 * \brief isOnlyXGroup
\r
141 * \param pattern the pattern to test
\r
142 * \param offset the column to test
\r
143 * isOnlyXGroup checks if there is only X in the column offset of pattern.
\r
145 bool isOnlyXDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
147 * \brief shifRightPattern
\r
148 * \param pattern the pattern to shift
\r
149 * \param offset the column where to shift
\r
150 * shiftRightPattern insert a null colmun in pattern, which leads to shift right the pattern at offset.
\r
151 * this method is used during admittance generation
\r
153 void shiftRightPattern(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
155 QMap<AbstractInterface*, QList<char>* > consumptionPattern;
\r
156 QMap<AbstractInterface*, QString > admittanceCyclic; // the admittance expressed as prologue-cyclic part-epilogue, deduced from admittance
\r
157 QMap<AbstractInterface*, QList<char>* > admittance; // the admittance taking into account nb exec.
\r
158 QMap<AbstractInterface*, QList<int>* > admittanceDelays; // the delay between what should be consumed and IP
\r
159 QMap<AbstractInterface*, QList<char>* > productionPattern;
\r
160 QMap<AbstractInterface*,QList<char>* > inputPattern;
\r
161 QMap<AbstractInterface*, QList<char>* > outputPattern; // CAUTION: the QList<char>* must also be stored in the outputPattern attributes of AbstractInterface
\r
162 QList<int> productionCounter; // only usefull for control output interfaces
\r
163 QList<int> triggers; // the clock cycles at which the block is triggered, taking into account IP
\r
164 int lengthIP; // for convenience, set in createInputPattern()
\r
165 int lengthCP; // for convenience, set in createConsumptionPattern()
\r
166 int lengthAP; // for convenience, set in createAdmittance()
\r
167 int lengthPP; // for convenience, set in createProductionPattern()
\r
168 int lengthOP; // for convenience, set in computeOutputPattern()
\r
171 ArithmeticEvaluator* evaluator;
\r
173 ReferenceBlock* reference;
\r
174 BlockImplementation* implementation;
\r
178 #endif // __FUNCTIONALBLOCK_H__
\r