aboutsummaryrefslogtreecommitdiff
path: root/src/function/base.h
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-15 17:23:13 +0200
committerAdrian Kummerländer2014-05-15 17:23:13 +0200
commitec6abad74348e9b577e1dd63b41d65263bb0334a (patch)
tree95d35491c723b12687e067ee2a480b37daf19da2 /src/function/base.h
parent5fbca0993146982ab1dbb0d352c1e15e40b3de22 (diff)
downloadInputXSLT-ec6abad74348e9b577e1dd63b41d65263bb0334a.tar
InputXSLT-ec6abad74348e9b577e1dd63b41d65263bb0334a.tar.gz
InputXSLT-ec6abad74348e9b577e1dd63b41d65263bb0334a.tar.bz2
InputXSLT-ec6abad74348e9b577e1dd63b41d65263bb0334a.tar.lz
InputXSLT-ec6abad74348e9b577e1dd63b41d65263bb0334a.tar.xz
InputXSLT-ec6abad74348e9b577e1dd63b41d65263bb0334a.tar.zst
InputXSLT-ec6abad74348e9b577e1dd63b41d65263bb0334a.zip
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
Diffstat (limited to 'src/function/base.h')
-rw-r--r--src/function/base.h40
1 files changed, 14 insertions, 26 deletions
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 <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xalanc/XPath/XObjectFactory.hpp>
#include <xalanc/XPath/Function.hpp>
#include <xalanc/XPath/XObject.hpp>
#include <memory>
-#include <algorithm>
-#include <array>
+#include <tuple>
#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<std::string, ArgumentCount> argument_array;
+ typedef std::tuple<Types...> argument_tuple;
FunctionBase():
document_cache_(std::make_shared<DomDocumentCache>()) { }
@@ -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<Implementation*>(
const_cast<FunctionBase*>(this)
)->constructDocument(
FilesystemContext(locator),
- pathArguments
+ Mapper::template construct<argument_tuple>(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<argument_tuple>::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<argument_tuple>::value || anyNull ) {
xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
executionContext
);