File indexing completed on 2024-04-06 12:04:32
0001 #ifndef L1TGlobal_GlobalLogicParser_h
0002 #define L1TGlobal_GlobalLogicParser_h
0003
0004
0005 #include <string>
0006 #include <vector>
0007 #include <list>
0008 #include <map>
0009
0010 #include <iosfwd>
0011
0012
0013
0014
0015
0016
0017 class GlobalLogicParser {
0018 public:
0019 struct OperandToken {
0020 std::string tokenName;
0021 int tokenNumber;
0022 bool tokenResult;
0023 };
0024
0025 enum OperationType {
0026 OP_NULL = 1,
0027 OP_INVALID = 2,
0028 OP_AND = 4,
0029 OP_OR = 8,
0030 OP_NOT = 16,
0031 OP_OPERAND = 32,
0032 OP_OPENBRACKET = 64,
0033 OP_CLOSEBRACKET = 128,
0034 OP_XOR = 256
0035 };
0036
0037 struct TokenRPN {
0038 OperationType operation;
0039 std::string operand;
0040 };
0041
0042 typedef std::vector<TokenRPN> RpnVector;
0043
0044 public:
0045
0046
0047
0048 GlobalLogicParser();
0049
0050
0051
0052
0053 GlobalLogicParser(const RpnVector&, const std::vector<OperandToken>&);
0054
0055
0056
0057 GlobalLogicParser(const std::string& logicalExpressionVal);
0058
0059
0060
0061 GlobalLogicParser(std::string& logicalExpressionVal);
0062
0063
0064 GlobalLogicParser(const std::string logicalExpressionVal, const std::string numericalExpressionVal);
0065
0066
0067
0068 GlobalLogicParser(const std::string& logicalExpressionVal,
0069 const std::string& numericalExpressionVal,
0070 const bool dummy);
0071
0072
0073 virtual ~GlobalLogicParser();
0074
0075 public:
0076
0077 inline std::string logicalExpression() const { return m_logicalExpression; }
0078
0079
0080 bool checkLogicalExpression(std::string&);
0081
0082
0083 inline std::string numericalExpression() const { return m_numericalExpression; }
0084
0085 public:
0086
0087 bool buildRpnVector(const std::string&);
0088
0089
0090 void clearRpnVector();
0091
0092
0093 inline RpnVector rpnVector() const { return m_rpnVector; }
0094
0095
0096
0097 void buildOperandTokenVector();
0098
0099
0100 inline std::vector<OperandToken>& operandTokenVector() { return m_operandTokenVector; }
0101 inline const std::vector<OperandToken>& operandTokenVector() const { return m_operandTokenVector; }
0102
0103 public:
0104
0105 int operandIndex(const std::string& operandNameVal) const;
0106
0107
0108 std::string operandName(const int iOperand) const;
0109
0110
0111
0112 bool operandResult(const std::string& operandNameVal) const;
0113
0114
0115
0116 bool operandResult(const int tokenNumberVal) const;
0117
0118
0119
0120 virtual const bool expressionResult() const;
0121
0122
0123
0124 bool operandResultNumExp(const std::string& operandNameVal) const;
0125
0126
0127
0128 bool operandResultNumExp(const int iOperand) const;
0129
0130
0131
0132 void buildOperandTokenVectorNumExp();
0133
0134
0135
0136 virtual const bool expressionResultNumExp() const;
0137
0138
0139
0140
0141 void convertNameToIntLogicalExpression(const std::map<std::string, int>& nameToIntMap);
0142
0143
0144
0145
0146 void convertIntToNameLogicalExpression(const std::map<int, std::string>& intToNameMap);
0147
0148
0149
0150 std::vector<GlobalLogicParser::OperandToken> expressionSeedsOperandList();
0151
0152 protected:
0153 struct OperationRule {
0154 const char* opString;
0155 int opType;
0156 int forbiddenLastOperation;
0157 };
0158
0159 virtual OperationType getOperation(const std::string& tokenString,
0160 OperationType lastOperation,
0161 TokenRPN& rpnToken) const;
0162
0163
0164 const OperationRule* getRuleFromType(OperationType t);
0165
0166 static const struct OperationRule m_operationRules[];
0167
0168 protected:
0169
0170 void addBracketSpaces(const std::string&, std::string&);
0171
0172
0173 bool setLogicalExpression(const std::string&);
0174
0175
0176
0177
0178 bool setNumericalExpression(const std::string&);
0179
0180 protected:
0181
0182 std::string m_logicalExpression;
0183
0184
0185
0186 std::string m_numericalExpression;
0187
0188
0189 RpnVector m_rpnVector;
0190
0191
0192 std::vector<OperandToken> m_operandTokenVector;
0193 };
0194
0195 #endif