30 std::string valid_sym =
"_";
31 if (isalpha(c) || isdigit(c) || valid_sym.find(c)!=std::string::npos) {
42 for (
unsigned int i=0; i<expr.size(); ++i) {
59 while (no_problem && i < expr.size()) {
66 if ( (n = sub.
parse(expr.substr(i+1),
true)) > 0) {
83 std::ostringstream formatedoutput;
97 std::ostringstream formatedoutput;
98 formatedoutput <<
kAND <<
" or " <<
kOR <<
" must come after a logic element";
112 }
else if ( (i+1)<expr.size() && expr[i+1]==
kOPEN) {
114 if ( (n = sub2.
parse(expr.substr(i+2),
true)) > 0) {
122 printError(
"Was expecting a sub-logic after !", i);
126 printError(
"! must not come directly after a logic element", i);
136 if (
name.size() > 0) {
145 printError(
"A logic element may not come immediately after another logic element", i);
160 printError(
"The expression started with a '(' but ')' not found.", i);
181 LogicV_t::const_iterator p;
184 s += (*p)->logicRep();
187 if (s.size() > 1) s[s.size()-1] =
kCLOSE;
205 LogicV_t::const_iterator p;
211 std::string e =
subLogics()[0]->element();
216 for (p=sublogics.begin(); p!=sublogics.end(); ++p) {
226 LogicV_t::const_iterator p;
234 n += (*p)->totalNumberOfElements();
247 std::string m=
"Error while parsing : ";
250 for (
int j=0; j<(n+i); ++j) s +=
" ";
261 sprintf(aaa,
"Current state: State=%c Nsublogics=%d Element=%s",
269 std::string s=indent;
275 LogicV_t::const_iterator p;
277 (*p)->print(indent +
" ");
280 m_ostream << indent <<
"NOT" << std::endl;
287 m_ostream << indent <<
"ERROR" << std::endl;
LogicExpression(std::ostream &o=std::cout)
constructor
std::ostream & m_ostream
output stream for all messages
static const char kAND
AND of sub-logics.
static const char kOPEN
empty logic but may have sub-logics.
bool isPlaceHolder() const
virtual std::string logicRep() const
static const char kNOT
NOT of a sub-logic. (only one sub-logic)
void addSubLogic(const LogicExpression &sub)
static const char kCLOSE
')' is a valid symbol, but not allowed as a state.
static const char kELEMENT
simple element.
static bool isValidElementChar(char c)
void printError(const std::string &message, int i)
const LogicV_t & subLogics() const
void setElement(const std::string &e)
int totalNumberOfElements() const
static const char kOR
OR of sub-logics.
const std::shared_ptr< LogicExpression > subLogic(int i) const
static std::string extractElementName(const std::string &expr)
void print(const std::string &indent="")
virtual int parse(const std::string &expr, bool enclosed=false)
Forward iterator to traverse the main components of the trigger configuration.
std::vector< std::shared_ptr< LogicExpression > > LogicV_t