signature.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #if !defined(BOOST_PP_IS_ITERATING)
  2. // Copyright David Abrahams 2002.
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. # ifndef SIGNATURE_DWA20021121_HPP
  7. # define SIGNATURE_DWA20021121_HPP
  8. # include <boost/python/type_id.hpp>
  9. # include <boost/python/detail/preprocessor.hpp>
  10. # include <boost/python/detail/indirect_traits.hpp>
  11. # include <boost/python/converter/pytype_function.hpp>
  12. # include <boost/preprocessor/iterate.hpp>
  13. # include <boost/preprocessor/iteration/local.hpp>
  14. # include <boost/mpl/at.hpp>
  15. # include <boost/mpl/size.hpp>
  16. namespace boost { namespace python { namespace detail {
  17. struct signature_element
  18. {
  19. char const* basename;
  20. converter::pytype_function pytype_f;
  21. bool lvalue;
  22. };
  23. struct py_func_sig_info
  24. {
  25. signature_element const *signature;
  26. signature_element const *ret;
  27. };
  28. template <unsigned> struct signature_arity;
  29. # define BOOST_PP_ITERATION_PARAMS_1 \
  30. (3, (0, BOOST_PYTHON_MAX_ARITY + 1, <boost/python/detail/signature.hpp>))
  31. # include BOOST_PP_ITERATE()
  32. // A metafunction returning the base class used for
  33. //
  34. // signature<class F, class CallPolicies, class Sig>.
  35. //
  36. template <class Sig>
  37. struct signature_base_select
  38. {
  39. enum { arity = mpl::size<Sig>::value - 1 };
  40. typedef typename signature_arity<arity>::template impl<Sig> type;
  41. };
  42. template <class Sig>
  43. struct signature
  44. : signature_base_select<Sig>::type
  45. {
  46. };
  47. }}} // namespace boost::python::detail
  48. # endif // SIGNATURE_DWA20021121_HPP
  49. #else
  50. # define N BOOST_PP_ITERATION()
  51. template <>
  52. struct signature_arity<N>
  53. {
  54. template <class Sig>
  55. struct impl
  56. {
  57. static signature_element const* elements()
  58. {
  59. static signature_element const result[N+2] = {
  60. #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
  61. # define BOOST_PP_LOCAL_MACRO(i) \
  62. { \
  63. type_id<BOOST_DEDUCED_TYPENAME mpl::at_c<Sig,i>::type>().name() \
  64. , &converter::expected_pytype_for_arg<BOOST_DEDUCED_TYPENAME mpl::at_c<Sig,i>::type>::get_pytype \
  65. , indirect_traits::is_reference_to_non_const<BOOST_DEDUCED_TYPENAME mpl::at_c<Sig,i>::type>::value \
  66. },
  67. #else
  68. # define BOOST_PP_LOCAL_MACRO(i) \
  69. { \
  70. type_id<BOOST_DEDUCED_TYPENAME mpl::at_c<Sig,i>::type>().name() \
  71. , 0 \
  72. , indirect_traits::is_reference_to_non_const<BOOST_DEDUCED_TYPENAME mpl::at_c<Sig,i>::type>::value \
  73. },
  74. #endif
  75. # define BOOST_PP_LOCAL_LIMITS (0, N)
  76. # include BOOST_PP_LOCAL_ITERATE()
  77. {0,0,0}
  78. };
  79. return result;
  80. }
  81. };
  82. };
  83. #endif // BOOST_PP_IS_ITERATING