CMS 3D CMS Logo

GlobalLogicParser.h
Go to the documentation of this file.
1 #ifndef L1TGlobal_GlobalLogicParser_h
2 #define L1TGlobal_GlobalLogicParser_h
3 
4 // system include files
5 #include <string>
6 #include <vector>
7 #include <list>
8 #include <map>
9 
10 #include <iosfwd>
11 
12 // user include files
13 
14 // forward declarations
15 
16 // class declaration
18 {
19 
20 public:
21 
22  struct OperandToken
23  {
27  };
28 
32  OP_AND=4,
33  OP_OR=8,
34  OP_NOT=16,
38  OP_XOR=256
39  };
40 
41  struct TokenRPN
42  {
43  OperationType operation; // type of operation: AND, OR, NOT or OPERAND
44  std::string operand; // a possible operand
45  };
46 
47  typedef std::vector<TokenRPN> RpnVector;
48 
49 public:
50 
52 
55 
59  GlobalLogicParser(const RpnVector&, const std::vector<OperandToken>&);
60 
63  GlobalLogicParser(const std::string& logicalExpressionVal);
64 
65  // from a non-constant logical expression - add/remove spaces if needed
66  // numerical expression will be empty
67  GlobalLogicParser(std::string& logicalExpressionVal);
68 
70  GlobalLogicParser(const std::string logicalExpressionVal,
71  const std::string numericalExpressionVal);
72 
75  GlobalLogicParser(const std::string& logicalExpressionVal,
76  const std::string& numericalExpressionVal,
77  const bool dummy);
78 
80  virtual ~GlobalLogicParser();
81 
82 public:
83 
86 
89 
92 
93 public:
94 
96  bool buildRpnVector(const std::string&);
97 
99  void clearRpnVector();
100 
102  inline RpnVector rpnVector() const { return m_rpnVector; }
103 
107 
109  inline std::vector<OperandToken>& operandTokenVector() { return m_operandTokenVector; }
110  inline const std::vector<OperandToken>& operandTokenVector() const { return m_operandTokenVector; }
111 
112 public:
113 
115  int operandIndex(const std::string& operandNameVal) const;
116 
118  std::string operandName(const int iOperand) const;
119 
122  bool operandResult(const std::string& operandNameVal) const;
123 
126  bool operandResult(const int tokenNumberVal) const;
127 
130  virtual const bool expressionResult() const;
131 
134  bool operandResultNumExp(const std::string& operandNameVal) const;
135 
138  bool operandResultNumExp(const int iOperand) const;
139 
143 
146  virtual const bool expressionResultNumExp() const;
147 
152  const std::map<std::string, int>& nameToIntMap);
153 
156 
157  void convertIntToNameLogicalExpression(const std::map<int, std::string>& intToNameMap);
158 
161  std::vector<GlobalLogicParser::OperandToken> expressionSeedsOperandList();
162 
163 
164 protected:
165 
166 
168  {
169  const char* opString;
170  int opType;
171  int forbiddenLastOperation; // int for bitmask of forbidden operations
172  };
173 
174 
175  virtual OperationType getOperation(const std::string& tokenString,
176  OperationType lastOperation, TokenRPN& rpnToken) const;
177 
180 
181  static const struct OperationRule m_operationRules[];
182 
183 protected:
184 
187 
189  bool setLogicalExpression(const std::string&);
190 
194  bool setNumericalExpression(const std::string&);
195 
196 protected:
197 
200 
204 
206  RpnVector m_rpnVector;
207 
209  std::vector<OperandToken> m_operandTokenVector;
210 
211 
212 };
213 
214 #endif /*L1TGlobal_GtLogicParser_h*/
RpnVector m_rpnVector
RPN vector - equivalent to the logical expression.
virtual const bool expressionResult() const
const OperationRule * getRuleFromType(OperationType t)
get the rule entry to an operation type
std::vector< OperandToken > m_operandTokenVector
vector of operand tokens
RpnVector rpnVector() const
return the RPN vector
void buildOperandTokenVectorNumExp()
std::string logicalExpression() const
return the logical expression
virtual const bool expressionResultNumExp() const
bool setLogicalExpression(const std::string &)
set the logical expression - check for correctness the input string
std::string m_numericalExpression
std::vector< GlobalLogicParser::OperandToken > expressionSeedsOperandList()
void clearRpnVector()
clear possible old rpn vector
bool buildRpnVector(const std::string &)
build the rpn vector
std::string m_logicalExpression
logical expression to be parsed
int operandIndex(const std::string &operandNameVal) const
return the position index of the operand in the logical expression
void convertIntToNameLogicalExpression(const std::map< int, std::string > &intToNameMap)
std::vector< OperandToken > & operandTokenVector()
return the vector of operand tokens
void addBracketSpaces(const std::string &, std::string &)
add spaces before and after parantheses
const std::vector< OperandToken > & operandTokenVector() const
std::vector< TokenRPN > RpnVector
bool checkLogicalExpression(std::string &)
check a logical expression for correctness - add/remove spaces if needed
void convertNameToIntLogicalExpression(const std::map< std::string, int > &nameToIntMap)
bool operandResultNumExp(const std::string &operandNameVal) const
bool operandResult(const std::string &operandNameVal) const
GlobalLogicParser()
constructor(s)
virtual ~GlobalLogicParser()
destructor
static const struct OperationRule m_operationRules[]
std::string operandName(const int iOperand) const
return the name of the (iOperand)th operand in the logical expression
virtual OperationType getOperation(const std::string &tokenString, OperationType lastOperation, TokenRPN &rpnToken) const
std::string numericalExpression() const
return the numerical expression
bool setNumericalExpression(const std::string &)