mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-17 18:12:04 +01:00
parameterised VariableResolver on string_adaptor as well as string_type
This commit is contained in:
parent
155ed52bba
commit
d8bd7c8968
5 changed files with 23 additions and 19 deletions
|
@ -20,7 +20,7 @@ xpath_execution_context.hpp
|
|||
xpath_expression.hpp
|
||||
xpath_function.hpp
|
||||
xpath_function_holder.hpp
|
||||
xpath_function_resolver.hpp
|
||||
DONE - xpath_function_resolver.hpp
|
||||
xpath_grammar.hpp
|
||||
xpath_logical.hpp
|
||||
DONE - xpath_namespace_context.hpp
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef ARABICA_XPATH_EXECUTION_CONTEXT_HPP
|
||||
#define ARABICA_XPATH_EXECUTION_CONTEXT_HPP
|
||||
|
||||
#include <Utils/StringAdaptor.h>
|
||||
#include "xpath_variable_resolver.hpp"
|
||||
#include "xpath_resolver_holder.hpp"
|
||||
|
||||
|
@ -30,14 +31,14 @@ public:
|
|||
|
||||
void setPosition(unsigned int pos) { position_ = pos; }
|
||||
|
||||
const VariableResolver<std::string>& variableResolver() const { return variableResolver_.get(); }
|
||||
void setVariableResolver(const VariableResolver<std::string>& resolver) { variableResolver_.set(resolver); }
|
||||
void setVariableResolver(VariableResolverPtr<std::string>& resolver) { variableResolver_.set(resolver); }
|
||||
const VariableResolver<std::string, Arabica::default_string_adaptor<std::string> >& variableResolver() const { return variableResolver_.get(); }
|
||||
void setVariableResolver(const VariableResolver<std::string, Arabica::default_string_adaptor<std::string> >& resolver) { variableResolver_.set(resolver); }
|
||||
void setVariableResolver(VariableResolverPtr<std::string, Arabica::default_string_adaptor<std::string> >& resolver) { variableResolver_.set(resolver); }
|
||||
|
||||
private:
|
||||
size_t position_;
|
||||
size_t last_;
|
||||
ResolverHolder<const VariableResolver<std::string> > variableResolver_;
|
||||
ResolverHolder<const VariableResolver<std::string, Arabica::default_string_adaptor<std::string> > > variableResolver_;
|
||||
|
||||
ExecutionContext(const ExecutionContext&);
|
||||
ExecutionContext& operator=(const ExecutionContext&);
|
||||
|
|
|
@ -87,10 +87,10 @@ public:
|
|||
const NamespaceContext<string_type, string_adaptor>& getNamespaceContext() const { return namespaceContext_.get(); }
|
||||
void resetNamespaceContext() { namespaceContext_.set(NamespaceContextPtr<string_type, string_adaptor>(new NullNamespaceContext<string_type, string_adaptor>())); }
|
||||
|
||||
void setVariableResolver(const VariableResolver<string_type>& variableResolver) { variableResolver_.set(variableResolver); }
|
||||
void setVariableResolver(VariableResolverPtr<string_type> variableResolver) { variableResolver_.set(variableResolver); }
|
||||
const VariableResolver<string_type>& getVariableResolver() const { return variableResolver_.get(); }
|
||||
void resetVariableResolver() { variableResolver_.set(VariableResolverPtr<string_type>(new NullVariableResolver<string_type>())); }
|
||||
void setVariableResolver(const VariableResolver<string_type, string_adaptor>& variableResolver) { variableResolver_.set(variableResolver); }
|
||||
void setVariableResolver(VariableResolverPtr<string_type, string_adaptor> variableResolver) { variableResolver_.set(variableResolver); }
|
||||
const VariableResolver<string_type, string_adaptor>& getVariableResolver() const { return variableResolver_.get(); }
|
||||
void resetVariableResolver() { variableResolver_.set(VariableResolverPtr<string_type, string_adaptor>(new NullVariableResolver<string_type, string_adaptor>())); }
|
||||
|
||||
void setFunctionResolver(const FunctionResolver<string_type, string_adaptor>& functionResolver) { functionResolver_.set(functionResolver); }
|
||||
void setFunctionResolver(FunctionResolverPtr<string_type, string_adaptor> functionResolver) { functionResolver_.set(functionResolver); }
|
||||
|
@ -136,7 +136,7 @@ private:
|
|||
xpath_grammar_expr xpathge_;
|
||||
|
||||
ResolverHolder<const NamespaceContext<string_type, string_adaptor> > namespaceContext_;
|
||||
ResolverHolder<const VariableResolver<string_type> > variableResolver_;
|
||||
ResolverHolder<const VariableResolver<string_type, string_adaptor> > variableResolver_;
|
||||
ResolverHolder<const FunctionResolver<string_type, string_adaptor> > functionResolver_;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -15,7 +15,7 @@ public:
|
|||
UnboundVariableException(const std::string& thing) : std::runtime_error("The variable '" + thing + "' is undefined.") { }
|
||||
}; // class UnboundVariableException
|
||||
|
||||
template<class string_type>
|
||||
template<class string_type, class string_adaptor>
|
||||
class VariableResolver
|
||||
{
|
||||
public:
|
||||
|
@ -24,20 +24,23 @@ public:
|
|||
virtual XPathValuePtr<string_type> resolveVariable(const string_type& name) const = 0;
|
||||
}; // class VariableResolver
|
||||
|
||||
template<class string_type>
|
||||
class VariableResolverPtr : public boost::shared_ptr<VariableResolver<string_type> >
|
||||
template<class string_type, class string_adaptor>
|
||||
class VariableResolverPtr : public boost::shared_ptr<VariableResolver<string_type, string_adaptor> >
|
||||
{
|
||||
public:
|
||||
explicit VariableResolverPtr(VariableResolver<string_type>* vr) : boost::shared_ptr<VariableResolver<string_type> >(vr) { }
|
||||
explicit VariableResolverPtr(VariableResolver<string_type, string_adaptor>* vr) :
|
||||
boost::shared_ptr<VariableResolver<string_type, string_adaptor> >(vr)
|
||||
{
|
||||
} // VariableResolverPtr
|
||||
}; // class VariableResolverPtr
|
||||
|
||||
template<class string_type>
|
||||
class NullVariableResolver : public VariableResolver<string_type>
|
||||
template<class string_type, class string_adaptor>
|
||||
class NullVariableResolver : public VariableResolver<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
virtual XPathValuePtr<string_type> resolveVariable(const string_type& name) const
|
||||
{
|
||||
throw UnboundVariableException(name);
|
||||
throw UnboundVariableException(string_adaptor().asStdString(name));
|
||||
} // resolveVariable
|
||||
}; // NullVariableResolver
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace Arabica::XPath;
|
||||
|
||||
class StringVariableResolver : public VariableResolver<std::string>
|
||||
class StringVariableResolver : public VariableResolver<std::string, Arabica::default_string_adaptor<std::string> >
|
||||
{
|
||||
public:
|
||||
virtual XPathValuePtr<std::string> resolveVariable(const std::string& name) const
|
||||
|
@ -31,7 +31,7 @@ private:
|
|||
VarMap map_;
|
||||
}; // StringVariableResolver
|
||||
|
||||
class NodeSetVariableResolver : public VariableResolver<std::string>
|
||||
class NodeSetVariableResolver : public VariableResolver<std::string, Arabica::default_string_adaptor<std::string> >
|
||||
{
|
||||
public:
|
||||
virtual XPathValuePtr<std::string> resolveVariable(const std::string& name) const
|
||||
|
|
Loading…
Reference in a new issue