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 string_type& name,
|
||||||
const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs) const
|
const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs) const
|
||||||
{
|
{
|
||||||
if(!string_adaptor::empty(namespace_uri))
|
return standardFunction(namespace_uri, name, argExprs);
|
||||||
return 0;
|
|
||||||
return standardFunction(name, argExprs);
|
|
||||||
} // resolveFuncton
|
} // 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>*
|
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)
|
const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs)
|
||||||
{
|
{
|
||||||
for(const NamedFunction* fn = FunctionLookupTable; fn->name != 0; ++fn)
|
const NamedFunction* fn = findFunction(namespace_uri, name);
|
||||||
if(name == string_adaptor::construct_from_utf8(fn->name))
|
return (fn != 0) ? fn->creator(argExprs) : 0;
|
||||||
return fn->creator(argExprs);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
} // standardFunction
|
} // standardFunction
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
typedef XPathFunction<string_type, string_adaptor>* (*CreateFnPtr)(const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs);
|
typedef XPathFunction<string_type, string_adaptor>* (*CreateFnPtr)(const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs);
|
||||||
|
|
||||||
struct NamedFunction { const char* name; CreateFnPtr creator; };
|
struct NamedFunction { const char* name; CreateFnPtr creator; };
|
||||||
|
|
||||||
static const NamedFunction FunctionLookupTable[];
|
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
|
}; // class StandardXPathFunctionResolver
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
|
@ -123,7 +137,7 @@ public:
|
||||||
XPathFunction<string_type, string_adaptor>* func = 0;
|
XPathFunction<string_type, string_adaptor>* func = 0;
|
||||||
|
|
||||||
if(string_adaptor::empty(namespace_uri))
|
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)
|
if(func == 0)
|
||||||
func = context.functionResolver().resolveFunction(namespace_uri, name, argExprs);
|
func = context.functionResolver().resolveFunction(namespace_uri, name, argExprs);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ public:
|
||||||
resolveFunction(const string_type& namespace_uri,
|
resolveFunction(const string_type& namespace_uri,
|
||||||
const string_type& name,
|
const string_type& name,
|
||||||
const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs) const = 0;
|
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
|
}; // class FunctionResolver
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
|
@ -56,6 +58,11 @@ public:
|
||||||
string_adaptor::append(error, name);
|
string_adaptor::append(error, name);
|
||||||
throw UndefinedFunctionException(string_adaptor().asStdString(error));
|
throw UndefinedFunctionException(string_adaptor().asStdString(error));
|
||||||
} // resolveVariable
|
} // resolveVariable
|
||||||
|
|
||||||
|
virtual bool hasFunction(const string_type&, const string_type&) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
} // hasFunction
|
||||||
}; // NullFunctionResolver
|
}; // NullFunctionResolver
|
||||||
|
|
||||||
} // namespace XPath
|
} // namespace XPath
|
||||||
|
|
|
@ -195,6 +195,12 @@ private:
|
||||||
return 0;
|
return 0;
|
||||||
} // resolveFunction
|
} // resolveFunction
|
||||||
|
|
||||||
|
virtual bool hasFunction(const std::string& namespace_uri,
|
||||||
|
const std::string& name) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
} // hasFunction
|
||||||
|
|
||||||
// NamespaceContext
|
// NamespaceContext
|
||||||
virtual std::string namespaceURI(const std::string& prefix) const
|
virtual std::string namespaceURI(const std::string& prefix) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -90,6 +90,8 @@ public:
|
||||||
return new TestFunction<string_type, string_adaptor>(argExprs);
|
return new TestFunction<string_type, string_adaptor>(argExprs);
|
||||||
return 0;
|
return 0;
|
||||||
} // resolveFunction
|
} // resolveFunction
|
||||||
|
|
||||||
|
virtual bool hasFunction(const string_type&, const string_type& name) const { return false; }
|
||||||
}; // class TestFunctionResolver
|
}; // class TestFunctionResolver
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
|
|
|
@ -61,6 +61,8 @@ public:
|
||||||
return new TestKeyFunction<string_type, string_adaptor>(argExprs);
|
return new TestKeyFunction<string_type, string_adaptor>(argExprs);
|
||||||
return 0;
|
return 0;
|
||||||
} // resolveFunction
|
} // resolveFunction
|
||||||
|
|
||||||
|
virtual bool hasFunction(const string_type&, const string_type& name) const { return false; }
|
||||||
}; // class TestFunctionResolver
|
}; // class TestFunctionResolver
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ public:
|
||||||
return new Arabica::XPath::impl::TrueFn<string_type, string_adaptor>(argExprs);
|
return new Arabica::XPath::impl::TrueFn<string_type, string_adaptor>(argExprs);
|
||||||
return 0;
|
return 0;
|
||||||
} // resolveFunction
|
} // resolveFunction
|
||||||
|
|
||||||
|
virtual bool hasFunction(const string_type&, const string_type&) const { return false; }
|
||||||
}; // class TrueFunctionResolver
|
}; // class TrueFunctionResolver
|
||||||
|
|
||||||
template<class string_type, class string_adaptor>
|
template<class string_type, class string_adaptor>
|
||||||
|
|
Loading…
Add table
Reference in a new issue