aboutsummaryrefslogtreecommitdiff
path: root/src/support/tuple/mapper.h
blob: c95365e6ea6b6b10abc806c78877307cd5718569 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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_