CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 public:
19  struct OperandToken {
23  };
24 
26  OP_NULL = 1,
28  OP_AND = 4,
29  OP_OR = 8,
30  OP_NOT = 16,
31  OP_OPERAND = 32,
34  OP_XOR = 256
35  };
36 
37  struct TokenRPN {
38  OperationType operation; // type of operation: AND, OR, NOT or OPERAND
39  std::string operand; // a possible operand
40  };
41 
42  typedef std::vector<TokenRPN> RpnVector;
43 
44 public:
46 
49 
53  GlobalLogicParser(const RpnVector&, const std::vector<OperandToken>&);
54 
57  GlobalLogicParser(const std::string& logicalExpressionVal);
58 
59  // from a non-constant logical expression - add/remove spaces if needed
60  // numerical expression will be empty
61  GlobalLogicParser(std::string& logicalExpressionVal);
62 
64  GlobalLogicParser(const std::string logicalExpressionVal, const std::string numericalExpressionVal);
65 
68  GlobalLogicParser(const std::string& logicalExpressionVal,
69  const std::string& numericalExpressionVal,
70  const bool dummy);
71 
73  virtual ~GlobalLogicParser();
74 
75 public:
78 
81 
84 
85 public:
87  bool buildRpnVector(const std::string&);
88 
90  void clearRpnVector();
91 
93  inline RpnVector rpnVector() const { return m_rpnVector; }
94 
98 
100  inline std::vector<OperandToken>& operandTokenVector() { return m_operandTokenVector; }
101  inline const std::vector<OperandToken>& operandTokenVector() const { return m_operandTokenVector; }
102 
103 public:
105  int operandIndex(const std::string& operandNameVal) const;
106 
108  std::string operandName(const int iOperand) const;
109 
112  bool operandResult(const std::string& operandNameVal) const;
113 
116  bool operandResult(const int tokenNumberVal) const;
117 
120  virtual const bool expressionResult() const;
121 
124  bool operandResultNumExp(const std::string& operandNameVal) const;
125 
128  bool operandResultNumExp(const int iOperand) const;
129 
133 
136  virtual const bool expressionResultNumExp() const;
137 
141  void convertNameToIntLogicalExpression(const std::map<std::string, int>& nameToIntMap);
142 
145 
146  void convertIntToNameLogicalExpression(const std::map<int, std::string>& intToNameMap);
147 
150  std::vector<GlobalLogicParser::OperandToken> expressionSeedsOperandList();
151 
152 protected:
153  struct OperationRule {
154  const char* opString;
155  int opType;
156  int forbiddenLastOperation; // int for bitmask of forbidden operations
157  };
158 
159  virtual OperationType getOperation(const std::string& tokenString,
160  OperationType lastOperation,
161  TokenRPN& rpnToken) const;
162 
165 
166  static const struct OperationRule m_operationRules[];
167 
168 protected:
171 
173  bool setLogicalExpression(const std::string&);
174 
178  bool setNumericalExpression(const std::string&);
179 
180 protected:
183 
187 
190 
192  std::vector<OperandToken> m_operandTokenVector;
193 };
194 
195 #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
static struct OperationRule m_operationRules[]
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
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 &)