parameterised VariableResolver on string_adaptor as well as string_type

This commit is contained in:
jez_higgins 2005-08-17 09:17:18 +00:00
parent 155ed52bba
commit d8bd7c8968
5 changed files with 23 additions and 19 deletions

View file

@ -20,7 +20,7 @@ xpath_execution_context.hpp
xpath_expression.hpp xpath_expression.hpp
xpath_function.hpp xpath_function.hpp
xpath_function_holder.hpp xpath_function_holder.hpp
xpath_function_resolver.hpp DONE - xpath_function_resolver.hpp
xpath_grammar.hpp xpath_grammar.hpp
xpath_logical.hpp xpath_logical.hpp
DONE - xpath_namespace_context.hpp DONE - xpath_namespace_context.hpp

View file

@ -1,6 +1,7 @@
#ifndef ARABICA_XPATH_EXECUTION_CONTEXT_HPP #ifndef ARABICA_XPATH_EXECUTION_CONTEXT_HPP
#define ARABICA_XPATH_EXECUTION_CONTEXT_HPP #define ARABICA_XPATH_EXECUTION_CONTEXT_HPP
#include <Utils/StringAdaptor.h>
#include "xpath_variable_resolver.hpp" #include "xpath_variable_resolver.hpp"
#include "xpath_resolver_holder.hpp" #include "xpath_resolver_holder.hpp"
@ -30,14 +31,14 @@ public:
void setPosition(unsigned int pos) { position_ = pos; } void setPosition(unsigned int pos) { position_ = pos; }
const VariableResolver<std::string>& variableResolver() const { return variableResolver_.get(); } const VariableResolver<std::string, Arabica::default_string_adaptor<std::string> >& variableResolver() const { return variableResolver_.get(); }
void setVariableResolver(const VariableResolver<std::string>& resolver) { variableResolver_.set(resolver); } void setVariableResolver(const VariableResolver<std::string, Arabica::default_string_adaptor<std::string> >& resolver) { variableResolver_.set(resolver); }
void setVariableResolver(VariableResolverPtr<std::string>& resolver) { variableResolver_.set(resolver); } void setVariableResolver(VariableResolverPtr<std::string, Arabica::default_string_adaptor<std::string> >& resolver) { variableResolver_.set(resolver); }
private: private:
size_t position_; size_t position_;
size_t last_; 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(const ExecutionContext&);
ExecutionContext& operator=(const ExecutionContext&); ExecutionContext& operator=(const ExecutionContext&);

View file

@ -87,10 +87,10 @@ public:
const NamespaceContext<string_type, string_adaptor>& getNamespaceContext() const { return namespaceContext_.get(); } 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 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(const VariableResolver<string_type, string_adaptor>& variableResolver) { variableResolver_.set(variableResolver); }
void setVariableResolver(VariableResolverPtr<string_type> variableResolver) { variableResolver_.set(variableResolver); } void setVariableResolver(VariableResolverPtr<string_type, string_adaptor> variableResolver) { variableResolver_.set(variableResolver); }
const VariableResolver<string_type>& getVariableResolver() const { return variableResolver_.get(); } const VariableResolver<string_type, string_adaptor>& getVariableResolver() const { return variableResolver_.get(); }
void resetVariableResolver() { variableResolver_.set(VariableResolverPtr<string_type>(new NullVariableResolver<string_type>())); } 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(const FunctionResolver<string_type, string_adaptor>& functionResolver) { functionResolver_.set(functionResolver); }
void setFunctionResolver(FunctionResolverPtr<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_; xpath_grammar_expr xpathge_;
ResolverHolder<const NamespaceContext<string_type, string_adaptor> > namespaceContext_; 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_; ResolverHolder<const FunctionResolver<string_type, string_adaptor> > functionResolver_;
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View file

@ -15,7 +15,7 @@ public:
UnboundVariableException(const std::string& thing) : std::runtime_error("The variable '" + thing + "' is undefined.") { } UnboundVariableException(const std::string& thing) : std::runtime_error("The variable '" + thing + "' is undefined.") { }
}; // class UnboundVariableException }; // class UnboundVariableException
template<class string_type> template<class string_type, class string_adaptor>
class VariableResolver class VariableResolver
{ {
public: public:
@ -24,20 +24,23 @@ public:
virtual XPathValuePtr<string_type> resolveVariable(const string_type& name) const = 0; virtual XPathValuePtr<string_type> resolveVariable(const string_type& name) const = 0;
}; // class VariableResolver }; // class VariableResolver
template<class string_type> template<class string_type, class string_adaptor>
class VariableResolverPtr : public boost::shared_ptr<VariableResolver<string_type> > class VariableResolverPtr : public boost::shared_ptr<VariableResolver<string_type, string_adaptor> >
{ {
public: 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 }; // class VariableResolverPtr
template<class string_type> template<class string_type, class string_adaptor>
class NullVariableResolver : public VariableResolver<string_type> class NullVariableResolver : public VariableResolver<string_type, string_adaptor>
{ {
public: public:
virtual XPathValuePtr<string_type> resolveVariable(const string_type& name) const virtual XPathValuePtr<string_type> resolveVariable(const string_type& name) const
{ {
throw UnboundVariableException(name); throw UnboundVariableException(string_adaptor().asStdString(name));
} // resolveVariable } // resolveVariable
}; // NullVariableResolver }; // NullVariableResolver

View file

@ -10,7 +10,7 @@
using namespace Arabica::XPath; using namespace Arabica::XPath;
class StringVariableResolver : public VariableResolver<std::string> class StringVariableResolver : public VariableResolver<std::string, Arabica::default_string_adaptor<std::string> >
{ {
public: public:
virtual XPathValuePtr<std::string> resolveVariable(const std::string& name) const virtual XPathValuePtr<std::string> resolveVariable(const std::string& name) const
@ -31,7 +31,7 @@ private:
VarMap map_; VarMap map_;
}; // StringVariableResolver }; // StringVariableResolver
class NodeSetVariableResolver : public VariableResolver<std::string> class NodeSetVariableResolver : public VariableResolver<std::string, Arabica::default_string_adaptor<std::string> >
{ {
public: public:
virtual XPathValuePtr<std::string> resolveVariable(const std::string& name) const virtual XPathValuePtr<std::string> resolveVariable(const std::string& name) const