GlsMenu
|
#include <gls_bool_expression.h>
Public Member Functions | |
GlsBoolExpression (GlsMenuDictionary &evalDict, bool defaultVal=false) | |
virtual | ~GlsBoolExpression () |
bool | operator() () const |
virtual void | Set (const std::string &val) |
GlsBoolExpression & | operator= (const GlsBoolExpression &r) |
bool | operator== (const GlsBoolExpression &r) const |
std::string | ExpressionString () const |
Protected Types | |
enum | Operator_t { OR, AND, EQ, NEQ, LT, LT_EQ, GT, GT_EQ, NOT, OPEN_PAREN, CLOSE_PAREN, MAX_OPERATORS } |
typedef std::vector< std::string > | TokenCont_t |
typedef std::map< std::string, Operator_t > | OperatorMap_t |
Protected Member Functions | |
virtual std::string | Evaluate (Operator_t op, const std::string &operand1, const std::string &operand2) const |
virtual bool | IsTrue (const std::string &word) const |
Static Protected Member Functions | |
static bool | IsAnOperator (const std::string &token) |
static TokenCont_t | InfixToRPN (const TokenCont_t &infixTokens) |
static void | Tokenize (const std::string &expr, TokenCont_t &tokens) |
static std::string::size_type | VarLength (const std::string &input, std::string::size_type start) |
static std::string | Uppercase (const std::string &str) |
static bool | ValidInfix (const TokenCont_t &infixTokens) |
Protected Attributes | |
GlsMenuDictionary & | _evalDict |
The dictionary to use to evaluate meta-data variables found in the expression. More... | |
std::string | _expressionString |
Storage of the original string for the expression. More... | |
bool | _latestValue |
The latest calculated result of the expression. More... | |
TokenCont_t | _RPNTokens |
These are the tokens that were extracted from the expression string and are stored in Reverse Polish Notation (RPN) order. More... | |
Static Protected Attributes | |
static bool | _initializedStaticData |
Whether or not the static class data has been initialized. This needs to be done only once by the first instance. More... | |
static OperatorMap_t | OP |
A map to convert from operator strings to their enum equivalent. More... | |
static const unsigned | PRECEDENCE [MAX_OPERATORS] |
Operator precedence values used when evaluating the expression. More... | |
The GlsBoolExpression provides a string-based boolean expression parser and evaluator for use with simulation meta-data variables. The expressions can be read in from an input stream so that boolean simulation meta-data can be set as a boolean expression rather than just literal boolean values (true and false).
Variables in the expression are also meta-data items from an associated evaluation data dictionary. Variables should be enclosed in the variable delimiters $( and ), eg Literals and variable comparisons will always be done on a string basis, so care must be taken to achieve the desired results. This could be improved later if the need ever arises. So far, string comparisons have been sufficient.
One limitation is that an expression must be contained all on a single line. There is currently no support for a multiline expression. This can be changed by modifying the stream extraction operator.
Definition at line 78 of file gls_bool_expression.h.
|
protected |
Definition at line 169 of file gls_bool_expression.h.
|
protected |
Definition at line 168 of file gls_bool_expression.h.
|
protected |
Enumerator | |
---|---|
OR | |
AND | |
EQ | |
NEQ | |
LT | |
LT_EQ | |
GT | |
GT_EQ | |
NOT | |
OPEN_PAREN | |
CLOSE_PAREN | |
MAX_OPERATORS |
Definition at line 151 of file gls_bool_expression.h.
GlsBoolExpression::GlsBoolExpression | ( | GlsMenuDictionary & | evalDict, |
bool | defaultVal = false |
||
) |
Class constructor.
evalDict | data dictionary used for evaluating values of variables used within the expression. |
defaultVal | value to initialize the expression with. |
|
inlinevirtual |
Class destructor.
Definition at line 96 of file gls_bool_expression.h.
|
protectedvirtual |
Evaluates the operation.
|
inline |
Returns the uppercase version of a string.
Definition at line 145 of file gls_bool_expression.h.
References _expressionString.
Referenced by operator<<().
|
staticprotected |
Converts the tokens into Reverse Polish Notation (RPN) order from infix. This makes evaluating the expression trivial.
|
inlinestaticprotected |
Returns true if the token is a logical operator.
Definition at line 216 of file gls_bool_expression.h.
|
protectedvirtual |
Determines if the string represents a boolean value of true.
bool GlsBoolExpression::operator() | ( | ) | const |
This operator evaluates the boolean expression and returns true or false.
|
inline |
Assignment operator.
Definition at line 118 of file gls_bool_expression.h.
References _expressionString, _latestValue, and _RPNTokens.
|
inline |
|
virtual |
Sets the boolean expression. This changes the entire expression.
Referenced by operator>>().
|
staticprotected |
Parses the input string expression and adds found tokens to the token container.
|
staticprotected |
Returns the uppercase version of a string.
|
staticprotected |
Determines if the infix expression is syntactically correct.
|
staticprotected |
Determines the length of the variable starting at start position in the input string.
|
protected |
The dictionary to use to evaluate meta-data variables found in the expression.
Definition at line 183 of file gls_bool_expression.h.
|
protected |
Storage of the original string for the expression.
Definition at line 186 of file gls_bool_expression.h.
Referenced by ExpressionString(), and operator=().
|
staticprotected |
Whether or not the static class data has been initialized. This needs to be done only once by the first instance.
Definition at line 173 of file gls_bool_expression.h.
|
mutableprotected |
The latest calculated result of the expression.
Definition at line 189 of file gls_bool_expression.h.
Referenced by operator=(), and operator==().
|
protected |
These are the tokens that were extracted from the expression string and are stored in Reverse Polish Notation (RPN) order.
Definition at line 193 of file gls_bool_expression.h.
Referenced by operator=().
|
staticprotected |
A map to convert from operator strings to their enum equivalent.
Definition at line 176 of file gls_bool_expression.h.
|
staticprotected |
Operator precedence values used when evaluating the expression.
Definition at line 179 of file gls_bool_expression.h.