More work on optimising expression evaluation.

This commit is contained in:
jez 2009-07-31 17:44:54 +01:00
parent 1f12f0a2f0
commit 9d72ecf556
6 changed files with 55 additions and 35 deletions

View file

@ -3,6 +3,7 @@
#include <functional>
#include "xpath_value.hpp"
#include "xpath_expression_impl.hpp"
namespace Arabica
{

View file

@ -282,33 +282,6 @@ private:
XPathExpression_impl<string_type, string_adaptor>* rhs_;
}; // class BinaryExpression
template<class string_type, class string_adaptor>
class NumericExpression : virtual public XPathExpression_impl<string_type, string_adaptor>
{
public:
NumericExpression() { }
virtual ValueType type() const { return NUMBER; }
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return NumericValue<string_type, string_adaptor>::createValue(doEvaluateAsNumber(context, executionContext));
} // evaluate
virtual double evaluateAsNumber(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return doEvaluateAsNumber(context, executionContext);
}
protected:
virtual double doEvaluateAsNumber(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const = 0;
~NumericExpression() { }
}; // class UnaryExpression
} // namespace impl
} // namespace XPath
} // namespace Arabica

View file

@ -0,0 +1,45 @@
#ifndef ARABICA_XPATHIC_XPATH_EXPRESSION_IMPL_H
#define ARABICA_XPATHIC_XPATH_EXPRESSION_IMPL_H
#include "xpath_expression.hpp"
namespace Arabica
{
namespace XPath
{
namespace impl
{
template<class string_type, class string_adaptor>
class NumericExpression : virtual public XPathExpression_impl<string_type, string_adaptor>
{
public:
NumericExpression() { }
virtual ValueType type() const { return NUMBER; }
virtual XPathValue<string_type, string_adaptor> evaluate(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return NumericValue<string_type, string_adaptor>::createValue(doEvaluateAsNumber(context, executionContext));
} // evaluate
virtual double evaluateAsNumber(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return doEvaluateAsNumber(context, executionContext);
} // evaluateAsNumber
protected:
virtual double doEvaluateAsNumber(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const = 0;
~NumericExpression() { }
}; // class NumericExpression
} // namespace impl
} // namespace XPath
} // namespace Arabica
#endif

View file

@ -81,7 +81,7 @@ class BooleanXPathFunction : public XPathFunction<string_type, string_adaptor>
{
public:
BooleanXPathFunction(int minArgs, int maxArgs, const std::vector<XPathExpression<string_type, string_adaptor> >& args) :
XPathFunction(minArgs, maxArgs, args) { }
XPathFunction<string_type, string_adaptor>(minArgs, maxArgs, args) { }
virtual ValueType type() const { return BOOL; }
@ -101,7 +101,7 @@ class NumericXPathFunction : public XPathFunction<string_type, string_adaptor>
{
public:
NumericXPathFunction(int minArgs, int maxArgs, const std::vector<XPathExpression<string_type, string_adaptor> >& args) :
XPathFunction(minArgs, maxArgs, args) { }
XPathFunction<string_type, string_adaptor>(minArgs, maxArgs, args) { }
virtual ValueType type() const { return NUMBER; }
@ -121,7 +121,7 @@ class StringXPathFunction : public XPathFunction<string_type, string_adaptor>
{
public:
StringXPathFunction(int minArgs, int maxArgs, const std::vector<XPathExpression<string_type, string_adaptor> >& args) :
XPathFunction(minArgs, maxArgs, args) { }
XPathFunction<string_type, string_adaptor>(minArgs, maxArgs, args) { }
virtual ValueType type() const { return STRING; }
@ -141,7 +141,7 @@ class NodeSetXPathFunction : public XPathFunction<string_type, string_adaptor>
{
public:
NodeSetXPathFunction(int minArgs, int maxArgs, const std::vector<XPathExpression<string_type, string_adaptor> >& args) :
XPathFunction(minArgs, maxArgs, args) { }
XPathFunction<string_type, string_adaptor>(minArgs, maxArgs, args) { }
virtual ValueType type() const { return NODE_SET; }

View file

@ -2,7 +2,7 @@
#define ARABICA_XPATH_FUNCTION_HOLDER_HPP
#include <boost/shared_ptr.hpp>
#include "xpath_value.hpp"
#include "xpath_expression.hpp"
#include "xpath_function.hpp"
namespace Arabica

View file

@ -7,7 +7,6 @@
#include <vector>
#include <Arabica/StringAdaptor.hpp>
#include "xpath_object.hpp"
#include "xpath_expression.hpp"
namespace Arabica
{
@ -15,7 +14,9 @@ namespace XPath
{
template<class string_type, class string_adaptor>
class Value_base : public XPathValue_impl<string_type, string_adaptor>, public XPathExpression_impl<string_type, string_adaptor>
class Value_base :
public XPathExpression_impl<string_type, string_adaptor>,
public XPathValue_impl<string_type, string_adaptor>
{
typedef XPathValue_impl<string_type, string_adaptor> XPathValue_implT;
using XPathValue_implT::asBool;
@ -34,7 +35,7 @@ public:
virtual NodeSet<string_type, string_adaptor> evaluateAsNodeSet(const DOM::Node<string_type, string_adaptor>& context) { return asNodeSet(); }
virtual bool evaluateAsBool(const DOM::Node<string_type, string_adaptor>& context,
const ExecutionContext<string_type, string_adaptor>& executionContext) const
const ExecutionContext<string_type, string_adaptor>& executionContext) const
{
return asBool();
}