arabica/include/XPath/impl/xpath_variable_resolver.hpp

61 lines
2 KiB
C++
Raw Normal View History

2005-08-04 22:42:30 +02:00
#ifndef ARABICA_XPATH_VARIABLE_RESOLVER_HPP
#define ARABICA_XPATH_VARIABLE_RESOLVER_HPP
2005-08-05 23:02:24 +02:00
#include <stdexcept>
#include "xpath_object.hpp"
2005-08-04 22:42:30 +02:00
namespace Arabica
{
namespace XPath
{
class UnboundVariableException : public std::runtime_error
{
public:
UnboundVariableException(const std::string& thing) : std::runtime_error("The variable '" + thing + "' is undefined.") { }
}; // class UnboundVariableException
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 VariableResolver
{
public:
virtual ~VariableResolver() { }
virtual XPathValue<string_type, string_adaptor> resolveVariable(const string_type& namespace_uri_,
2007-07-19 19:01:31 +02:00
const string_type& name) const = 0;
2005-08-04 22:42:30 +02:00
}; // class VariableResolver
template<class string_type, class string_adaptor>
class VariableResolverPtr : public boost::shared_ptr<VariableResolver<string_type, string_adaptor> >
{
public:
explicit VariableResolverPtr(VariableResolver<string_type, string_adaptor>* vr) :
boost::shared_ptr<VariableResolver<string_type, string_adaptor> >(vr)
{
} // VariableResolverPtr
}; // class VariableResolverPtr
2005-08-04 22:42:30 +02:00
template<class string_type, class string_adaptor>
class NullVariableResolver : public VariableResolver<string_type, string_adaptor>
2005-08-04 22:42:30 +02:00
{
public:
virtual XPathValue<string_type, string_adaptor> resolveVariable(const string_type& namespace_uri,
2007-07-19 19:01:31 +02:00
const string_type& name) 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 UnboundVariableException(string_adaptor().asStdString(error));
2005-08-04 22:42:30 +02:00
} // resolveVariable
}; // NullVariableResolver
} // namespace XPath
} // namespace Arabica
#endif