From 9000066ce4f94a7c9e089da30dacbeec2f0c7d81 Mon Sep 17 00:00:00 2001 From: jez_higgins <> Date: Thu, 18 Aug 2005 21:51:02 +0000 Subject: [PATCH] parameterised RelativeLocationPath and AbsoluteLocationPath --- XPath/impl/xpath_parser.hpp | 8 ++++---- XPath/impl/xpath_step.hpp | 40 +++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/XPath/impl/xpath_parser.hpp b/XPath/impl/xpath_parser.hpp index 4154fdc2..2d65139d 100644 --- a/XPath/impl/xpath_parser.hpp +++ b/XPath/impl/xpath_parser.hpp @@ -371,20 +371,20 @@ namespace XPath template XPathExpression* XPath::createAbsoluteLocationPath(node_iter_t const& i, CompilationContext& context) { - return new AbsoluteLocationPath(createStepList(i->children.begin(), i->children.end(), context)); + return new AbsoluteLocationPath(createStepList(i->children.begin(), i->children.end(), context)); } // createAbsoluteLocationPath template XPathExpression* XPath::createRelativeLocationPath(node_iter_t const& i, CompilationContext& context) { - return new RelativeLocationPath(createStepList(i->children.begin(), i->children.end(), context)); + return new RelativeLocationPath(createStepList(i->children.begin(), i->children.end(), context)); } // createRelativeLocationPath template XPathExpression* XPath::createSingleStepRelativeLocationPath(node_iter_t const& i, CompilationContext& context) { node_iter_t n = i; - return new RelativeLocationPath(StepFactory::createStep(n, context)); + return new RelativeLocationPath(StepFactory::createStep(n, context)); } // createSingleStepRelativeLocationPath template @@ -508,7 +508,7 @@ template XPathExpression* XPath::createSingleStepAbsoluteLocationPath(node_iter_t const& i, CompilationContext& context) { node_iter_t n = i; - return new AbsoluteLocationPath(StepFactory::createStep(n, context)); + return new AbsoluteLocationPath(StepFactory::createStep(n, context)); } // createSingleStepAbsoluteLocationPath template diff --git a/XPath/impl/xpath_step.hpp b/XPath/impl/xpath_step.hpp index 709a7798..fc90952a 100644 --- a/XPath/impl/xpath_step.hpp +++ b/XPath/impl/xpath_step.hpp @@ -373,51 +373,53 @@ private: StepFactory(); }; // class StepFactory -class RelativeLocationPath : public XPathExpression > +template +class RelativeLocationPath : public XPathExpression { public: - RelativeLocationPath(StepExpression >* step) : steps_() { steps_.push_back(step); } - RelativeLocationPath(const StepList >& steps) : steps_(steps) { } + RelativeLocationPath(StepExpression* step) : steps_() { steps_.push_back(step); } + RelativeLocationPath(const StepList& steps) : steps_(steps) { } virtual ~RelativeLocationPath() { - for(StepList >::const_iterator i = steps_.begin(); i != steps_.end(); ++i) + for(StepList::const_iterator i = steps_.begin(); i != steps_.end(); ++i) delete *i; } // ~LocationPath - virtual XPathValuePtr evaluate(const DOM::Node& context, const ExecutionContext >& executionContext) const + virtual XPathValuePtr evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { - NodeSet nodes; + NodeSet nodes; nodes.push_back(context); - for(StepList >::const_iterator i = steps_.begin(); i != steps_.end(); ++i) + for(StepList::const_iterator i = steps_.begin(); i != steps_.end(); ++i) { - XPathValuePtr v = (*i)->evaluate(nodes, executionContext); + XPathValuePtr v = (*i)->evaluate(nodes, executionContext); nodes = v->asNodeSet(); } // for ... - return XPathValuePtr(new NodeSetValue >(nodes)); + return XPathValuePtr(new NodeSetValue(nodes)); } // do_evaluate private: - StepList > steps_; + StepList steps_; }; // LocationPath -class AbsoluteLocationPath : public RelativeLocationPath +template +class AbsoluteLocationPath : public RelativeLocationPath { public: - AbsoluteLocationPath(StepExpression >* step) : RelativeLocationPath(step) { } - AbsoluteLocationPath(const StepList >& steps) : RelativeLocationPath(steps) { } + AbsoluteLocationPath(StepExpression* step) : RelativeLocationPath(step) { } + AbsoluteLocationPath(const StepList& steps) : RelativeLocationPath(steps) { } - virtual XPathValuePtr evaluate(const DOM::Node& context, const ExecutionContext >& executionContext) const + virtual XPathValuePtr evaluate(const DOM::Node& context, const ExecutionContext& executionContext) const { int type = context.getNodeType(); - if((type == DOM::Node::DOCUMENT_NODE) || - (type == DOM::Node::DOCUMENT_FRAGMENT_NODE)) - return RelativeLocationPath::evaluate(context, executionContext); + if((type == DOM::Node::DOCUMENT_NODE) || + (type == DOM::Node::DOCUMENT_FRAGMENT_NODE)) + return RelativeLocationPath::evaluate(context, executionContext); - DOM::Document document = context.getOwnerDocument(); - return RelativeLocationPath::evaluate(document, executionContext); + DOM::Document document = context.getOwnerDocument(); + return RelativeLocationPath::evaluate(document, executionContext); } // evaluate }; // class AbsoluteLocationPath