2005-08-04 22:42:30 +02:00
|
|
|
#ifndef ARABICA_XPATHIC_XPATH_ARITHMETIC_HPP
|
|
|
|
#define ARABICA_XPATHIC_XPATH_ARITHMETIC_HPP
|
|
|
|
|
|
|
|
#include "xpath_value.hpp"
|
|
|
|
|
|
|
|
namespace Arabica
|
|
|
|
{
|
|
|
|
namespace XPath
|
|
|
|
{
|
|
|
|
|
2005-08-17 09:01:27 +02:00
|
|
|
template<class string_type, class string_adaptor>
|
2005-08-17 12:13:05 +02:00
|
|
|
class PlusOperator : private BinaryExpression<string_type, string_adaptor>,
|
|
|
|
public XPathExpression<string_type, string_adaptor>
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 12:13:05 +02:00
|
|
|
typedef BinaryExpression<string_type, string_adaptor> baseT;
|
2005-08-04 22:42:30 +02:00
|
|
|
public:
|
2005-08-17 12:13:05 +02:00
|
|
|
PlusOperator(XPathExpression<string_type, string_adaptor>* lhs, XPathExpression<string_type, string_adaptor>* rhs) :
|
|
|
|
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2005-08-16 18:23:10 +02:00
|
|
|
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
|
2005-08-17 12:13:05 +02:00
|
|
|
const ExecutionContext<string_type, string_adaptor>& executionContext) const
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 09:01:27 +02:00
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context) + baseT::rhs()->evaluateAsNumber(context));
|
2005-08-04 22:42:30 +02:00
|
|
|
} // evaluate
|
|
|
|
}; // class PlusOperator
|
|
|
|
|
2005-08-17 09:01:27 +02:00
|
|
|
template<class string_type, class string_adaptor>
|
2005-08-17 12:13:05 +02:00
|
|
|
class MinusOperator : private BinaryExpression<string_type, string_adaptor>,
|
|
|
|
public XPathExpression<string_type, string_adaptor>
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 12:13:05 +02:00
|
|
|
typedef BinaryExpression<string_type, string_adaptor> baseT;
|
2005-08-04 22:42:30 +02:00
|
|
|
public:
|
2005-08-17 12:13:05 +02:00
|
|
|
MinusOperator(XPathExpression<string_type, string_adaptor>* lhs, XPathExpression<string_type, string_adaptor>* rhs) :
|
|
|
|
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2005-08-16 18:23:10 +02:00
|
|
|
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
|
2005-08-17 12:13:05 +02:00
|
|
|
const ExecutionContext<string_type, string_adaptor>& executionContext) const
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 09:01:27 +02:00
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context) - baseT::rhs()->evaluateAsNumber(context));
|
2005-08-04 22:42:30 +02:00
|
|
|
} // evaluate
|
|
|
|
}; // class MinusOperator
|
|
|
|
|
2005-08-17 09:01:27 +02:00
|
|
|
template<class string_type, class string_adaptor>
|
2005-08-17 12:13:05 +02:00
|
|
|
class MultiplyOperator : private BinaryExpression<string_type, string_adaptor>,
|
|
|
|
public XPathExpression<string_type, string_adaptor>
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 12:13:05 +02:00
|
|
|
typedef BinaryExpression<string_type, string_adaptor> baseT;
|
2005-08-04 22:42:30 +02:00
|
|
|
public:
|
2005-08-17 12:13:05 +02:00
|
|
|
MultiplyOperator(XPathExpression<string_type, string_adaptor>* lhs, XPathExpression<string_type, string_adaptor>* rhs) :
|
|
|
|
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2005-08-16 18:23:10 +02:00
|
|
|
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
|
2005-08-17 12:13:05 +02:00
|
|
|
const ExecutionContext<string_type, string_adaptor>& executionContext) const
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 09:01:27 +02:00
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context) * baseT::rhs()->evaluateAsNumber(context));
|
2005-08-04 22:42:30 +02:00
|
|
|
} // evaluate
|
|
|
|
}; // class MultiplyOperator
|
|
|
|
|
2005-08-17 09:01:27 +02:00
|
|
|
template<class string_type, class string_adaptor>
|
2005-08-17 12:13:05 +02:00
|
|
|
class DivideOperator : private BinaryExpression<string_type, string_adaptor>,
|
|
|
|
public XPathExpression<string_type, string_adaptor>
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 12:13:05 +02:00
|
|
|
typedef BinaryExpression<string_type, string_adaptor> baseT;
|
2005-08-04 22:42:30 +02:00
|
|
|
public:
|
2005-08-17 12:13:05 +02:00
|
|
|
DivideOperator(XPathExpression<string_type, string_adaptor>* lhs, XPathExpression<string_type, string_adaptor>* rhs) :
|
|
|
|
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2005-08-16 18:23:10 +02:00
|
|
|
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
|
2005-08-17 12:13:05 +02:00
|
|
|
const ExecutionContext<string_type, string_adaptor>& executionContext) const
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 09:01:27 +02:00
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context) / baseT::rhs()->evaluateAsNumber(context));
|
2005-08-04 22:42:30 +02:00
|
|
|
} // evaluate
|
|
|
|
}; // class DivideOperator
|
|
|
|
|
2005-08-17 09:01:27 +02:00
|
|
|
template<class string_type, class string_adaptor>
|
2005-08-17 12:13:05 +02:00
|
|
|
class ModOperator : private BinaryExpression<string_type, string_adaptor>,
|
|
|
|
public XPathExpression<string_type, string_adaptor>
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 12:13:05 +02:00
|
|
|
typedef BinaryExpression<string_type, string_adaptor> baseT;
|
2005-08-04 22:42:30 +02:00
|
|
|
public:
|
2005-08-17 12:13:05 +02:00
|
|
|
ModOperator(XPathExpression<string_type, string_adaptor>* lhs, XPathExpression<string_type, string_adaptor>* rhs) :
|
|
|
|
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2005-08-16 18:23:10 +02:00
|
|
|
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
|
2005-08-17 12:13:05 +02:00
|
|
|
const ExecutionContext<string_type, string_adaptor>& executionContext) const
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 09:01:27 +02:00
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(static_cast<long>(baseT::lhs()->evaluateAsNumber(context)) % static_cast<long>(baseT::rhs()->evaluateAsNumber(context)));
|
2005-08-04 22:42:30 +02:00
|
|
|
} // evaluate
|
|
|
|
}; // class ModOperator
|
|
|
|
|
2005-08-17 09:01:27 +02:00
|
|
|
template<class string_type, class string_adaptor>
|
2005-08-17 12:13:05 +02:00
|
|
|
class UnaryNegative : private UnaryExpression<string_type, string_adaptor>,
|
|
|
|
public XPathExpression<string_type, string_adaptor>
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 12:13:05 +02:00
|
|
|
typedef UnaryExpression<string_type, string_adaptor> baseT;
|
2005-08-04 22:42:30 +02:00
|
|
|
public:
|
2005-08-17 12:13:05 +02:00
|
|
|
UnaryNegative(XPathExpression<string_type, string_adaptor>* expr) :
|
|
|
|
UnaryExpression<string_type, string_adaptor>(expr) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2005-08-16 18:23:10 +02:00
|
|
|
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
|
2005-08-17 12:13:05 +02:00
|
|
|
const ExecutionContext<string_type, string_adaptor>& executionContext) const
|
2005-08-04 22:42:30 +02:00
|
|
|
{
|
2005-08-17 09:01:27 +02:00
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(-baseT::expr()->evaluate(context, executionContext)->asNumber());
|
2005-08-04 22:42:30 +02:00
|
|
|
} // evaluate
|
|
|
|
}; // class UnaryNegative
|
|
|
|
|
|
|
|
} // XPath
|
|
|
|
} // Arabica
|
|
|
|
|
|
|
|
#endif
|