From 5f6fc45749b99e9013f04c95a525f2d627db01bf Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sat, 7 Jun 2014 17:24:44 +0200 Subject: Improved FunctionBase constructDocument parameter propagation * replaced std::tuple constructing Mapper template methods with direct XObjectArgVectorType unpacking ** XObjectValue::get template method is applied directly using parameter pack unpacking * implemented custom IndexSequence / Sequence type to provide vector indexes * modified all external functions to provide matching constructDocument overloads --- src/function/base.h | 55 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'src/function/base.h') diff --git a/src/function/base.h b/src/function/base.h index 3609201..56712bb 100644 --- a/src/function/base.h +++ b/src/function/base.h @@ -12,8 +12,9 @@ #include "support/xalan_string.h" #include "support/filesystem_context.h" #include "support/include_entity_resolver.h" -#include "support/tuple/mapper.h" #include "support/dom/document_cache.h" +#include "support/type/sequence.h" +#include "support/type/xobject_value.h" namespace InputXSLT { @@ -22,18 +23,18 @@ template < typename... Types > class FunctionBase : public xalan::Function { - public: - typedef std::tuple parameter_tuple; + static const std::size_t parameter_count = sizeof...(Types); + public: FunctionBase(IncludeEntityResolver* resolver): include_resolver_(resolver), document_cache_(std::make_shared()) { } virtual xalan::XObjectPtr execute( xalan::XPathExecutionContext& executionContext, - xalan::XalanNode* context, - const XObjectArgVectorType& parameters, - const xalan::Locator* locator + xalan::XalanNode* context, + const XObjectArgVectorType& parameters, + const xalan::Locator* locator ) const { this->validateParameters( parameters, @@ -43,25 +44,22 @@ class FunctionBase : public xalan::Function { ); xalan::XalanDocument* const domDocument( - this->document_cache_->create( - static_cast( - const_cast(this) - )->constructDocument( - FilesystemContext(locator), - Mapper::template construct(parameters) - ) + this->callConstructDocument( + parameters, + locator, + typename IndexSequence::type() ) ); - xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodeList( + xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodes( executionContext ); - nodeList->addNodes( + nodes->addNodes( *domDocument->getDocumentElement()->getChildNodes() ); - return executionContext.getXObjectFactory().createNodeSet(nodeList); + return executionContext.getXObjectFactory().createNodeSet(nodes); } virtual FunctionBase* clone( @@ -84,14 +82,33 @@ class FunctionBase : public xalan::Function { const xalan::XalanDOMString& getError( xalan::XalanDOMString& result) const { result.assign(std::string( - "The function expects " + - std::to_string(std::tuple_size::value) + + "The function expects " + + std::to_string(parameter_count) + " parameter(s)" ).data()); return result; } + template + inline xalan::XalanDocument* callConstructDocument( + const XObjectArgVectorType& parameters, + const xalan::Locator* locator, + Sequence + ) const { + return this->document_cache_->create( + static_cast( + const_cast(this) + )->constructDocument( + FilesystemContext(locator), + XObjectValue::get + >::type>(parameters[Index])... + ) + ); + } + inline void validateParameters( const XObjectArgVectorType& parameters, xalan::XPathExecutionContext& executionContext, @@ -106,7 +123,7 @@ class FunctionBase : public xalan::Function { } ); - if ( parameters.size() != std::tuple_size::value || anyNull ) { + if ( parameters.size() != parameter_count || anyNull ) { xalan::XPathExecutionContext::GetAndReleaseCachedString guard( executionContext ); -- cgit v1.2.3