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 clearOutputPattern();
\r
78 void clearAdmittanceDelays();
\r
79 int createTriggers(); // compute the clock cycle at which the block is triggered
\r
81 double evaluateExpression(const QString& expression) throw(Exception);
\r
82 QList<char>* expandPattern(const QString& patternIn) throw(Exception);
\r
83 QList<char> expandPatternRecur(const QString& patternIn, int* offset) throw(Exception);
\r
84 QString replaceExpressions(const QString& patternIn) throw(Exception);
\r
86 * \brief samePatterns
\r
87 * \param patternSrc the pattern that must be tested with patternDest (is patternDest == patternDest)
\r
88 * \param srcCol the column index within patternSrc
\r
89 * \param patternDest the pattern that must be tested with patternSrc
\r
90 * \param destCol the column index within patternDest
\r
91 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
92 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
94 bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
\r
95 bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, const QList<int>& srcCols, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
\r
97 * \brief canCombinePatterns
\r
98 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
99 * \param srcCol the column index within patternSrc
\r
100 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
101 * \param destCol the column index within patternDest
\r
102 * \return true if the combination is possible, and false else (e.g. when X1 must be combined with 11)
\r
103 * NB: if src/destCol are outside the range of the list, false is returned.
\r
105 bool canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
107 * \brief combinePatterns
\r
108 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
109 * \param srcCol the column index within patternSrc
\r
110 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
111 * \param destCol the column index within patternDest
\r
112 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
113 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
115 void combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
117 * \brief appendToPattern
\r
118 * \param patternSrc the pattern that must be appended to patternDest
\r
119 * \param srcCol the column index within patternSrc
\r
120 * \param patternDest the pattern that is modified by the append
\r
121 * \param nbCols the numer of columns to append
\r
122 * BEWARE: if nbCols is not consistent with the real length of src pattern, there may be less that nbCols
\r
123 * that will be appended
\r
125 void appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols);
\r
127 * \brief removeDataGroup
\r
128 * \param pattern the pattern for which a column is removed
\r
129 * \param offset the index of the column to remove
\r
131 void removeDataGroup(QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
133 * \brief isValidGroup
\r
134 * \param pattern the pattern to test
\r
135 * \param offset the column to test
\r
136 * isValidGroup checks if there is at least one 1 in the column offset of pattern.
\r
138 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
139 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, const QList<int> offsets);
\r
141 * \brief isOnlyXGroup
\r
142 * \param pattern the pattern to test
\r
143 * \param offset the column to test
\r
144 * isOnlyXGroup checks if there is only X in the column offset of pattern.
\r
146 bool isOnlyXDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
148 * \brief shifRightPattern
\r
149 * \param pattern the pattern to shift
\r
150 * \param offset the column where to shift
\r
151 * shiftRightPattern insert a null colmun in pattern, which leads to shift right the pattern at offset.
\r
152 * this method is used during admittance generation
\r
154 void shiftRightPattern(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
156 QMap<AbstractInterface*, QList<char>* > consumptionPattern;
\r
157 QMap<AbstractInterface*, QString > admittanceCyclic; // the admittance expressed as prologue-cyclic part-epilogue, deduced from admittance
\r
158 QMap<AbstractInterface*, QList<char>* > admittance; // the admittance taking into account nb exec.
\r
159 QMap<AbstractInterface*, QList<int>* > admittanceDelays; // the delay between what should be consumed and IP
\r
160 QMap<AbstractInterface*, QList<char>* > productionPattern;
\r
161 QMap<AbstractInterface*,QList<char>* > inputPattern;
\r
162 QMap<AbstractInterface*, QList<char>* > outputPattern; // CAUTION: the QList<char>* must also be stored in the outputPattern attributes of AbstractInterface
\r
163 QList<int> productionCounter; // only usefull for control output interfaces
\r
164 QList<int> triggers; // the clock cycles at which the block is triggered, taking into account IP
\r
165 int lengthIP; // for convenience, set in createInputPattern()
\r
166 int lengthCP; // for convenience, set in createConsumptionPattern()
\r
167 int lengthAP; // for convenience, set in createAdmittance()
\r
168 int lengthPP; // for convenience, set in createProductionPattern()
\r
169 int lengthOP; // for convenience, set in computeOutputPattern()
\r
172 ArithmeticEvaluator* evaluator;
\r
174 ReferenceBlock* reference;
\r
175 BlockImplementation* implementation;
\r
179 #endif // __FUNCTIONALBLOCK_H__
\r