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-22 17:04:27 +02:00
|
|
|
namespace impl
|
|
|
|
{
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2005-08-17 09:01:27 +02:00
|
|
|
template<class string_type, class string_adaptor>
|
2007-12-21 16:56:04 +01:00
|
|
|
class PlusOperator : public BinaryExpression<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:
|
2007-10-23 23:37:24 +02:00
|
|
|
PlusOperator(XPathExpression_impl<string_type, string_adaptor>* lhs, XPathExpression_impl<string_type, string_adaptor>* rhs) :
|
2005-08-17 12:13:05 +02:00
|
|
|
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2007-12-19 00:03:16 +01:00
|
|
|
virtual ValueType type() const { return NUMBER; }
|
|
|
|
|
2007-10-22 19:42:50 +02:00
|
|
|
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& 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
|
|
|
{
|
2007-07-19 19:01:31 +02:00
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context, executionContext) + baseT::rhs()->evaluateAsNumber(context, executionContext));
|
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>
|
2007-12-21 16:56:04 +01:00
|
|
|
class MinusOperator : public BinaryExpression<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:
|
2007-10-23 23:37:24 +02:00
|
|
|
MinusOperator(XPathExpression_impl<string_type, string_adaptor>* lhs, XPathExpression_impl<string_type, string_adaptor>* rhs) :
|
2005-08-17 12:13:05 +02:00
|
|
|
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2007-12-19 00:03:16 +01:00
|
|
|
virtual ValueType type() const { return NUMBER; }
|
|
|
|
|
2007-10-22 19:42:50 +02:00
|
|
|
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& 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
|
|
|
{
|
2007-07-19 19:01:31 +02:00
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context, executionContext) - baseT::rhs()->evaluateAsNumber(context, executionContext));
|
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>
|
2007-12-21 16:56:04 +01:00
|
|
|
class MultiplyOperator : public BinaryExpression<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:
|
2007-10-23 23:37:24 +02:00
|
|
|
MultiplyOperator(XPathExpression_impl<string_type, string_adaptor>* lhs, XPathExpression_impl<string_type, string_adaptor>* rhs) :
|
2005-08-17 12:13:05 +02:00
|
|
|
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2007-12-19 00:03:16 +01:00
|
|
|
virtual ValueType type() const { return NUMBER; }
|
|
|
|
|
2007-10-22 19:42:50 +02:00
|
|
|
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& 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
|
|
|
{
|
2007-07-19 19:01:31 +02:00
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context, executionContext) * baseT::rhs()->evaluateAsNumber(context, executionContext));
|
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>
|
2007-12-21 16:56:04 +01:00
|
|
|
class DivideOperator : public BinaryExpression<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:
|
2007-10-23 23:37:24 +02:00
|
|
|
DivideOperator(XPathExpression_impl<string_type, string_adaptor>* lhs, XPathExpression_impl<string_type, string_adaptor>* rhs) :
|
2005-08-17 12:13:05 +02:00
|
|
|
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2007-12-19 00:03:16 +01:00
|
|
|
virtual ValueType type() const { return NUMBER; }
|
|
|
|
|
2007-10-22 19:42:50 +02:00
|
|
|
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& 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
|
|
|
{
|
2007-07-19 19:01:31 +02:00
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(baseT::lhs()->evaluateAsNumber(context, executionContext) / baseT::rhs()->evaluateAsNumber(context, executionContext));
|
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>
|
2007-12-21 16:56:04 +01:00
|
|
|
class ModOperator : public BinaryExpression<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:
|
2007-10-23 23:37:24 +02:00
|
|
|
ModOperator(XPathExpression_impl<string_type, string_adaptor>* lhs, XPathExpression_impl<string_type, string_adaptor>* rhs) :
|
2005-08-17 12:13:05 +02:00
|
|
|
BinaryExpression<string_type, string_adaptor>(lhs, rhs) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2007-12-19 00:03:16 +01:00
|
|
|
virtual ValueType type() const { return NUMBER; }
|
|
|
|
|
2007-10-22 19:42:50 +02:00
|
|
|
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& 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
|
|
|
{
|
2007-07-19 19:01:31 +02:00
|
|
|
double l = baseT::lhs()->evaluateAsNumber(context, executionContext);
|
|
|
|
double r = baseT::rhs()->evaluateAsNumber(context, executionContext);
|
|
|
|
|
|
|
|
if(isNaN(l) || isNaN(r))
|
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(NaN);
|
|
|
|
return NumericValue<string_type, string_adaptor>::createValue(static_cast<long>(l) % static_cast<long>(r));
|
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>
|
2007-12-21 16:56:04 +01:00
|
|
|
class UnaryNegative : public UnaryExpression<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:
|
2007-10-23 23:37:24 +02:00
|
|
|
UnaryNegative(XPathExpression_impl<string_type, string_adaptor>* expr) :
|
2005-08-17 12:13:05 +02:00
|
|
|
UnaryExpression<string_type, string_adaptor>(expr) { }
|
2005-08-04 22:42:30 +02:00
|
|
|
|
2007-12-19 00:03:16 +01:00
|
|
|
virtual ValueType type() const { return NUMBER; }
|
|
|
|
|
2007-10-22 19:42:50 +02:00
|
|
|
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& 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
|
|
|
{
|
2007-10-22 19:42:50 +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
|
|
|
|
|
2005-08-22 17:04:27 +02:00
|
|
|
} // namespace impl
|
|
|
|
} // namespace XPath
|
|
|
|
} // namespace Arabica
|
2005-08-04 22:42:30 +02:00
|
|
|
|
|
|
|
#endif
|