arabica/include/XPath/impl/xpath_relational.hpp
jez 235f81718d Added Expression_scanner and scan (a visitor pattern basically) to allow XPathExpression_impls to be examined. This is used in the match rewriting to search for position() and last() function calls.
To ease implementing scan, BinaryExpression and UnaryExpression now inherit XPathExpression_impl.  Other classes now derived only from Binary|UnaryExpression rather than from XPathExpression_impl as well.
2007-12-21 15:56:04 +00:00

130 lines
6.3 KiB
C++

#ifndef ARABICA_XPATHIC_XPATH_RELATIONAL_HPP
#define ARABICA_XPATHIC_XPATH_RELATIONAL_HPP
#include "xpath_value.hpp"
namespace Arabica
{
namespace XPath
{
namespace impl
{
template<class string_type, class string_adaptor>
class EqualsOperator : public BinaryExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
EqualsOperator(XPathExpression_impl<string_type, string_adaptor>* lhs,
XPathExpression_impl<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual ValueType type() const { return BOOL; }
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return BoolValue<string_type, string_adaptor>::createValue(areEqual<string_type, string_adaptor>(baseT::lhs()->evaluate(context, executionContext),
baseT::rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class EqualsOperator
template<class string_type, class string_adaptor>
class NotEqualsOperator : public BinaryExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
NotEqualsOperator(XPathExpression_impl<string_type, string_adaptor>* lhs,
XPathExpression_impl<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual ValueType type() const { return BOOL; }
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return BoolValue<string_type, string_adaptor>::createValue(areNotEqual<string_type, string_adaptor>(baseT::lhs()->evaluate(context, executionContext),
baseT::rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class NotEqualsOperator
template<class string_type, class string_adaptor>
class LessThanOperator : public BinaryExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
LessThanOperator(XPathExpression_impl<string_type, string_adaptor>* lhs,
XPathExpression_impl<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual ValueType type() const { return BOOL; }
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return BoolValue<string_type, string_adaptor>::createValue(isLessThan<string_type, string_adaptor>(baseT::lhs()->evaluate(context, executionContext),
baseT::rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class LessThanOperator
template<class string_type, class string_adaptor>
class LessThanEqualsOperator : public BinaryExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
LessThanEqualsOperator(XPathExpression_impl<string_type, string_adaptor>* lhs,
XPathExpression_impl<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual ValueType type() const { return BOOL; }
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return BoolValue<string_type, string_adaptor>::createValue(isLessThanEquals<string_type, string_adaptor>(baseT::lhs()->evaluate(context, executionContext),
baseT::rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class LessThanEqualsOperator
template<class string_type, class string_adaptor>
class GreaterThanOperator : public BinaryExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
GreaterThanOperator(XPathExpression_impl<string_type, string_adaptor>* lhs,
XPathExpression_impl<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual ValueType type() const { return BOOL; }
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return BoolValue<string_type, string_adaptor>::createValue(isGreaterThan<string_type, string_adaptor>(baseT::lhs()->evaluate(context, executionContext),
baseT::rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class GreaterThanOperator
template<class string_type, class string_adaptor>
class GreaterThanEqualsOperator : public BinaryExpression<string_type, string_adaptor>
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
public:
GreaterThanEqualsOperator(XPathExpression_impl<string_type, string_adaptor>* lhs,
XPathExpression_impl<string_type, string_adaptor>* rhs) :
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
virtual ValueType type() const { return BOOL; }
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return BoolValue<string_type, string_adaptor>::createValue(isGreaterThanEquals<string_type, string_adaptor>(baseT::lhs()->evaluate(context, executionContext),
baseT::rhs()->evaluate(context, executionContext)));
} // evaluate
}; // class GreaterThanEqualsOperator
} // namespace impl
} // namespace XPath
} // namespace Arabica
#endif