#ifndef ARABICA_XPATHIC_MATCH_HPP #define ARABICA_XPATHIC_MATCH_HPP #include #include "xpath_expression.hpp" #include "xpath_value.hpp" namespace Arabica { namespace XPath { template > class MatchExpr { public: MatchExpr(XPathExpression_impl* match, double priority) : 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; } double priority() const { return priority_; } bool evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { return match_.evaluateAsBool(context, executionContext); } // evaluate void override_priority(double p) { priority_ = p; } private: XPathExpression match_; double priority_; }; // MatchExpr namespace impl { template class MatchExpressionWrapper : public XPathExpression_impl { public: MatchExpressionWrapper(XPathExpression_impl* expr, double priority) { add_match(expr, priority); } // MatchExpressionWrapper MatchExpressionWrapper(XPathExpression_impl* expr) { add_matches(expr); } // MatchExpressionWrapper virtual XPathValue evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { throw std::runtime_error("MatchExpressionWrapper - you should never see this"); } // evaluate const std::vector >& matches() const { return matches_; } // matches void add_match(XPathExpression_impl* match, double priority) { matches_.push_back(MatchExpr(match, priority)); } // add_match void add_matches(XPathExpression_impl* wrapper) { const std::vector >& more = static_cast*>(wrapper)->matches(); for(typename std::vector >::const_iterator m = more.begin(), me = more.end(); m != me; ++m) matches_.push_back(*m); delete wrapper; } // add_matches private: std::vector > matches_; }; // class MatchExpressionWrapper } // namespace impl } // namespace XPath } // namespace Arabica #endif