/src/contrib/boost/spirit/home/phoenix/bind/detail/member_function_ptr.hpp

http://pythonocc.googlecode.com/ · C++ Header · 119 lines · 87 code · 21 blank · 11 comment · 0 complexity · 3a67467edf9a3d512f0acbc0d202726a MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_PP_IS_ITERATING)
  7. #if !defined(PHOENIX_BIND_DETAIL_MEMBER_FUNCTION_PTR_HPP)
  8. #define PHOENIX_BIND_DETAIL_MEMBER_FUNCTION_PTR_HPP
  9. #include <boost/preprocessor/iterate.hpp>
  10. #include <boost/preprocessor/repetition/enum_params.hpp>
  11. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  12. #include <boost/preprocessor/dec.hpp>
  13. #include <boost/utility/addressof.hpp>
  14. namespace boost { namespace phoenix { namespace detail
  15. {
  16. template <int N>
  17. struct member_function_ptr_impl
  18. {
  19. template <typename RT, typename FP>
  20. struct impl;
  21. };
  22. template <int N, typename RT, typename FP>
  23. struct member_function_ptr
  24. : member_function_ptr_impl<N>::template impl<RT, FP>
  25. {
  26. typedef typename member_function_ptr_impl<N>::
  27. template impl<RT, FP> base;
  28. member_function_ptr(FP fp)
  29. : base(fp) {}
  30. };
  31. template <>
  32. struct member_function_ptr_impl<0>
  33. {
  34. template <typename RT, typename FP>
  35. struct impl
  36. {
  37. template <typename Class>
  38. struct result
  39. {
  40. typedef RT type;
  41. };
  42. impl(FP fp)
  43. : fp(fp) {}
  44. template <typename Class>
  45. RT operator()(Class& obj) const
  46. {
  47. return (obj.*fp)();
  48. }
  49. template <typename Class>
  50. RT operator()(Class* obj) const
  51. {
  52. return (obj->*fp)();
  53. }
  54. FP fp;
  55. };
  56. };
  57. #define BOOST_PP_ITERATION_PARAMS_1 \
  58. (3, (1, PHOENIX_COMPOSITE_LIMIT, \
  59. "boost/spirit/home/phoenix/bind/detail/member_function_ptr.hpp"))
  60. #include BOOST_PP_ITERATE()
  61. }}} // namespace boost::phoenix::detail
  62. #endif
  63. ///////////////////////////////////////////////////////////////////////////////
  64. //
  65. // Preprocessor vertical repetition code
  66. //
  67. ///////////////////////////////////////////////////////////////////////////////
  68. #else // defined(BOOST_PP_IS_ITERATING)
  69. #define N BOOST_PP_ITERATION()
  70. template <>
  71. struct member_function_ptr_impl<N>
  72. {
  73. template <typename RT, typename FP>
  74. struct impl
  75. {
  76. template <typename Class, BOOST_PP_ENUM_PARAMS(N, typename T)>
  77. struct result
  78. {
  79. typedef RT type;
  80. };
  81. impl(FP fp)
  82. : fp(fp) {}
  83. template <typename Class, BOOST_PP_ENUM_PARAMS(N, typename A)>
  84. RT operator()(Class& obj, BOOST_PP_ENUM_BINARY_PARAMS(N, A, & _)) const
  85. {
  86. return (obj.*fp)(BOOST_PP_ENUM_PARAMS(N, _));
  87. }
  88. template <typename Class, BOOST_PP_ENUM_PARAMS(N, typename A)>
  89. RT operator()(Class* obj, BOOST_PP_ENUM_BINARY_PARAMS(N, A, & _)) const
  90. {
  91. return (obj->*fp)(BOOST_PP_ENUM_PARAMS(N, _));
  92. }
  93. FP fp;
  94. };
  95. };
  96. #undef N
  97. #endif // defined(BOOST_PP_IS_ITERATING)