MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckClause( const MojObject& clause, const MojObject& response, MatchMode mode) const { LOG_AM_TRACE("Entering function %s", __FUNCTION__); if (clause.type() == MojObject::TypeArray) { return CheckClauses(clause, response, mode); } else if (clause.type() != MojObject::TypeObject) { throw std::runtime_error("Clauses must be either an object or array " "of objects"); } LOG_AM_DEBUG("Checking clause '%s' against response '%s' (%s)", MojoObjectJson(clause).c_str(), MojoObjectJson(response).c_str(), (mode == AndMode) ? "and" : "or"); if (clause.contains(_T("and"))) { MojObject andClause; clause.get(_T("and"), andClause); return CheckClause(andClause, response, AndMode); } else if (clause.contains(_T("or"))) { MojObject orClause; clause.get(_T("or"), orClause); return CheckClause(orClause, response, OrMode); } MojObject prop; bool found = clause.get(_T("prop"), prop); if (!found) { throw std::runtime_error("Clauses must contain \"and\", \"or\", " "or a comparison to make"); } MojObject op; found = clause.get(_T("op"), op); if (!found) { throw std::runtime_error("Clauses must specify a comparison operation " "to perform"); } MojObject val; found = clause.get(_T("val"), val); if (!found) { throw std::runtime_error("Clauses must specify a value to compare " "against"); } MatchResult result = CheckProperty(prop, response, op, val, mode); LOG_AM_DEBUG("Where Trigger: Clause %s %s", MojoObjectJson(clause).c_str(), (result == Matched) ? "matched" : "did not match"); return result; }
bool MojoWhereMatcher::Match(const MojObject& response) { MojLogTrace(s_log); if (CheckClauses(m_where, response)) { MojLogInfo(s_log, _T("Where Matcher: Response %s matches"), MojoObjectJson(response).c_str()); return true; } else { MojLogInfo(s_log, _T("Where Matcher: Response %s does not match"), MojoObjectJson(response).c_str()); return false; } }
bool MojoWhereMatcher::Match(const MojObject& response) { LOG_AM_TRACE("Entering function %s", __FUNCTION__); if (CheckClauses(m_where, response)) { LOG_AM_DEBUG("Where Matcher: Response %s matches", MojoObjectJson(response).c_str()); return true; } else { LOG_AM_DEBUG("Where Matcher: Response %s does not match", MojoObjectJson(response).c_str()); return false; } }