arabica/include/XPath/impl/xpath_function_resolver.hpp

65 lines
2.2 KiB
C++
Raw Normal View History

2005-08-04 22:42:30 +02:00
#ifndef ARABICA_XPATH_FUNCTION_RESOLVER_HPP
#define ARABICA_XPATH_FUNCTION_RESOLVER_HPP
namespace Arabica
{
namespace XPath
{
2005-08-18 11:00:35 +02:00
template<class string_type, class string_adaptor> class XPathFunction;
2007-10-25 22:42:00 +02:00
template<class string_type, class string_adaptor> class XPathExpression;
2005-08-04 22:42:30 +02:00
class UndefinedFunctionException : public std::runtime_error
{
public:
UndefinedFunctionException(const std::string& thing) : std::runtime_error("The function '" + thing + "' is undefined.") { }
}; // class UndefinedFunctionException
2007-07-19 19:01:31 +02:00
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
2005-08-04 22:42:30 +02:00
class FunctionResolver
{
public:
2005-08-07 22:16:02 +02:00
virtual ~FunctionResolver() { }
2005-08-18 11:00:35 +02:00
virtual XPathFunction<string_type, string_adaptor>*
2007-07-19 19:01:31 +02:00
resolveFunction(const string_type& namespace_uri,
const string_type& name,
2007-10-25 22:42:00 +02:00
const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs) const = 0;
2005-08-04 22:42:30 +02:00
}; // class FunctionResolver
template<class string_type, class string_adaptor>
class FunctionResolverPtr : public boost::shared_ptr<FunctionResolver<string_type, string_adaptor> >
{
public:
explicit FunctionResolverPtr(FunctionResolver<string_type, string_adaptor>* fr) :
boost::shared_ptr<FunctionResolver<string_type, string_adaptor> >(fr)
{
} // FunctionResolverPtr
}; // class FunctionResolverPtr
template<class string_type, class string_adaptor>
class NullFunctionResolver : public FunctionResolver<string_type, string_adaptor>
2005-08-04 22:42:30 +02:00
{
public:
2005-08-18 11:00:35 +02:00
virtual XPathFunction<string_type, string_adaptor>*
2007-07-19 19:01:31 +02:00
resolveFunction(const string_type& namespace_uri,
const string_type& name,
2007-10-25 22:42:00 +02:00
const std::vector<XPathExpression<string_type, string_adaptor> >& argExprs) const
2005-08-04 22:42:30 +02:00
{
2007-07-19 19:01:31 +02:00
string_type error;
if(!string_adaptor::empty(namespace_uri))
{
string_adaptor::append(error, string_adaptor::construct_from_utf8("{"));
string_adaptor::append(error, namespace_uri);
string_adaptor::append(error, string_adaptor::construct_from_utf8("}"));
} // if ...
string_adaptor::append(error, name);
throw UndefinedFunctionException(string_adaptor().asStdString(error));
2005-08-04 22:42:30 +02:00
} // resolveVariable
}; // NullFunctionResolver
} // namespace XPath
} // namespace Arabica
#endif