2014-06-13 13:17:38 -04:00
|
|
|
#include "Filter.h"
|
|
|
|
|
|
|
|
|
|
using namespace boost;
|
|
|
|
|
namespace qi = boost::spirit::qi;
|
2014-07-07 20:24:57 -04:00
|
|
|
using qi::no_case;
|
|
|
|
|
|
2014-06-13 13:17:38 -04:00
|
|
|
namespace EntityFilter
|
|
|
|
|
{
|
2014-08-15 13:53:17 -04:00
|
|
|
Filter::Filter(const std::string &what, ProviderFactory* factory)
|
2014-06-13 13:17:38 -04:00
|
|
|
{
|
2014-08-15 13:53:17 -04:00
|
|
|
parser::query_parser<std::string::const_iterator> grammar(factory);
|
2014-06-13 13:17:38 -04:00
|
|
|
auto iter_begin = what.begin();
|
|
|
|
|
auto iter_end = what.end();
|
|
|
|
|
|
2014-07-07 20:24:57 -04:00
|
|
|
bool parse_success = qi::phrase_parse(iter_begin, iter_end, grammar,
|
2014-07-30 16:42:51 -04:00
|
|
|
boost::spirit::ascii::space, m_predicate);
|
|
|
|
|
|
2014-07-07 20:24:57 -04:00
|
|
|
if (!(parse_success && iter_begin == iter_end)) {
|
2015-05-11 19:11:26 +02:00
|
|
|
throw std::invalid_argument(String::compose("Attempted creating entity filter with invalid query. Query was '%1'", what));
|
2014-06-17 17:44:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
2014-06-13 13:17:38 -04:00
|
|
|
|
2014-07-30 16:42:51 -04:00
|
|
|
Filter::~Filter(){
|
|
|
|
|
delete m_predicate;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-27 15:27:01 -04:00
|
|
|
bool Filter::match(LocatedEntity& entity)
|
2014-06-17 17:44:13 -04:00
|
|
|
{
|
2014-07-30 16:42:51 -04:00
|
|
|
return m_predicate->isMatch(QueryContext{entity});
|
2014-06-13 13:17:38 -04:00
|
|
|
}
|
|
|
|
|
|
2014-08-13 13:07:46 -04:00
|
|
|
bool Filter::match(const QueryContext& context){
|
2014-07-30 16:42:51 -04:00
|
|
|
|
|
|
|
|
return m_predicate->isMatch(context);
|
|
|
|
|
}
|
2014-06-13 13:17:38 -04:00
|
|
|
}
|