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 int getConsumptionPatternLength() { return lengthCP; }
\r
37 inline int getProductionPatternLength() { return lengthPP; }
\r
38 inline int getDelta() { return delta; }
\r
41 inline void setImplementation(BlockImplementation* impl) { implementation = impl; }
\r
42 inline void setProductionCounter(QList<int> pattern) { productionCounter = pattern; }
\r
43 inline void setDelta(int _delta) { delta = _delta; }
\r
47 bool isFunctionalBlock();
\r
48 bool isSourceBlock(); //! a source block has no parent and has no data inputs
\r
52 void populate(); // create parameters and interface from reference block
\r
53 void parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock*>* blocksToConfigure);
\r
55 QString getReferenceXmlFile();
\r
56 QString getReferenceHashMd5();
\r
59 void createPatterns() throw(Exception); // called in Graph, before checking compatibility and computing output pattern
\r
60 void checkInputPatternCompatibility() throw(Exception);
\r
61 void computeOutputPattern(int nbExec = -1) throw(Exception);
\r
65 void createDelta() throw(Exception);
\r
66 void createConsumptionPattern() throw(Exception); // initialize a QList<char> for each interface from patterns defined in implementation
\r
67 void createProductionPattern() throw(Exception); // initialize a QList<char> for each interface from patterns defined in implementation
\r
68 void createProductionCounter() throw(Exception); // initialize a QList<int> from counter defined in implementation
\r
69 void createAdmittance(int nbExec) throw(Exception); // initialize a QList<char> from consumption pattern and delta
\r
70 void clearConsumptionPattern();
\r
71 void clearProductionPattern();
\r
72 void createInputPattern() throw(Exception);
\r
73 void clearInputPattern();
\r
74 int createTriggers(); // compute the clock cycle at which the block is triggered
\r
76 double evaluateExpression(const QString& expression) throw(Exception);
\r
77 QList<char>* expandPattern(const QString& patternIn) throw(Exception);
\r
78 void expandPatternRecur(const QString& patternIn, int* offset, QList<char> *patternOut) throw(Exception);
\r
80 * \brief samePatterns
\r
81 * \param patternSrc the pattern that must be tested with patternDest (is patternDest == patternDest)
\r
82 * \param srcCol the column index within patternSrc
\r
83 * \param patternDest the pattern that must be tested with patternSrc
\r
84 * \param destCol the column index within patternDest
\r
85 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
86 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
88 bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
\r
90 * \brief canCombinePatterns
\r
91 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
92 * \param srcCol the column index within patternSrc
\r
93 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
94 * \param destCol the column index within patternDest
\r
95 * \return true if the combination is possible, and false else (e.g. when X1 must be combined with 11)
\r
96 * NB: if src/destCol are outside the range of the list, false is returned.
\r
98 bool canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
100 * \brief combinePatterns
\r
101 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
102 * \param srcCol the column index within patternSrc
\r
103 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
104 * \param destCol the column index within patternDest
\r
105 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
106 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
108 void combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
110 * \brief appendToPattern
\r
111 * \param patternSrc the pattern that must be appended to patternDest
\r
112 * \param srcCol the column index within patternSrc
\r
113 * \param patternDest the pattern that is modified by the append
\r
114 * \param nbCols the numer of columns to append
\r
115 * BEWARE: if nbCols is not consistent with the real length of src pattern, there may be less that nbCols
\r
116 * that will be appended
\r
118 void appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols);
\r
120 * \brief removeDataGroup
\r
121 * \param pattern the pattern for which a column is removed
\r
122 * \param offset the index of the column to remove
\r
124 void removeDataGroup(QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
126 * \brief isValidGroup
\r
127 * \param pattern the pattern to test
\r
128 * \param offset the column to test
\r
129 * isValidGroup checks if there is at least one 1 in the column offset of pattern.
\r
131 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
133 * \brief isOnlyXGroup
\r
134 * \param pattern the pattern to test
\r
135 * \param offset the column to test
\r
136 * isOnlyXGroup checks if there is only X in the column offset of pattern.
\r
138 bool isOnlyXDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
140 * \brief shifRightPattern
\r
141 * \param pattern the pattern to shift
\r
142 * \param offset the column where to shift
\r
143 * shiftRightPattern insert a null colmun in pattern, which leads to shift right the pattern at offset.
\r
144 * this method is used during admittance generation
\r
146 void shiftRightPattern(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
148 QMap<AbstractInterface*, QList<char>* > consumptionPattern;
\r
149 QMap<AbstractInterface*, QString > admittanceCyclic; // the admittance expressed as prologue-cyclic part-eppilogue, deduced from admittance
\r
150 QMap<AbstractInterface*, QList<char>* > admittance; // the admittance taking into account nb exec.
\r
151 QMap<AbstractInterface*, QList<char>* > productionPattern;
\r
152 QMap<AbstractInterface*,QList<char>* > inputPattern;
\r
153 QMap<AbstractInterface*, QList<char>* > outputPattern; // CAUTION: the QList<char>* must also be stored in the outputPattern attributes of AbstractInterface
\r
154 QList<int> productionCounter; // only usefull for control output interfaces
\r
155 QList<int> triggers; // the clock cycles at which the block is triggered, taking into account IP
\r
156 int lengthIP; // for convenience, set in createInputPattern()
\r
157 int lengthCP; // for convenience, set in createConsumptionPattern()
\r
158 int lengthAP; // for convenience, set in createAdmittance()
\r
159 int lengthPP; // for convenience, set in createProductionPattern()
\r
160 int lengthOP; // for convenience, set in computeOutputPattern()
\r
163 ArithmeticEvaluator* evaluator;
\r
165 ReferenceBlock* reference;
\r
166 BlockImplementation* implementation;
\r
170 #endif // __FUNCTIONALBLOCK_H__
\r