aboutsummaryrefslogtreecommitdiff
path: root/src/function
diff options
context:
space:
mode:
Diffstat (limited to 'src/function')
-rw-r--r--src/function/base.h40
-rw-r--r--src/function/read_directory.cc4
-rw-r--r--src/function/read_directory.h7
-rw-r--r--src/function/read_file.cc4
-rw-r--r--src/function/read_file.h7
-rw-r--r--src/function/read_xml_file.cc6
-rw-r--r--src/function/read_xml_file.h7
-rw-r--r--src/function/transform.cc6
-rw-r--r--src/function/transform.h8
9 files changed, 46 insertions, 43 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
);
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<FunctionReadDirectory, 1> {
+class FunctionReadDirectory : public FunctionBase<
+ FunctionReadDirectory,
+ std::string
+> {
public:
using FunctionBase::FunctionBase;
@@ -14,7 +17,7 @@ class FunctionReadDirectory : public FunctionBase<FunctionReadDirectory, 1> {
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<FunctionReadFile, 1> {
+class FunctionReadFile : public FunctionBase<
+ FunctionReadFile,
+ std::string
+> {
public:
using FunctionBase::FunctionBase;
@@ -14,7 +17,7 @@ class FunctionReadFile : public FunctionBase<FunctionReadFile, 1> {
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 <xalanc/XSLT/XSLTInputSource.hpp>
+
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMElement.hpp>
@@ -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<FunctionReadXmlFile, 1> {
+class FunctionReadXmlFile : public FunctionBase<
+ FunctionReadXmlFile,
+ std::string
+> {
public:
using FunctionBase::FunctionBase;
@@ -14,7 +17,7 @@ class FunctionReadXmlFile : public FunctionBase<FunctionReadXmlFile, 1> {
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<FunctionTransform, 2> {
+class FunctionTransform : public FunctionBase<
+ FunctionTransform,
+ std::string,
+ std::string
+> {
public:
using FunctionBase::FunctionBase;
@@ -14,7 +18,7 @@ class FunctionTransform : public FunctionBase<FunctionTransform, 2> {
xercesc::DOMDocument* constructDocument(
const FilesystemContext&,
- const FunctionBase::argument_array&
+ const FunctionBase::argument_tuple&
);
};