diff options
author | Adrian Kummerländer | 2014-05-15 17:23:13 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-05-15 17:23:13 +0200 |
commit | ec6abad74348e9b577e1dd63b41d65263bb0334a (patch) | |
tree | 95d35491c723b12687e067ee2a480b37daf19da2 /src/support/tuple | |
parent | 5fbca0993146982ab1dbb0d352c1e15e40b3de22 (diff) | |
download | InputXSLT-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/support/tuple')
-rw-r--r-- | src/support/tuple/mapper.h | 62 | ||||
-rw-r--r-- | src/support/tuple/xobject_value.cc | 18 | ||||
-rw-r--r-- | src/support/tuple/xobject_value.h | 17 |
3 files changed, 97 insertions, 0 deletions
diff --git a/src/support/tuple/mapper.h b/src/support/tuple/mapper.h new file mode 100644 index 0000000..c95365e --- /dev/null +++ b/src/support/tuple/mapper.h @@ -0,0 +1,62 @@ +#ifndef INPUTXSLT_SRC_SUPPORT_TUPLE_MAPPER_H_ +#define INPUTXSLT_SRC_SUPPORT_TUPLE_MAPPER_H_ + +#include <xalanc/XPath/XObject.hpp> + +#include <tuple> +#include <type_traits> + +#include "common.h" +#include "xobject_value.h" + +namespace InputXSLT { + +template <bool Condition> +using enable_if = typename std::enable_if<Condition, std::size_t>::type; + +namespace Mapper { + template < + typename Target, + std::size_t Index = 0, + typename Current = std::tuple<>, + enable_if<Index == std::tuple_size<Target>::value> = 0 + > + inline Target construct( + const xalan::XPathExecutionContext::XObjectArgVectorType&, + Current&& current + ) { + return current; + } + + template < + typename Target, + std::size_t Index = 0, + typename Current = std::tuple<>, + enable_if<Index < std::tuple_size<Target>::value> = 0 + > + inline Target construct( + const xalan::XPathExecutionContext::XObjectArgVectorType& source, + Current&& current = std::tuple<>() + ) { + return construct< + Target, + Index + 1 + >( + source, + std::tuple_cat( + current, + std::make_tuple( + XObjectValue::get< + typename std::tuple_element<Index, Target>::type + >( + source[Index] + ) + ) + ) + ); + } +}; + +} + +#endif // INPUTXSLT_SRC_SUPPORT_TUPLE_MAPPER_H_ diff --git a/src/support/tuple/xobject_value.cc b/src/support/tuple/xobject_value.cc new file mode 100644 index 0000000..3883436 --- /dev/null +++ b/src/support/tuple/xobject_value.cc @@ -0,0 +1,18 @@ +#include "xobject_value.h" + +#include <string> + +#include "support/xalan_string.h" + +namespace InputXSLT { + +namespace XObjectValue { + +template <> +std::string get<std::string>(const xalan::XObjectPtr& ptr) { + return toString(ptr->str()); +} + +} + +} diff --git a/src/support/tuple/xobject_value.h b/src/support/tuple/xobject_value.h new file mode 100644 index 0000000..bb602a4 --- /dev/null +++ b/src/support/tuple/xobject_value.h @@ -0,0 +1,17 @@ +#ifndef INPUTXSLT_SRC_SUPPORT_TUPLE_XOBJECT_VALUE_H_ +#define INPUTXSLT_SRC_SUPPORT_TUPLE_XOBJECT_VALUE_H_ + +#include <xalanc/XPath/XObject.hpp> + +#include "common.h" + +namespace InputXSLT { + +namespace XObjectValue { + template <typename Type> + Type get(const xalan::XObjectPtr&); +} + +} + +#endif // INPUTXSLT_SRC_SUPPORT_TUPLE_XOBJECT_VALUE_H_ |