- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
functionsignature.hxx
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2013 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6
7 #ifndef _QITYPE_DETAIL_FUNCTIONSIGNATURE_HXX_
8 #define _QITYPE_DETAIL_FUNCTIONSIGNATURE_HXX_
9
10 #include <boost/thread/mutex.hpp>
11 #include <qi/macro.hpp>
12
13 namespace qi {
14 namespace detail {
15 struct signature_function_arg_apply {
16 signature_function_arg_apply(std::string* val)
17 : val(*val)
18 {}
19
20 template<typename T> void operator()(T *x) {
21 val += qi::typeOf<T>()->signature().toString();
22 }
23
24 std::string &val;
25 };
26
27 template<typename T>
28 struct RawFunctionSignature
29 {
30 static qi::Signature makeSigreturn()
31 {
32 using ResultType = typename boost::function_types::result_type<T>::type;
33 return typeOf<ResultType>()->signature();
34 }
35 static qi::Signature makeSignature()
36 {
37 std::string signature;
38 signature += '(';
39 using ArgsType = typename boost::function_types::parameter_types<T>::type;
40 boost::mpl::for_each<
41 boost::mpl::transform_view<ArgsType,
42 boost::add_pointer<
43 boost::remove_const<
44 boost::remove_reference<boost::mpl::_1>
45 >
46 >
47 >
48 >(qi::detail::signature_function_arg_apply(&signature));
49 signature += ')';
50 return qi::Signature(signature);
51 }
52 };
53
54 template<typename R, typename F, typename B>
55 struct RawFunctionSignature<boost::_bi::bind_t<R, F, B> >
56 {
57 static qi::Signature makeSigreturn()
58 {
59 using ResultType = typename qi::boost_bind_result_type<boost::_bi::bind_t<R, F, B>>::type;
60 return typeOf<ResultType>()->signature();
61 }
62
63 static qi::Signature makeSignature()
64 {
65 std::string signature;
66 signature += '(';
67 using ArgsType = typename qi::boost_bind_parameter_types<boost::_bi::bind_t<R, F, B>>::type;
68 boost::mpl::for_each<
69 boost::mpl::transform_view<ArgsType,
70 boost::add_pointer<
71 boost::remove_const<
72 boost::remove_reference<boost::mpl::_1>
73 >
74 >
75 >
76 >(qi::detail::signature_function_arg_apply(&signature));
77 signature += ')';
78 return Signature(signature);
79 }
80 };
81
82 template<typename T>
83 struct MemberFunctionSignature
84 {
85 static qi::Signature makeSigreturn()
86 {
87 using ResultType = typename boost::function_types::result_type<T>::type;
88 return typeOf<ResultType>()->signature();
89 }
90 static qi::Signature makeSignature()
91 {
92 // Reconstruct the boost::bind(instance, _1, _2...) signature
93 using RetType = typename boost::function_types::result_type<T>::type;
94 using MemArgsType = typename boost::function_types::parameter_types<T>::type;
95 using ArgsType = typename boost::mpl::pop_front<MemArgsType>::type;
96 using EffectiveType = typename boost::mpl::push_front<ArgsType, RetType>::type;
97 using type = typename boost::function_types::function_type<EffectiveType>::type;
98 return RawFunctionSignature<type>::makeSignature();
99 }
100 };
101
102 template<typename T>
103 struct FunctionSignature
104 {
105 using Backend = typename boost::mpl::if_<
106 typename boost::function_types::is_member_pointer<T>,
107 MemberFunctionSignature<T>,
108 RawFunctionSignature<T>
109 >::type;
110 static qi::Signature signature()
111 {
112 static qi::Signature result = Backend::makeSignature();
113 return result;
114 }
115 static qi::Signature sigreturn()
116 {
117 static qi::Signature result = Backend::makeSigreturn();
118 return result;
119 }
120 };
121
122 template<typename T>
123 struct FunctionSignature<boost::function<T> >: public FunctionSignature<T> {};
124
125 template<typename T> inline
126 qi::Signature _functionArgumentsSignature()
127 {
128 std::string sigs;
129 sigs += '(';
130 using ArgsType = typename boost::function_types::parameter_types<T>::type;
131 boost::mpl::for_each<
132 boost::mpl::transform_view<ArgsType,
133 boost::add_pointer<
134 boost::remove_const<
135 boost::remove_reference<boost::mpl::_1>>>>> (qi::detail::signature_function_arg_apply(&sigs));
136 sigs += ')';
137 return Signature(sigs);
138 }
139 template<typename T> inline
140 qi::Signature functionArgumentsSignature()
141 {
142 static Signature* res;
143 QI_ONCE(res = new Signature(_functionArgumentsSignature<T>()));
144 return *res;
145 }
146 }
147 }
148
149
150 #endif // _QITYPE_DETAIL_FUNCTIONSIGNATURE_HXX_
qi::detail::signature_function_arg_apply::operator()
void operator()(T *x)
Definition: functionsignature.hxx:20
qi::boost_bind_result_type
Definition: bindtype.hxx:239
qi::detail::MemberFunctionSignature
Definition: functionsignature.hxx:83
qi::Signature
Definition: signature.hpp:66
qi::detail::MemberFunctionSignature::makeSignature
static qi::Signature makeSignature()
Definition: functionsignature.hxx:90
qi::detail::FunctionSignature::sigreturn
static qi::Signature sigreturn()
Definition: functionsignature.hxx:115
qi::detail::signature_function_arg_apply::signature_function_arg_apply
signature_function_arg_apply(std::string *val)
Definition: functionsignature.hxx:16
qi::detail::functionArgumentsSignature
qi::Signature functionArgumentsSignature()
Definition: functionsignature.hxx:140
qi::detail::FunctionSignature::Backend
typename boost::mpl::if_< typename boost::function_types::is_member_pointer< T >, MemberFunctionSignature< T >, RawFunctionSignature< T > >::type Backend
Definition: functionsignature.hxx:109
qi::detail::MemberFunctionSignature::makeSigreturn
static qi::Signature makeSigreturn()
Definition: functionsignature.hxx:85
qi::detail::FunctionSignature::signature
static qi::Signature signature()
Definition: functionsignature.hxx:110
qi::detail::_functionArgumentsSignature
qi::Signature _functionArgumentsSignature()
Definition: functionsignature.hxx:126
macro.hpp
Various macros for qi. (deprecated, export API, disallow copy, ..) <includename>qi/macro.hpp</includename> .
QI_ONCE
#define QI_ONCE(code)
Execute code once, parallel calls are blocked until code finishes.
Definition: atomic.hpp:420
qi::detail::signature_function_arg_apply::val
std::string & val
Definition: functionsignature.hxx:24
qi::detail::FunctionSignature
Definition: functionsignature.hxx:103
qi::boost_bind_parameter_types
Definition: bindtype.hxx:246
qi::detail::signature_function_arg_apply
Definition: functionsignature.hxx:15