-
Notifications
You must be signed in to change notification settings - Fork 298
/
adaptable_factory_free_functions.hpp
71 lines (66 loc) · 2.76 KB
/
adaptable_factory_free_functions.hpp
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
63
64
65
66
67
68
69
70
/*
* Copyright Jeremy Pack 2008
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* See http://www.boost.org/ for latest version.
*/
// No header guard - this file is intended to be included multiple times.
#define N BOOST_PP_ITERATION()
template <class Interface, class Derived, class Info, class TypeInfo
BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_PARAMS(N, class Param)>
inline Interface* create_func(
boost::extensions::basic_parameter_map<Info, TypeInfo>& map,
const std::vector<Info>& names) {
#if N
extensions::generic_parameter<TypeInfo>* gen;
#define BOOST_EXTENSION_GET_FROM_LIST(z, n, data) \
gen = map.template get_first<BOOST_PP_CAT(Param, n)>(names[n]); \
if (!gen) return 0; \
BOOST_PP_CAT(Param, n) BOOST_PP_CAT(p, n) = \
gen->template cast<BOOST_PP_CAT(Param, n)>();
BOOST_PP_REPEAT(N, BOOST_EXTENSION_GET_FROM_LIST, )
#undef BOOST_EXTENSION_GET_FROM_LIST
#endif // N
return new Derived(BOOST_PP_ENUM_PARAMS(N, p));
}
template <class Interface, class Derived, class Info, class TypeInfo
BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_PARAMS(N, class Param)>
inline boost::function<Interface* ()> get_functor_func(
boost::extensions::basic_parameter_map<Info, TypeInfo>& map,
const std::vector<Info>& names) {
#if N
extensions::generic_parameter<TypeInfo>* gen;
#define BOOST_EXTENSION_GET_FROM_LIST(z, n, data) \
gen = map.template get_first<BOOST_PP_CAT(Param, n)>(names[n]); \
if (!gen) return boost::function<Interface* ()>(); \
BOOST_PP_CAT(Param, n) BOOST_PP_CAT(p, n) = \
gen->template cast<BOOST_PP_CAT(Param, n)>();
BOOST_PP_REPEAT(N, BOOST_EXTENSION_GET_FROM_LIST, )
#undef BOOST_EXTENSION_GET_FROM_LIST
#endif // N
Interface* (*f)(BOOST_PP_ENUM_PARAMS(N, Param)) =
impl::create_derived<Interface, Derived BOOST_PP_COMMA_IF(N)
BOOST_PP_ENUM_PARAMS(N, Param)>;
return bind(f
BOOST_PP_COMMA_IF(N)
BOOST_PP_ENUM_PARAMS(N, p));
}
template <class Info, class TypeInfo BOOST_PP_COMMA_IF(N)
BOOST_PP_ENUM_PARAMS(N, class Param)>
inline std::vector<std::pair<TypeInfo, Info> > check_func(
const boost::extensions::basic_parameter_map<Info, TypeInfo>& map,
const std::vector<Info>& names) {
std::vector<std::pair<TypeInfo, Info> > needed_parameters;
#define BOOST_EXTENSION_CHECK_IN_LIST(z, n, data) \
if (!map.template has<BOOST_PP_CAT(Param, n)>(names[n])) \
needed_parameters.push_back(std::make_pair(\
type_info_handler<TypeInfo, \
BOOST_PP_CAT(Param, n)>::template get_class_type(), \
names[n]));
BOOST_PP_REPEAT(N, BOOST_EXTENSION_CHECK_IN_LIST, )
#undef BOOST_EXTENSION_CHECK_IN_LIST
return needed_parameters;
}
#undef N