From 2425702f9dcfdcba6cde4b4790e4caa642a85063 Mon Sep 17 00:00:00 2001 From: jez_higgins <> Date: Thu, 18 Aug 2005 09:33:19 +0000 Subject: [PATCH] parameterised the nodeset functions --- XPath/impl/xpath_function.hpp | 94 +++++++++++++++------------- XPath/impl/xpath_function_holder.hpp | 12 ++-- 2 files changed, 58 insertions(+), 48 deletions(-) diff --git a/XPath/impl/xpath_function.hpp b/XPath/impl/xpath_function.hpp index f4e1e63f..11ebe2fc 100644 --- a/XPath/impl/xpath_function.hpp +++ b/XPath/impl/xpath_function.hpp @@ -69,60 +69,66 @@ private: //////////////////////////////// // node-set functions // number last() -class LastFn : public XPathFunction > +template +class LastFn : public XPathFunction { public: - LastFn(const std::vector > >& args) : XPathFunction >(0, 0, args) { } + LastFn(const std::vector >& args) : XPathFunction(0, 0, args) { } - virtual XPathValue* evaluate(const DOM::Node& context, - const ExecutionContext >& executionContext) const + virtual XPathValue* evaluate(const DOM::Node& context, + const ExecutionContext& executionContext) const { - return new NumericValue >(executionContext.last()); + return new NumericValue(executionContext.last()); } // evaluate }; // class LastFn // number position() -class PositionFn : public XPathFunction > +template +class PositionFn : public XPathFunction { public: - PositionFn(const std::vector > >& args) : XPathFunction >(0, 0, args) { } + PositionFn(const std::vector >& args) : XPathFunction(0, 0, args) { } - virtual XPathValue* evaluate(const DOM::Node& context, - const ExecutionContext >& executionContext) const + virtual XPathValue* evaluate(const DOM::Node& context, + const ExecutionContext& executionContext) const { - return new NumericValue >(executionContext.position()); + return new NumericValue(executionContext.position()); } // evaluate }; // class PositionFn // number count(node-set) -class CountFn : public XPathFunction > +template +class CountFn : public XPathFunction { + typedef XPathFunction baseT; public: - CountFn(const std::vector > >& args) : XPathFunction >(1, 1, args) { } + CountFn(const std::vector >& args) : XPathFunction(1, 1, args) { } - virtual XPathValue* evaluate(const DOM::Node& context, - const ExecutionContext >& executionContext) const + virtual XPathValue* evaluate(const DOM::Node& context, + const ExecutionContext& executionContext) const { - return new NumericValue >(argAsNodeSet(0, context, executionContext).size()); + return new NumericValue(baseT::argAsNodeSet(0, context, executionContext).size()); } // evaluate }; // class CountFn // node-set id(object) // string local-name(node-set?) -class LocalNameFn : public XPathFunction > +template +class LocalNameFn : public XPathFunction { + typedef XPathFunction baseT; public: - LocalNameFn(const std::vector > >& args) : XPathFunction >(0, 1, args) { } + LocalNameFn(const std::vector >& args) : XPathFunction(0, 1, args) { } - virtual XPathValue* evaluate(const DOM::Node& context, - const ExecutionContext >& executionContext) const + virtual XPathValue* evaluate(const DOM::Node& context, + const ExecutionContext& executionContext) const { - DOM::Node node; - if(argCount() == 0) + DOM::Node node; + if(baseT::argCount() == 0) node = context; else { - NodeSet ns = argAsNodeSet(0, context, executionContext); + NodeSet ns = baseT::argAsNodeSet(0, context, executionContext); if(ns.size() != 0) node = ns.top(); } // if ... @@ -133,29 +139,31 @@ public: case DOM::Node_base::ATTRIBUTE_NODE: case DOM::Node_base::ELEMENT_NODE: case DOM::Node_base::PROCESSING_INSTRUCTION_NODE: - return new StringValue >(node.hasNamespaceURI() ? node.getLocalName() : node.getNodeName()); + return new StringValue(node.hasNamespaceURI() ? node.getLocalName() : node.getNodeName()); default: // put this in to keep gcc quiet ; } // switch ... - return new StringValue >(""); + return new StringValue(""); } // evaluate }; // class LocalNameFn // string namespace-uri(node-set?) -class NamespaceURIFn : public XPathFunction > +template +class NamespaceURIFn : public XPathFunction { + typedef XPathFunction baseT; public: - NamespaceURIFn(const std::vector > >& args) : XPathFunction >(0, 1, args) { } + NamespaceURIFn(const std::vector >& args) : XPathFunction(0, 1, args) { } - virtual XPathValue* evaluate(const DOM::Node& context, - const ExecutionContext >& executionContext) const + virtual XPathValue* evaluate(const DOM::Node& context, + const ExecutionContext& executionContext) const { - DOM::Node node; - if(argCount() == 0) + DOM::Node node; + if(baseT::argCount() == 0) node = context; else { - NodeSet ns = argAsNodeSet(0, context, executionContext); + NodeSet ns = baseT::argAsNodeSet(0, context, executionContext); if(ns.size() != 0) node = ns.top(); } // if ... @@ -165,29 +173,31 @@ public: { case DOM::Node_base::ATTRIBUTE_NODE: case DOM::Node_base::ELEMENT_NODE: - return new StringValue >(node.getNamespaceURI()); + return new StringValue(node.getNamespaceURI()); default: // put this in to keep gcc quiet ; } // switch ... - return new StringValue >(""); + return new StringValue(""); } // evaluate }; // class NamespaceURIFn // string name(node-set?) -class NameFn : public XPathFunction > +template +class NameFn : public XPathFunction { + typedef XPathFunction baseT; public: - NameFn(const std::vector > >& args) : XPathFunction >(0, 1, args) { } + NameFn(const std::vector >& args) : XPathFunction(0, 1, args) { } - virtual XPathValue* evaluate(const DOM::Node& context, - const ExecutionContext >& executionContext) const + virtual XPathValue* evaluate(const DOM::Node& context, + const ExecutionContext& executionContext) const { - DOM::Node node; - if(argCount() == 0) + DOM::Node node; + if(baseT::argCount() == 0) node = context; else { - NodeSet ns = argAsNodeSet(0, context, executionContext); + NodeSet ns = baseT::argAsNodeSet(0, context, executionContext); if(ns.size() != 0) node = ns.top(); } // if ... @@ -198,11 +208,11 @@ public: case DOM::Node_base::ATTRIBUTE_NODE: case DOM::Node_base::ELEMENT_NODE: case DOM::Node_base::PROCESSING_INSTRUCTION_NODE: - return new StringValue >(node.getNodeName()); + return new StringValue(node.getNodeName()); default: // stop gcc generating a warning about unhandled enum values ; } // switch ... - return new StringValue >(""); + return new StringValue(""); } // evaluate }; // class NameFn diff --git a/XPath/impl/xpath_function_holder.hpp b/XPath/impl/xpath_function_holder.hpp index 18dee29a..f9c314b1 100644 --- a/XPath/impl/xpath_function_holder.hpp +++ b/XPath/impl/xpath_function_holder.hpp @@ -61,12 +61,12 @@ template const typename FunctionHolder::NamedFunction FunctionHolder::FunctionLookupTable[] = { // node-set functions - { "position", CreateFn }, - { "last", CreateFn }, - { "count", CreateFn }, - { "local-name", CreateFn }, - { "namespace-uri", CreateFn }, - { "name", CreateFn }, + { "position", CreateFn, string_type, string_adaptor> }, + { "last", CreateFn, string_type, string_adaptor> }, + { "count", CreateFn, string_type, string_adaptor> }, + { "local-name", CreateFn, string_type, string_adaptor> }, + { "namespace-uri", CreateFn, string_type, string_adaptor> }, + { "name", CreateFn, string_type, string_adaptor> }, // string functions {"string", CreateFn }, {"concat", CreateFn },