1 #ifndef LogicalExpressions_h
2 #define LogicalExpressions_h 1
10 typedef std::map< const std::string, std::string > ConditionsMap ;
11 typedef std::map< const std::string, bool > ResultMap ;
24 Expression() : Operation( AND ), isNot(
false ), Value(
"") {
26 enum Operator{ OR, AND } ;
33 std::ostream& operator<< ( std::ostream& s,
Expression& e ) ;
47 std::vector< Expression >& _tokens ;
56 Tokenizer( std::vector< Expression >& tokens ) : _tokens(tokens) , _last(0), needToken(
true)
57 , openPar(0), closedPar(0) ,
65 if( c !=
' ' && c !=
'\t' ) {
67 if( c ==
'(' ) ++openPar ;
69 if( c ==
')' ) ++closedPar ;
80 _tokens.back().isNot = true ;
83 _state = parenthesis ;
86 _tokens.back().Value += c ;
93 if( closedPar == openPar ) {
99 _tokens.back().Value += c ;
105 if( c ==
'&' || c==
'|' ){
107 if ( c ==
'&' && _last ==
'&' ) {
109 _tokens.back().Operation = Expression::AND ;
112 if ( c ==
'|' && _last ==
'|' ) {
114 _tokens.back().Operation = Expression::OR ;
120 _tokens.back().Value += c ;
133 std::vector<Expression> & result() {
157 void addCondition(
const std::string& name,
const std::string& expression ) ;
169 void setValue(
const std::string& key,
bool val ) ;
175 bool getValue(
const std::string& key );
177 ConditionsMap _condMap{};
178 ResultMap _resultMap{};
void clear()
Clear all boolean values.
Definition: LogicalExpressions.cc:34
void setValue(const std::string &key, bool val)
Set the the boolean value for the given key.
Definition: LogicalExpressions.cc:102
bool getValue(const std::string &key)
helper function for finding return values, that actually have been set by their corresponding process...
Definition: LogicalExpressions.cc:113
virtual ~LogicalExpressions()
Virtual d'tor.
Definition: LogicalExpressions.h:152
Helper class for LogicalExpressions that splits the expression into subexpressions - needs to be apll...
Definition: LogicalExpressions.h:39
Helper struct for LogicalExpression.
Definition: LogicalExpressions.h:22
Helper class that holds named boolean values and named conditions that are expressions of these value...
Definition: LogicalExpressions.h:143
bool expressionIsTrue(const std::string &expression)
True if the given expression is true with the current values.
Definition: LogicalExpressions.cc:51
LogicalExpressions()
C'tor.
Definition: LogicalExpressions.cc:20
bool conditionIsTrue(const std::string &name)
True if the named condition (stored with addCondition) is true with the current values.
Definition: LogicalExpressions.cc:46
void operator()(const char &c)
Save the current character and change state if necessary.
Definition: LogicalExpressions.h:63
void addCondition(const std::string &name, const std::string &expression)
Add a new named logical expression formed out of [!,(,&&,||,),value], e.g.
Definition: LogicalExpressions.cc:28