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 int getDelta() { return delta; }
\r
37 inline void setImplementation(BlockImplementation* impl) { implementation = impl; }
\r
38 inline void setProductionCounter(QList<int> pattern) { productionCounter = pattern; }
\r
39 inline void setDelta(int _delta) { delta = _delta; }
\r
43 bool isFunctionalBlock();
\r
44 bool isSourceBlock(); //! a source block has no parent and has no data inputs
\r
48 void populate(); // create parameters and interface from reference block
\r
49 void parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock*>* blocksToConfigure);
\r
51 QString getReferenceXmlFile();
\r
52 QString getReferenceHashMd5();
\r
55 bool createPatterns();
\r
57 bool createConsumptionPattern(); // initialize a QList<char> for each interface from patterns defined in implementation
\r
58 bool createProductionPattern(); // initialize a QList<char> for each interface from patterns defined in implementation
\r
59 bool createProductionCounter(); // initialize a QList<int> from counter defined in implementation
\r
60 void clearConsumptionPattern();
\r
61 void clearProductionPattern();
\r
62 bool computeOutputPattern(int nbExec = -1);
\r
66 double evaluateExpression(const QString& expression, bool* ok);
\r
67 QList<char>* expandPattern(const QString& patternIn, bool* ok);
\r
68 void expandPatternRecur(const QString& patternIn, int* offset, bool* ok, QList<char> *patternOut);
\r
70 * \brief canCombinePatterns
\r
71 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
72 * \param srcCol the column index within patternSrc
\r
73 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
74 * \param destCol the column index within patternDest
\r
75 * \return true if the combination is possible, and false else (e.g. when X1 must be combined with 11)
\r
76 * NB: if src/destCol are outside the range of the list, false is returned.
\r
78 bool canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
80 * \brief combinePatterns
\r
81 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
82 * \param srcCol the column index within patternSrc
\r
83 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR 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 void combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
90 * \brief appendToPattern
\r
91 * \param patternSrc the pattern that must be appended to patternDest
\r
92 * \param srcCol the column index within patternSrc
\r
93 * \param patternDest the pattern that is modified by the append
\r
94 * \param nbCols the numer of columns to append
\r
95 * BEWARE: if nbCols is not consistent with the real length of src pattern, there may be less that nbCols
\r
96 * that will be appended
\r
98 void appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols);
\r
100 * \brief removeDataGroup
\r
101 * \param pattern the pattern for which a column is removed
\r
102 * \param offset the index of the column to remove
\r
104 void removeDataGroup(QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
106 * \brief isValidGroup
\r
107 * \param pattern the pattern to test
\r
108 * \param offset the column to test
\r
109 * isValidGroup checks if there is at least one 1 in the column offset of pattern.
\r
111 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
113 * \brief isOnlyXGroup
\r
114 * \param pattern the pattern to test
\r
115 * \param offset the column to test
\r
116 * isOnlyXGroup checks if there is only X in the column offset of pattern.
\r
118 bool isOnlyXDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
120 * \brief shifRightPattern
\r
121 * \param pattern the pattern to shift
\r
122 * \param offset the column where to shift
\r
123 * shiftRightPattern insert a null colmun in pattern, which leads to shift right the pattern at offset.
\r
124 * this method is used during admittance generation
\r
126 void shiftRightPattern(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
128 QMap<AbstractInterface*, QList<char>* > consumptionPattern;
\r
129 QMap<AbstractInterface*, QString > admittance; // the admittance expressed as prologue-cyclic part-eppilogue
\r
130 QMap<AbstractInterface*, QList<char>* > admittanceExpanded; // the admittance expanded by taking into account nb exec.
\r
131 QMap<AbstractInterface*, QList<char>* > productionPattern;
\r
132 QMap<AbstractInterface*, QList<char>* > outputPattern; // CAUTION: the QList<char>* must also be stored in the outputPattern attributes of AbstractInterface
\r
133 QList<int> productionCounter; //! only usefull for control output interfaces
\r
137 ArithmeticEvaluator* evaluator;
\r
139 ReferenceBlock* reference;
\r
140 BlockImplementation* implementation;
\r
144 #endif // __FUNCTIONALBLOCK_H__
\r