libqi-api  2.8.7.4
 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 {
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  >
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  >
77  signature += ')';
78  return Signature(signature);
79  }
80  };
81 
82  template<typename T>
84  {
86  {
87  using ResultType = typename boost::function_types::result_type<T>::type;
88  return typeOf<ResultType>()->signature();
89  }
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>
104  {
105  using Backend = typename boost::mpl::if_<
106  typename boost::function_types::is_member_pointer<T>,
108  RawFunctionSignature<T>
109  >::type;
111  {
112  static qi::Signature result = Backend::makeSignature();
113  return result;
114  }
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
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
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_
static qi::Signature sigreturn()
qi::Signature functionArgumentsSignature()
typename boost::mpl::if_< typename boost::function_types::is_member_pointer< T >, MemberFunctionSignature< T >, RawFunctionSignature< T > >::type Backend
static qi::Signature signature()
qi::Signature _functionArgumentsSignature()
Various macros for qi. (deprecated, export API, disallow copy, ..) <includename>qi/macro.hpp</includename> .
#define QI_ONCE(code)
Execute code once, parallel calls are blocked until code finishes.
Definition: atomic.hpp:420