2007-07-19 19:01:31 +02:00
|
|
|
#ifndef ARABICA_XPATHIC_MATCH_HPP
|
|
|
|
#define ARABICA_XPATHIC_MATCH_HPP
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include "xpath_expression.hpp"
|
|
|
|
#include "xpath_value.hpp"
|
|
|
|
|
|
|
|
namespace Arabica
|
|
|
|
{
|
|
|
|
namespace XPath
|
|
|
|
{
|
|
|
|
|
|
|
|
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
|
2007-10-14 22:06:27 +02:00
|
|
|
class MatchExpr
|
2007-07-19 19:01:31 +02:00
|
|
|
{
|
2007-10-14 22:06:27 +02:00
|
|
|
public:
|
2007-10-23 23:37:24 +02:00
|
|
|
MatchExpr(XPathExpression_impl<string_type, string_adaptor>* match, double priority) :
|
2007-07-19 19:01:31 +02:00
|
|
|
match_(match), priority_(priority) { }
|
|
|
|
MatchExpr(const MatchExpr& rhs) :
|
|
|
|
match_(rhs.match_), priority_(rhs.priority_) { }
|
|
|
|
MatchExpr& operator=(const MatchExpr& rhs)
|
|
|
|
{ match_ = rhs.match_; priority_ = rhs.priority_; return *this; }
|
|
|
|
|
2007-10-14 22:06:27 +02:00
|
|
|
double priority() const { return priority_; }
|
|
|
|
bool evaluate(const DOM::Node<string_type, string_adaptor>& context,
|
|
|
|
const ExecutionContext<string_type, string_adaptor>& executionContext) const
|
|
|
|
{
|
2007-10-25 22:42:00 +02:00
|
|
|
return match_.evaluateAsBool(context, executionContext);
|
2007-10-14 22:06:27 +02:00
|
|
|
} // evaluate
|
|
|
|
|
|
|
|
void override_priority(double p) { priority_ = p; }
|
|
|
|
|
|
|
|
private:
|
2007-10-25 22:42:00 +02:00
|
|
|
XPathExpression<string_type, string_adaptor> match_;
|
2007-07-19 19:01:31 +02:00
|
|
|
double priority_;
|
|
|
|
}; // MatchExpr
|
|
|
|
|
|
|
|
namespace impl
|
|
|
|
{
|
|
|
|
|
|
|
|
template<class string_type, class string_adaptor>
|
2007-10-23 23:37:24 +02:00
|
|
|
class MatchExpressionWrapper : public XPathExpression_impl<string_type, string_adaptor>
|
2007-07-19 19:01:31 +02:00
|
|
|
{
|
|
|
|
public:
|
2007-10-23 23:37:24 +02:00
|
|
|
MatchExpressionWrapper(XPathExpression_impl<string_type, string_adaptor>* expr, double priority)
|
2007-07-19 19:01:31 +02:00
|
|
|
{
|
|
|
|
add_match(expr, priority);
|
|
|
|
} // MatchExpressionWrapper
|
|
|
|
|
2007-10-23 23:37:24 +02:00
|
|
|
MatchExpressionWrapper(XPathExpression_impl<string_type, string_adaptor>* expr)
|
2007-07-19 19:01:31 +02:00
|
|
|
{
|
|
|
|
add_matches(expr);
|
|
|
|
} // MatchExpressionWrapper
|
|
|
|
|
2007-10-22 19:42:50 +02:00
|
|
|
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& context,
|
2007-07-19 19:01:31 +02:00
|
|
|
const ExecutionContext<string_type, string_adaptor>& executionContext) const
|
|
|
|
{
|
|
|
|
throw std::runtime_error("MatchExpressionWrapper - you should never see this");
|
|
|
|
} // evaluate
|
|
|
|
|
|
|
|
const std::vector<MatchExpr<string_type, string_adaptor> >& matches() const
|
|
|
|
{
|
|
|
|
return matches_;
|
|
|
|
} // matches
|
|
|
|
|
2007-10-23 23:37:24 +02:00
|
|
|
void add_match(XPathExpression_impl<string_type, string_adaptor>* match, double priority)
|
2007-07-19 19:01:31 +02:00
|
|
|
{
|
|
|
|
matches_.push_back(MatchExpr<string_type, string_adaptor>(match, priority));
|
|
|
|
} // add_match
|
|
|
|
|
2007-10-23 23:37:24 +02:00
|
|
|
void add_matches(XPathExpression_impl<string_type, string_adaptor>* wrapper)
|
2007-07-19 19:01:31 +02:00
|
|
|
{
|
|
|
|
const std::vector<MatchExpr<string_type, string_adaptor> >& more = static_cast<impl::MatchExpressionWrapper<string_type, string_adaptor>*>(wrapper)->matches();
|
|
|
|
for(typename std::vector<MatchExpr<string_type, string_adaptor> >::const_iterator m = more.begin(), me = more.end(); m != me; ++m)
|
|
|
|
matches_.push_back(*m);
|
|
|
|
delete wrapper;
|
|
|
|
} // add_matches
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<MatchExpr<string_type, string_adaptor> > matches_;
|
|
|
|
}; // class MatchExpressionWrapper
|
|
|
|
|
|
|
|
} // namespace impl
|
|
|
|
} // namespace XPath
|
|
|
|
} // namespace Arabica
|
|
|
|
|
|
|
|
#endif
|