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 bool createPatterns();
\r
61 bool createConsumptionPattern(); // initialize a QList<char> for each interface from patterns defined in implementation
\r
62 bool createProductionPattern(); // initialize a QList<char> for each interface from patterns defined in implementation
\r
63 bool createProductionCounter(); // initialize a QList<int> from counter defined in implementation
\r
64 bool createAdmittance(int nbExec); // initialize a QList<char> from consumption pattern and delta
\r
65 void clearConsumptionPattern();
\r
66 void clearProductionPattern();
\r
67 void createInputPattern();
\r
68 void clearInputPattern();
\r
69 int getNumberOfExecution(); // compute number of block execution from inputPattern and delta
\r
70 bool checkInputPatternCompatibility();
\r
71 bool computeOutputPattern(int nbExec = -1);
\r
75 double evaluateExpression(const QString& expression, bool* ok);
\r
76 QList<char>* expandPattern(const QString& patternIn, bool* ok);
\r
77 void expandPatternRecur(const QString& patternIn, int* offset, bool* ok, QList<char> *patternOut);
\r
79 * \brief canCombinePatterns
\r
80 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
81 * \param srcCol the column index within patternSrc
\r
82 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
83 * \param destCol the column index within patternDest
\r
84 * \return true if the combination is possible, and false else (e.g. when X1 must be combined with 11)
\r
85 * NB: if src/destCol are outside the range of the list, false is returned.
\r
87 bool canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
89 * \brief combinePatterns
\r
90 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
91 * \param srcCol the column index within patternSrc
\r
92 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
93 * \param destCol the column index within patternDest
\r
94 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
95 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
97 void combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
99 * \brief appendToPattern
\r
100 * \param patternSrc the pattern that must be appended to patternDest
\r
101 * \param srcCol the column index within patternSrc
\r
102 * \param patternDest the pattern that is modified by the append
\r
103 * \param nbCols the numer of columns to append
\r
104 * BEWARE: if nbCols is not consistent with the real length of src pattern, there may be less that nbCols
\r
105 * that will be appended
\r
107 void appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols);
\r
109 * \brief removeDataGroup
\r
110 * \param pattern the pattern for which a column is removed
\r
111 * \param offset the index of the column to remove
\r
113 void removeDataGroup(QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
115 * \brief isValidGroup
\r
116 * \param pattern the pattern to test
\r
117 * \param offset the column to test
\r
118 * isValidGroup checks if there is at least one 1 in the column offset of pattern.
\r
120 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
122 * \brief isOnlyXGroup
\r
123 * \param pattern the pattern to test
\r
124 * \param offset the column to test
\r
125 * isOnlyXGroup checks if there is only X in the column offset of pattern.
\r
127 bool isOnlyXDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
129 * \brief shifRightPattern
\r
130 * \param pattern the pattern to shift
\r
131 * \param offset the column where to shift
\r
132 * shiftRightPattern insert a null colmun in pattern, which leads to shift right the pattern at offset.
\r
133 * this method is used during admittance generation
\r
135 void shiftRightPattern(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
137 QMap<AbstractInterface*, QList<char>* > consumptionPattern;
\r
138 QMap<AbstractInterface*, QString > admittanceCyclic; // the admittance expressed as prologue-cyclic part-eppilogue, deduced from admittance
\r
139 QMap<AbstractInterface*, QList<char>* > admittance; // the admittance taking into account nb exec.
\r
140 QMap<AbstractInterface*, QList<char>* > productionPattern;
\r
141 QMap<AbstractInterface*,QList<char>* > inputPattern;
\r
142 QMap<AbstractInterface*, QList<char>* > outputPattern; // CAUTION: the QList<char>* must also be stored in the outputPattern attributes of AbstractInterface
\r
143 QList<int> productionCounter; //! only usefull for control output interfaces
\r
144 int lengthIP; // for convenience, set in createInputPattern()
\r
145 int lengthCP; // for convenience, set in createConsumptionPattern()
\r
146 int lengthAP; // for convenience, set in createAdmittance()
\r
147 int lengthPP; // for convenience, set in createProductionPattern()
\r
148 int lengthOP; // for convenience, set in computeOutputPattern()
\r
151 ArithmeticEvaluator* evaluator;
\r
153 ReferenceBlock* reference;
\r
154 BlockImplementation* implementation;
\r
158 #endif // __FUNCTIONALBLOCK_H__
\r