arabica/XPath/impl/xpath_arithmetic.hpp

111 lines
5.2 KiB
C++
Raw Normal View History

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>
class PlusOperator : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
2005-08-04 22:42:30 +02:00
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
2005-08-04 22:42:30 +02:00
public:
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
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
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>
class MinusOperator : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
2005-08-04 22:42:30 +02:00
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
2005-08-04 22:42:30 +02:00
public:
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
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
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>
class MultiplyOperator : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
2005-08-04 22:42:30 +02:00
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
2005-08-04 22:42:30 +02:00
public:
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
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
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>
class DivideOperator : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
2005-08-04 22:42:30 +02:00
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
2005-08-04 22:42:30 +02:00
public:
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
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
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>
class ModOperator : private BinaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
2005-08-04 22:42:30 +02:00
{
typedef BinaryExpression<string_type, string_adaptor> baseT;
2005-08-04 22:42:30 +02:00
public:
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
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
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>
class UnaryNegative : private UnaryExpression<string_type, string_adaptor>,
public XPathExpression<string_type, string_adaptor>
2005-08-04 22:42:30 +02:00
{
typedef UnaryExpression<string_type, string_adaptor> baseT;
2005-08-04 22:42:30 +02:00
public:
UnaryNegative(XPathExpression<string_type, string_adaptor>* expr) :
UnaryExpression<string_type, string_adaptor>(expr) { }
2005-08-04 22:42:30 +02:00
virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context,
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