#ifndef ARABICA_XPATHIC_XPATH_ARITHMETIC_HPP #define ARABICA_XPATHIC_XPATH_ARITHMETIC_HPP #include "xpath_value.hpp" namespace Arabica { namespace XPath { namespace impl { template class PlusOperator : private BinaryExpression, public XPathExpression { typedef BinaryExpression baseT; public: PlusOperator(XPathExpression* lhs, XPathExpression* rhs) : BinaryExpression(lhs, rhs) { } virtual XPathValuePtr evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { return NumericValue::createValue(baseT::lhs()->evaluateAsNumber(context) + baseT::rhs()->evaluateAsNumber(context)); } // evaluate }; // class PlusOperator template class MinusOperator : private BinaryExpression, public XPathExpression { typedef BinaryExpression baseT; public: MinusOperator(XPathExpression* lhs, XPathExpression* rhs) : BinaryExpression(lhs, rhs) { } virtual XPathValuePtr evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { return NumericValue::createValue(baseT::lhs()->evaluateAsNumber(context) - baseT::rhs()->evaluateAsNumber(context)); } // evaluate }; // class MinusOperator template class MultiplyOperator : private BinaryExpression, public XPathExpression { typedef BinaryExpression baseT; public: MultiplyOperator(XPathExpression* lhs, XPathExpression* rhs) : BinaryExpression(lhs, rhs) { } virtual XPathValuePtr evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { return NumericValue::createValue(baseT::lhs()->evaluateAsNumber(context) * baseT::rhs()->evaluateAsNumber(context)); } // evaluate }; // class MultiplyOperator template class DivideOperator : private BinaryExpression, public XPathExpression { typedef BinaryExpression baseT; public: DivideOperator(XPathExpression* lhs, XPathExpression* rhs) : BinaryExpression(lhs, rhs) { } virtual XPathValuePtr evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { return NumericValue::createValue(baseT::lhs()->evaluateAsNumber(context) / baseT::rhs()->evaluateAsNumber(context)); } // evaluate }; // class DivideOperator template class ModOperator : private BinaryExpression, public XPathExpression { typedef BinaryExpression baseT; public: ModOperator(XPathExpression* lhs, XPathExpression* rhs) : BinaryExpression(lhs, rhs) { } virtual XPathValuePtr evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { return NumericValue::createValue(static_cast(baseT::lhs()->evaluateAsNumber(context)) % static_cast(baseT::rhs()->evaluateAsNumber(context))); } // evaluate }; // class ModOperator template class UnaryNegative : private UnaryExpression, public XPathExpression { typedef UnaryExpression baseT; public: UnaryNegative(XPathExpression* expr) : UnaryExpression(expr) { } virtual XPathValuePtr evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { return NumericValue::createValue(-baseT::expr()->evaluate(context, executionContext)->asNumber()); } // evaluate }; // class UnaryNegative } // namespace impl } // namespace XPath } // namespace Arabica #endif