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 ++++++++++++++-------------------------- src/function/read_directory.cc | 4 ++-- src/function/read_directory.h | 7 +++++-- src/function/read_file.cc | 4 ++-- src/function/read_file.h | 7 +++++-- src/function/read_xml_file.cc | 6 ++++-- src/function/read_xml_file.h | 7 +++++-- src/function/transform.cc | 6 +++--- src/function/transform.h | 8 ++++++-- 9 files changed, 46 insertions(+), 43 deletions(-) (limited to 'src/function') 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 ); diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc index 54d3d0d..4060523 100644 --- a/src/function/read_directory.cc +++ b/src/function/read_directory.cc @@ -11,10 +11,10 @@ namespace InputXSLT { xercesc::DOMDocument* FunctionReadDirectory::constructDocument( const InputXSLT::FilesystemContext& fsContext, - const FunctionBase::argument_array& arguments + const FunctionBase::argument_tuple& arguments ) { const boost::filesystem::path directoryPath( - fsContext.resolve(arguments[0]) + fsContext.resolve(std::get<0>(arguments)) ); xercesc::DOMDocument* const domDocument( diff --git a/src/function/read_directory.h b/src/function/read_directory.h index 9dc3869..562e191 100644 --- a/src/function/read_directory.h +++ b/src/function/read_directory.h @@ -5,7 +5,10 @@ namespace InputXSLT { -class FunctionReadDirectory : public FunctionBase { +class FunctionReadDirectory : public FunctionBase< + FunctionReadDirectory, + std::string +> { public: using FunctionBase::FunctionBase; @@ -14,7 +17,7 @@ class FunctionReadDirectory : public FunctionBase { xercesc::DOMDocument* constructDocument( const FilesystemContext&, - const FunctionBase::argument_array& + const FunctionBase::argument_tuple& ); }; diff --git a/src/function/read_file.cc b/src/function/read_file.cc index 19ca296..8e14f41 100644 --- a/src/function/read_file.cc +++ b/src/function/read_file.cc @@ -26,10 +26,10 @@ namespace InputXSLT { xercesc::DOMDocument* FunctionReadFile::constructDocument( const FilesystemContext& fsContext, - const FunctionBase::argument_array& arguments + const FunctionBase::argument_tuple& arguments ) { const boost::filesystem::path filePath( - fsContext.resolve(arguments[0]) + fsContext.resolve(std::get<0>(arguments)) ); xercesc::DOMDocument* const domDocument( diff --git a/src/function/read_file.h b/src/function/read_file.h index e7b746c..7b17583 100644 --- a/src/function/read_file.h +++ b/src/function/read_file.h @@ -5,7 +5,10 @@ namespace InputXSLT { -class FunctionReadFile : public FunctionBase { +class FunctionReadFile : public FunctionBase< + FunctionReadFile, + std::string +> { public: using FunctionBase::FunctionBase; @@ -14,7 +17,7 @@ class FunctionReadFile : public FunctionBase { xercesc::DOMDocument* constructDocument( const FilesystemContext&, - const FunctionBase::argument_array& + const FunctionBase::argument_tuple& ); }; diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc index cf2cadd..6e89701 100644 --- a/src/function/read_xml_file.cc +++ b/src/function/read_xml_file.cc @@ -1,5 +1,7 @@ #include "read_xml_file.h" +#include + #include #include #include @@ -34,10 +36,10 @@ namespace InputXSLT { xercesc::DOMDocument* FunctionReadXmlFile::constructDocument( const FilesystemContext& fsContext, - const FunctionBase::argument_array& arguments + const FunctionBase::argument_tuple& arguments ) { const boost::filesystem::path filePath( - fsContext.resolve(arguments[0]) + fsContext.resolve(std::get<0>(arguments)) ); xercesc::DOMDocument* const domDocument( diff --git a/src/function/read_xml_file.h b/src/function/read_xml_file.h index 423f0a2..5355449 100644 --- a/src/function/read_xml_file.h +++ b/src/function/read_xml_file.h @@ -5,7 +5,10 @@ namespace InputXSLT { -class FunctionReadXmlFile : public FunctionBase { +class FunctionReadXmlFile : public FunctionBase< + FunctionReadXmlFile, + std::string +> { public: using FunctionBase::FunctionBase; @@ -14,7 +17,7 @@ class FunctionReadXmlFile : public FunctionBase { xercesc::DOMDocument* constructDocument( const FilesystemContext&, - const FunctionBase::argument_array& + const FunctionBase::argument_tuple& ); }; diff --git a/src/function/transform.cc b/src/function/transform.cc index 5c53044..be06037 100644 --- a/src/function/transform.cc +++ b/src/function/transform.cc @@ -11,14 +11,14 @@ namespace InputXSLT { xercesc::DOMDocument* FunctionTransform::constructDocument( const InputXSLT::FilesystemContext& fsContext, - const FunctionBase::argument_array& arguments + const FunctionBase::argument_tuple& arguments ) { const boost::filesystem::path transformationPath( - fsContext.resolve(arguments[0]) + fsContext.resolve(std::get<0>(arguments)) ); const boost::filesystem::path targetPath( - fsContext.resolve(arguments[1]) + fsContext.resolve(std::get<1>(arguments)) ); xercesc::DOMDocument* const domDocument( diff --git a/src/function/transform.h b/src/function/transform.h index fc735f0..2be8925 100644 --- a/src/function/transform.h +++ b/src/function/transform.h @@ -5,7 +5,11 @@ namespace InputXSLT { -class FunctionTransform : public FunctionBase { +class FunctionTransform : public FunctionBase< + FunctionTransform, + std::string, + std::string +> { public: using FunctionBase::FunctionBase; @@ -14,7 +18,7 @@ class FunctionTransform : public FunctionBase { xercesc::DOMDocument* constructDocument( const FilesystemContext&, - const FunctionBase::argument_array& + const FunctionBase::argument_tuple& ); }; -- cgit v1.2.3