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 addCondition(const std::string &name, const std::string &expression)
Definition: LogicalExpressions.cc:28
Definition: LogicalExpressions.h:22
bool conditionIsTrue(const std::string &name)
Definition: LogicalExpressions.cc:46
Definition: LogicalExpressions.h:143
void clear()
Definition: LogicalExpressions.cc:34
LogicalExpressions()
Definition: LogicalExpressions.cc:20
bool expressionIsTrue(const std::string &expression)
Definition: LogicalExpressions.cc:51
void setValue(const std::string &key, bool val)
Definition: LogicalExpressions.cc:102
void operator()(const char &c)
Definition: LogicalExpressions.h:63
Namespace for Luiza framework.
Definition: CCCollection.h:6
virtual ~LogicalExpressions()
Definition: LogicalExpressions.h:152
Definition: LogicalExpressions.h:39
bool getValue(const std::string &key)
Definition: LogicalExpressions.cc:113