parameterised RelativeLocationPath and AbsoluteLocationPath

This commit is contained in:
jez_higgins 2005-08-18 21:51:02 +00:00
parent 04bcf0b107
commit 9000066ce4
2 changed files with 25 additions and 23 deletions

View file

@ -371,20 +371,20 @@ namespace XPath
template<class string_type, class string_adaptor> template<class string_type, class string_adaptor>
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context) XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{ {
return new AbsoluteLocationPath(createStepList(i->children.begin(), i->children.end(), context)); return new AbsoluteLocationPath<string_type, string_adaptor>(createStepList(i->children.begin(), i->children.end(), context));
} // createAbsoluteLocationPath } // createAbsoluteLocationPath
template<class string_type, class string_adaptor> template<class string_type, class string_adaptor>
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context) XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{ {
return new RelativeLocationPath(createStepList(i->children.begin(), i->children.end(), context)); return new RelativeLocationPath<string_type, string_adaptor>(createStepList(i->children.begin(), i->children.end(), context));
} // createRelativeLocationPath } // createRelativeLocationPath
template<class string_type, class string_adaptor> template<class string_type, class string_adaptor>
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createSingleStepRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context) XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createSingleStepRelativeLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{ {
node_iter_t n = i; node_iter_t n = i;
return new RelativeLocationPath(StepFactory<string_type, string_adaptor>::createStep(n, context)); return new RelativeLocationPath<string_type, string_adaptor>(StepFactory<string_type, string_adaptor>::createStep(n, context));
} // createSingleStepRelativeLocationPath } // createSingleStepRelativeLocationPath
template<class string_type, class string_adaptor> template<class string_type, class string_adaptor>
@ -508,7 +508,7 @@ template<class string_type, class string_adaptor>
XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createSingleStepAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context) XPathExpression<string_type, string_adaptor>* XPath<string_type, string_adaptor>::createSingleStepAbsoluteLocationPath(node_iter_t const& i, CompilationContext<string_type, string_adaptor>& context)
{ {
node_iter_t n = i; node_iter_t n = i;
return new AbsoluteLocationPath(StepFactory<string_type, string_adaptor>::createStep(n, context)); return new AbsoluteLocationPath<string_type, string_adaptor>(StepFactory<string_type, string_adaptor>::createStep(n, context));
} // createSingleStepAbsoluteLocationPath } // createSingleStepAbsoluteLocationPath
template<class string_type, class string_adaptor> template<class string_type, class string_adaptor>

View file

@ -373,51 +373,53 @@ private:
StepFactory(); StepFactory();
}; // class StepFactory }; // class StepFactory
class RelativeLocationPath : public XPathExpression<std::string, Arabica::default_string_adaptor<std::string> > template<class string_type, class string_adaptor>
class RelativeLocationPath : public XPathExpression<string_type, string_adaptor>
{ {
public: public:
RelativeLocationPath(StepExpression<std::string, Arabica::default_string_adaptor<std::string> >* step) : steps_() { steps_.push_back(step); } RelativeLocationPath(StepExpression<string_type, string_adaptor>* step) : steps_() { steps_.push_back(step); }
RelativeLocationPath(const StepList<std::string, Arabica::default_string_adaptor<std::string> >& steps) : steps_(steps) { } RelativeLocationPath(const StepList<string_type, string_adaptor>& steps) : steps_(steps) { }
virtual ~RelativeLocationPath() virtual ~RelativeLocationPath()
{ {
for(StepList<std::string, Arabica::default_string_adaptor<std::string> >::const_iterator i = steps_.begin(); i != steps_.end(); ++i) for(StepList<string_type, string_adaptor>::const_iterator i = steps_.begin(); i != steps_.end(); ++i)
delete *i; delete *i;
} // ~LocationPath } // ~LocationPath
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context, const ExecutionContext<string_type, string_adaptor>& executionContext) const
{ {
NodeSet<std::string> nodes; NodeSet<string_type> nodes;
nodes.push_back(context); nodes.push_back(context);
for(StepList<std::string, Arabica::default_string_adaptor<std::string> >::const_iterator i = steps_.begin(); i != steps_.end(); ++i) for(StepList<string_type, string_adaptor>::const_iterator i = steps_.begin(); i != steps_.end(); ++i)
{ {
XPathValuePtr<std::string> v = (*i)->evaluate(nodes, executionContext); XPathValuePtr<string_type> v = (*i)->evaluate(nodes, executionContext);
nodes = v->asNodeSet(); nodes = v->asNodeSet();
} // for ... } // for ...
return XPathValuePtr<std::string>(new NodeSetValue<std::string, Arabica::default_string_adaptor<std::string> >(nodes)); return XPathValuePtr<string_type>(new NodeSetValue<string_type, string_adaptor>(nodes));
} // do_evaluate } // do_evaluate
private: private:
StepList<std::string, Arabica::default_string_adaptor<std::string> > steps_; StepList<string_type, string_adaptor> steps_;
}; // LocationPath }; // LocationPath
class AbsoluteLocationPath : public RelativeLocationPath template<class string_type, class string_adaptor>
class AbsoluteLocationPath : public RelativeLocationPath<string_type, string_adaptor>
{ {
public: public:
AbsoluteLocationPath(StepExpression<std::string, Arabica::default_string_adaptor<std::string> >* step) : RelativeLocationPath(step) { } AbsoluteLocationPath(StepExpression<string_type, string_adaptor>* step) : RelativeLocationPath<string_type, string_adaptor>(step) { }
AbsoluteLocationPath(const StepList<std::string, Arabica::default_string_adaptor<std::string> >& steps) : RelativeLocationPath(steps) { } AbsoluteLocationPath(const StepList<string_type, string_adaptor>& steps) : RelativeLocationPath<string_type, string_adaptor>(steps) { }
virtual XPathValuePtr<std::string> evaluate(const DOM::Node<std::string>& context, const ExecutionContext<std::string, Arabica::default_string_adaptor<std::string> >& executionContext) const virtual XPathValuePtr<string_type> evaluate(const DOM::Node<string_type>& context, const ExecutionContext<string_type, string_adaptor>& executionContext) const
{ {
int type = context.getNodeType(); int type = context.getNodeType();
if((type == DOM::Node<std::string>::DOCUMENT_NODE) || if((type == DOM::Node<string_type>::DOCUMENT_NODE) ||
(type == DOM::Node<std::string>::DOCUMENT_FRAGMENT_NODE)) (type == DOM::Node<string_type>::DOCUMENT_FRAGMENT_NODE))
return RelativeLocationPath::evaluate(context, executionContext); return RelativeLocationPath<string_type, string_adaptor>::evaluate(context, executionContext);
DOM::Document<std::string> document = context.getOwnerDocument(); DOM::Document<string_type> document = context.getOwnerDocument();
return RelativeLocationPath::evaluate(document, executionContext); return RelativeLocationPath<string_type, string_adaptor>::evaluate(document, executionContext);
} // evaluate } // evaluate
}; // class AbsoluteLocationPath }; // class AbsoluteLocationPath