From d8bd7c896885d5982a977f0982149dd5b3afc077 Mon Sep 17 00:00:00 2001 From: jez_higgins <> Date: Wed, 17 Aug 2005 09:17:18 +0000 Subject: [PATCH] parameterised VariableResolver on string_adaptor as well as string_type --- XPath/XPath.hpp | 2 +- XPath/impl/xpath_execution_context.hpp | 9 +++++---- XPath/impl/xpath_parser.hpp | 10 +++++----- XPath/impl/xpath_variable_resolver.hpp | 17 ++++++++++------- test/XPath/execute_test.cpp | 4 ++-- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/XPath/XPath.hpp b/XPath/XPath.hpp index 65b3bf66..8cd65a39 100644 --- a/XPath/XPath.hpp +++ b/XPath/XPath.hpp @@ -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 diff --git a/XPath/impl/xpath_execution_context.hpp b/XPath/impl/xpath_execution_context.hpp index b5ba0bf1..ea9f6afd 100644 --- a/XPath/impl/xpath_execution_context.hpp +++ b/XPath/impl/xpath_execution_context.hpp @@ -1,6 +1,7 @@ #ifndef ARABICA_XPATH_EXECUTION_CONTEXT_HPP #define ARABICA_XPATH_EXECUTION_CONTEXT_HPP +#include #include "xpath_variable_resolver.hpp" #include "xpath_resolver_holder.hpp" @@ -30,14 +31,14 @@ public: void setPosition(unsigned int pos) { position_ = pos; } - const VariableResolver& variableResolver() const { return variableResolver_.get(); } - void setVariableResolver(const VariableResolver& resolver) { variableResolver_.set(resolver); } - void setVariableResolver(VariableResolverPtr& resolver) { variableResolver_.set(resolver); } + const VariableResolver >& variableResolver() const { return variableResolver_.get(); } + void setVariableResolver(const VariableResolver >& resolver) { variableResolver_.set(resolver); } + void setVariableResolver(VariableResolverPtr >& resolver) { variableResolver_.set(resolver); } private: size_t position_; size_t last_; - ResolverHolder > variableResolver_; + ResolverHolder > > variableResolver_; ExecutionContext(const ExecutionContext&); ExecutionContext& operator=(const ExecutionContext&); diff --git a/XPath/impl/xpath_parser.hpp b/XPath/impl/xpath_parser.hpp index 4ba3558a..90478c36 100644 --- a/XPath/impl/xpath_parser.hpp +++ b/XPath/impl/xpath_parser.hpp @@ -87,10 +87,10 @@ public: const NamespaceContext& getNamespaceContext() const { return namespaceContext_.get(); } void resetNamespaceContext() { namespaceContext_.set(NamespaceContextPtr(new NullNamespaceContext())); } - void setVariableResolver(const VariableResolver& variableResolver) { variableResolver_.set(variableResolver); } - void setVariableResolver(VariableResolverPtr variableResolver) { variableResolver_.set(variableResolver); } - const VariableResolver& getVariableResolver() const { return variableResolver_.get(); } - void resetVariableResolver() { variableResolver_.set(VariableResolverPtr(new NullVariableResolver())); } + void setVariableResolver(const VariableResolver& variableResolver) { variableResolver_.set(variableResolver); } + void setVariableResolver(VariableResolverPtr variableResolver) { variableResolver_.set(variableResolver); } + const VariableResolver& getVariableResolver() const { return variableResolver_.get(); } + void resetVariableResolver() { variableResolver_.set(VariableResolverPtr(new NullVariableResolver())); } void setFunctionResolver(const FunctionResolver& functionResolver) { functionResolver_.set(functionResolver); } void setFunctionResolver(FunctionResolverPtr functionResolver) { functionResolver_.set(functionResolver); } @@ -136,7 +136,7 @@ private: xpath_grammar_expr xpathge_; ResolverHolder > namespaceContext_; - ResolverHolder > variableResolver_; + ResolverHolder > variableResolver_; ResolverHolder > functionResolver_; ///////////////////////////////////////////////////////////////////////////////// diff --git a/XPath/impl/xpath_variable_resolver.hpp b/XPath/impl/xpath_variable_resolver.hpp index bd36f21b..b191fba3 100644 --- a/XPath/impl/xpath_variable_resolver.hpp +++ b/XPath/impl/xpath_variable_resolver.hpp @@ -15,7 +15,7 @@ public: UnboundVariableException(const std::string& thing) : std::runtime_error("The variable '" + thing + "' is undefined.") { } }; // class UnboundVariableException -template +template class VariableResolver { public: @@ -24,20 +24,23 @@ public: virtual XPathValuePtr resolveVariable(const string_type& name) const = 0; }; // class VariableResolver -template -class VariableResolverPtr : public boost::shared_ptr > +template +class VariableResolverPtr : public boost::shared_ptr > { public: - explicit VariableResolverPtr(VariableResolver* vr) : boost::shared_ptr >(vr) { } + explicit VariableResolverPtr(VariableResolver* vr) : + boost::shared_ptr >(vr) + { + } // VariableResolverPtr }; // class VariableResolverPtr -template -class NullVariableResolver : public VariableResolver +template +class NullVariableResolver : public VariableResolver { public: virtual XPathValuePtr resolveVariable(const string_type& name) const { - throw UnboundVariableException(name); + throw UnboundVariableException(string_adaptor().asStdString(name)); } // resolveVariable }; // NullVariableResolver diff --git a/test/XPath/execute_test.cpp b/test/XPath/execute_test.cpp index d406a181..8433c8f4 100644 --- a/test/XPath/execute_test.cpp +++ b/test/XPath/execute_test.cpp @@ -10,7 +10,7 @@ using namespace Arabica::XPath; -class StringVariableResolver : public VariableResolver +class StringVariableResolver : public VariableResolver > { public: virtual XPathValuePtr resolveVariable(const std::string& name) const @@ -31,7 +31,7 @@ private: VarMap map_; }; // StringVariableResolver -class NodeSetVariableResolver : public VariableResolver +class NodeSetVariableResolver : public VariableResolver > { public: virtual XPathValuePtr resolveVariable(const std::string& name) const