arabica/XPath/impl/xpath_variable_resolver.hpp

51 lines
1.4 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
template<class string_type, class string_adaptor>
2005-08-04 22:42:30 +02:00
class VariableResolver
{
public:
virtual ~VariableResolver() { }
virtual XPathValuePtr<string_type> resolveVariable(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 XPathValuePtr<string_type> resolveVariable(const string_type& name) const
2005-08-04 22:42:30 +02:00
{
throw UnboundVariableException(string_adaptor().asStdString(name));
2005-08-04 22:42:30 +02:00
} // resolveVariable
}; // NullVariableResolver
} // namespace XPath
} // namespace Arabica
#endif