#ifndef INPUTXSLT_SRC_FUNCTION_BASE_H_ #define INPUTXSLT_SRC_FUNCTION_BASE_H_ #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 < typename Implementation, typename... Types > class FunctionBase : public xalan::Function { public: typedef std::tuple parameter_tuple; FunctionBase(): document_cache_(std::make_shared()) { } virtual xalan::XObjectPtr execute( xalan::XPathExecutionContext& executionContext, xalan::XalanNode* context, const XObjectArgVectorType& parameters, const xalan::Locator* locator ) const { this->validateParameters( parameters, executionContext, context, locator ); xalan::XalanDocument* const domDocument( this->document_cache_->create( static_cast( const_cast(this) )->constructDocument( FilesystemContext(locator), Mapper::template construct(parameters) ) ) ); xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodeList( executionContext ); nodeList->addNodes( *domDocument->getDocumentElement()->getChildNodes() ); return executionContext.getXObjectFactory().createNodeSet(nodeList); } virtual FunctionBase* clone( xalan::MemoryManager& manager) const { return xalan::XalanCopyConstruct( manager, static_cast(*this) ); } FunctionBase& operator=(const FunctionBase&) = delete; bool operator==(const FunctionBase&) const = delete; private: std::shared_ptr document_cache_; const xalan::XalanDOMString& getError( xalan::XalanDOMString& result) const { result.assign(std::string( "The function expects " + std::to_string(std::tuple_size::value) + " parameter(s)" ).data()); return result; } inline void validateParameters( const XObjectArgVectorType& parameters, xalan::XPathExecutionContext& executionContext, xalan::XalanNode* context, const xalan::Locator* locator ) const { const bool anyNull = std::any_of( parameters.begin(), parameters.end(), [](const xalan::XObjectPtr& ptr) -> bool { return ptr.null(); } ); if ( parameters.size() != std::tuple_size::value || anyNull ) { xalan::XPathExecutionContext::GetAndReleaseCachedString guard( executionContext ); this->generalError(executionContext, context, locator); } } }; } #endif // INPUTXSLT_SRC_FUNCTION_BASE_H_