mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-30 08:38:15 +01:00
add hasFunction to FunctionResolver interface
This commit is contained in:
parent
9d7384c8ef
commit
c35185a64c
6 changed files with 44 additions and 11 deletions
|
@ -26,29 +26,43 @@ public:
|
|||
const string_type& name,
|
||||
const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs) const
|
||||
{
|
||||
if(!string_adaptor::empty(namespace_uri))
|
||||
return 0;
|
||||
return standardFunction(name, argExprs);
|
||||
return standardFunction(namespace_uri, name, argExprs);
|
||||
} // resolveFuncton
|
||||
|
||||
virtual bool hasFunction(const string_type& namespace_uri,
|
||||
const string_type& name) const
|
||||
{
|
||||
return findFunction(namespace_uri, name);
|
||||
} // hasFunction
|
||||
|
||||
static XPathFunction<string_type, string_adaptor>*
|
||||
standardFunction(const string_type& name,
|
||||
standardFunction(const string_type& namespace_uri,
|
||||
const string_type& name,
|
||||
const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs)
|
||||
{
|
||||
for(const NamedFunction* fn = FunctionLookupTable; fn->name != 0; ++fn)
|
||||
if(name == string_adaptor::construct_from_utf8(fn->name))
|
||||
return fn->creator(argExprs);
|
||||
|
||||
return 0;
|
||||
const NamedFunction* fn = findFunction(namespace_uri, name);
|
||||
return (fn != 0) ? fn->creator(argExprs) : 0;
|
||||
} // standardFunction
|
||||
|
||||
private:
|
||||
|
||||
typedef XPathFunction<string_type, string_adaptor>* (*CreateFnPtr)(const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs);
|
||||
|
||||
struct NamedFunction { const char* name; CreateFnPtr creator; };
|
||||
|
||||
static const NamedFunction FunctionLookupTable[];
|
||||
|
||||
static const NamedFunction* findFunction(const string_type& namespace_uri,
|
||||
const string_type& name)
|
||||
{
|
||||
if(!string_adaptor::empty(namespace_uri))
|
||||
return 0;
|
||||
|
||||
for(const NamedFunction* fn = FunctionLookupTable; fn->name != 0; ++fn)
|
||||
if(name == string_adaptor::construct_from_utf8(fn->name))
|
||||
return fn;
|
||||
|
||||
return 0;
|
||||
} // findFunction
|
||||
}; // class StandardXPathFunctionResolver
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
|
@ -123,7 +137,7 @@ public:
|
|||
XPathFunction<string_type, string_adaptor>* func = 0;
|
||||
|
||||
if(string_adaptor::empty(namespace_uri))
|
||||
func = StandardXPathFunctionResolver<string_type, string_adaptor>::standardFunction(name, argExprs);
|
||||
func = StandardXPathFunctionResolver<string_type, string_adaptor>::standardFunction(namespace_uri, name, argExprs);
|
||||
if(func == 0)
|
||||
func = context.functionResolver().resolveFunction(namespace_uri, name, argExprs);
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ public:
|
|||
resolveFunction(const string_type& namespace_uri,
|
||||
const string_type& name,
|
||||
const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs) const = 0;
|
||||
|
||||
virtual bool hasFunction(const string_type& namespace_uri, const string_type& name) const = 0;
|
||||
}; // class FunctionResolver
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
|
@ -56,6 +58,11 @@ public:
|
|||
string_adaptor::append(error, name);
|
||||
throw UndefinedFunctionException(string_adaptor().asStdString(error));
|
||||
} // resolveVariable
|
||||
|
||||
virtual bool hasFunction(const string_type&, const string_type&) const
|
||||
{
|
||||
return false;
|
||||
} // hasFunction
|
||||
}; // NullFunctionResolver
|
||||
|
||||
} // namespace XPath
|
||||
|
|
|
@ -195,6 +195,12 @@ private:
|
|||
return 0;
|
||||
} // resolveFunction
|
||||
|
||||
virtual bool hasFunction(const std::string& namespace_uri,
|
||||
const std::string& name) const
|
||||
{
|
||||
return false;
|
||||
} // hasFunction
|
||||
|
||||
// NamespaceContext
|
||||
virtual std::string namespaceURI(const std::string& prefix) const
|
||||
{
|
||||
|
|
|
@ -90,6 +90,8 @@ public:
|
|||
return new TestFunction<string_type, string_adaptor>(argExprs);
|
||||
return 0;
|
||||
} // resolveFunction
|
||||
|
||||
virtual bool hasFunction(const string_type&, const string_type& name) const { return false; }
|
||||
}; // class TestFunctionResolver
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
|
|
|
@ -61,6 +61,8 @@ public:
|
|||
return new TestKeyFunction<string_type, string_adaptor>(argExprs);
|
||||
return 0;
|
||||
} // resolveFunction
|
||||
|
||||
virtual bool hasFunction(const string_type&, const string_type& name) const { return false; }
|
||||
}; // class TestFunctionResolver
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ public:
|
|||
return new Arabica::XPath::impl::TrueFn<string_type, string_adaptor>(argExprs);
|
||||
return 0;
|
||||
} // resolveFunction
|
||||
|
||||
virtual bool hasFunction(const string_type&, const string_type&) const { return false; }
|
||||
}; // class TrueFunctionResolver
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
|
|
Loading…
Add table
Reference in a new issue