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  };
39 
40  struct TokenRPN
41  {
42  OperationType operation; // type of operation: AND, OR, NOT or OPERAND
43  std::string operand; // a possible operand
44  };
45 
46  typedef std::vector<TokenRPN> RpnVector;
47 
48 public:
49 
51 
54 
58  GlobalLogicParser(const RpnVector&, const std::vector<OperandToken>&);
59 
62  GlobalLogicParser(const std::string& logicalExpressionVal);
63 
64  // from a non-constant logical expression - add/remove spaces if needed
65  // numerical expression will be empty
66  GlobalLogicParser(std::string& logicalExpressionVal);
67 
69  GlobalLogicParser(const std::string logicalExpressionVal,
70  const std::string numericalExpressionVal);
71 
74  GlobalLogicParser(const std::string& logicalExpressionVal,
75  const std::string& numericalExpressionVal,
76  const bool dummy);
77 
79  virtual ~GlobalLogicParser();
80 
81 public:
82 
85 
88 
91 
92 public:
93 
95  bool buildRpnVector(const std::string&);
96 
98  void clearRpnVector();
99 
101  inline RpnVector rpnVector() const { return m_rpnVector; }
102 
106 
108  inline std::vector<OperandToken>& operandTokenVector() { return m_operandTokenVector; }
109  inline const std::vector<OperandToken>& operandTokenVector() const { return m_operandTokenVector; }
110 
111 public:
112 
114  int operandIndex(const std::string& operandNameVal) const;
115 
117  std::string operandName(const int iOperand) const;
118 
121  bool operandResult(const std::string& operandNameVal) const;
122 
125  bool operandResult(const int tokenNumberVal) const;
126 
129  virtual const bool expressionResult() const;
130 
133  bool operandResultNumExp(const std::string& operandNameVal) const;
134 
137  bool operandResultNumExp(const int iOperand) const;
138 
142 
145  virtual const bool expressionResultNumExp() const;
146 
151  const std::map<std::string, int>& nameToIntMap);
152 
155 
156  void convertIntToNameLogicalExpression(const std::map<int, std::string>& intToNameMap);
157 
160  std::vector<GlobalLogicParser::OperandToken> expressionSeedsOperandList();
161 
162 
163 protected:
164 
165 
167  {
168  const char* opString;
169  int opType;
170  int forbiddenLastOperation; // int for bitmask of forbidden operations
171  };
172 
173 
174  virtual OperationType getOperation(const std::string& tokenString,
175  OperationType lastOperation, TokenRPN& rpnToken) const;
176 
179 
180  static const struct OperationRule m_operationRules[];
181 
182 protected:
183 
186 
188  bool setLogicalExpression(const std::string&);
189 
193  bool setNumericalExpression(const std::string&);
194 
195 protected:
196 
199 
203 
205  RpnVector m_rpnVector;
206 
208  std::vector<OperandToken> m_operandTokenVector;
209 
210 
211 };
212 
213 #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 &)