From ec6abad74348e9b577e1dd63b41d65263bb0334a Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Thu, 15 May 2014 17:23:13 +0200 Subject: Adapted FunctionBase template to accept multiple argument types * FunctionBase::argument_tuple is a std::tuple specialization type specialized on the argument types passed inside the variadic template argument of FunctionBase * added tuple Mapper and XObjectValue helper namespaces containing recursive tuple construction and XObjectPtr value extraction logic * changed all external function implementations accordingly * this change was implemented to uniformly support different external function argument types than std::string --- src/function/base.h | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'src/function/base.h') diff --git a/src/function/base.h b/src/function/base.h index 7fbd818..b74a7d8 100644 --- a/src/function/base.h +++ b/src/function/base.h @@ -1,29 +1,28 @@ #ifndef INPUTXSLT_SRC_FUNCTION_BASE_H_ #define INPUTXSLT_SRC_FUNCTION_BASE_H_ -#include #include #include #include #include -#include -#include +#include #include "common.h" #include "support/xalan_string.h" +#include "support/tuple/mapper.h" #include "support/dom/document_cache.h" #include "support/filesystem_context.h" namespace InputXSLT { template < - class Implementation, - std::size_t ArgumentCount + typename Implementation, + typename... Types > class FunctionBase : public xalan::Function { public: - typedef std::array argument_array; + typedef std::tuple argument_tuple; FunctionBase(): document_cache_(std::make_shared()) { } @@ -31,34 +30,23 @@ class FunctionBase : public xalan::Function { virtual xalan::XObjectPtr execute( xalan::XPathExecutionContext& executionContext, xalan::XalanNode* context, - const XObjectArgVectorType& rawArguments, + const XObjectArgVectorType& arguments, const xalan::Locator* locator ) const { this->validateArguments( - rawArguments, + arguments, executionContext, context, locator ); - argument_array pathArguments; - - std::transform( - rawArguments.begin(), - rawArguments.end(), - pathArguments.begin(), - [](const xalan::XObjectPtr& ptr) -> std::string { - return toString(ptr->str()); - } - ); - xalan::XalanDocument* const domDocument( this->document_cache_->create( static_cast( const_cast(this) )->constructDocument( FilesystemContext(locator), - pathArguments + Mapper::template construct(arguments) ) ) ); @@ -91,8 +79,8 @@ class FunctionBase : public xalan::Function { const xalan::XalanDOMString& getError( xalan::XalanDOMString& result) const { result.assign(std::string( - "The function expects " + - std::to_string(ArgumentCount) + + "The function expects " + + std::to_string(std::tuple_size::value) + " argument(s) of type string." ).data()); @@ -100,20 +88,20 @@ class FunctionBase : public xalan::Function { } inline void validateArguments( - const XObjectArgVectorType& rawArguments, + const XObjectArgVectorType& arguments, xalan::XPathExecutionContext& executionContext, xalan::XalanNode* context, const xalan::Locator* locator ) const { const bool anyNull = std::any_of( - rawArguments.begin(), - rawArguments.end(), + arguments.begin(), + arguments.end(), [](const xalan::XObjectPtr& ptr) -> bool { return ptr.null(); } ); - if ( rawArguments.size() != ArgumentCount || anyNull ) { + if ( arguments.size() != std::tuple_size::value || anyNull ) { xalan::XPathExecutionContext::GetAndReleaseCachedString guard( executionContext ); -- cgit v1.2.3