member_function_ptr.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 !BOOST_PHOENIX_IS_ITERATING
  7. #ifndef BOOST_PHOENIX_BIND_DETAIL_MEMBER_FUNCTION_PTR_HPP
  8. #define BOOST_PHOENIX_BIND_DETAIL_MEMBER_FUNCTION_PTR_HPP
  9. #include <boost/phoenix/core/limits.hpp>
  10. #include <boost/phoenix/support/iterate.hpp>
  11. namespace boost { namespace phoenix { namespace detail
  12. {
  13. template <int N>
  14. struct member_function_ptr_impl
  15. {
  16. template <typename RT, typename FP>
  17. struct impl;
  18. };
  19. template <int N, typename RT, typename FP>
  20. struct member_function_ptr
  21. : member_function_ptr_impl<N>::template impl<RT, FP>
  22. {
  23. typedef typename member_function_ptr_impl<N>::
  24. template impl<RT, FP> base;
  25. member_function_ptr(FP fp)
  26. : base(fp) {}
  27. using base::fp;
  28. bool operator==(member_function_ptr const & rhs) const
  29. {
  30. return fp == rhs.fp;
  31. }
  32. template <int M, typename RhsRT, typename RhsFP>
  33. bool operator==(member_function_ptr<M, RhsRT, RhsFP> const & rhs) const
  34. {
  35. return false;
  36. }
  37. };
  38. template <>
  39. struct member_function_ptr_impl<0>
  40. {
  41. template <typename RT, typename FP>
  42. struct impl
  43. {
  44. typedef RT result_type;
  45. impl(FP fp)
  46. : fp(fp) {}
  47. template <typename Class>
  48. RT operator()(Class& obj) const
  49. {
  50. BOOST_PROTO_USE_GET_POINTER();
  51. typedef typename proto::detail::class_member_traits<FP>::class_type class_type;
  52. return (BOOST_PROTO_GET_POINTER(class_type, obj) ->*fp)();
  53. }
  54. template <typename Class>
  55. RT operator()(Class* obj) const
  56. {
  57. return (obj->*fp)();
  58. }
  59. FP fp;
  60. };
  61. };
  62. #if !defined(BOOST_PHOENIX_DONT_USE_PREPROCESSED_FILES)
  63. #include <boost/phoenix/bind/detail/preprocessed/member_function_ptr.hpp>
  64. #else
  65. #if defined(__WAVE__) && defined (BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  66. #pragma wave option(preserve: 2, line: 0, output: "preprocessed/member_function_ptr_" BOOST_PHOENIX_LIMIT_STR ".hpp")
  67. #endif
  68. /*=============================================================================
  69. Copyright (c) 2001-2007 Joel de Guzman
  70. Distributed under the Boost Software License, Version 1.0. (See accompanying
  71. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  72. ==============================================================================*/
  73. #if defined(__WAVE__) && defined(BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  74. #pragma wave option(preserve: 1)
  75. #endif
  76. #define BOOST_PHOENIX_ITERATION_PARAMS \
  77. (3, (1, BOOST_PHOENIX_COMPOSITE_LIMIT, \
  78. <boost/phoenix/bind/detail/member_function_ptr.hpp>))
  79. #include BOOST_PHOENIX_ITERATE()
  80. #if defined(__WAVE__) && defined (BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  81. #pragma wave option(output: null)
  82. #endif
  83. #endif
  84. }}} // namespace boost::phoenix::detail
  85. #endif
  86. ///////////////////////////////////////////////////////////////////////////////
  87. //
  88. // Preprocessor vertical repetition code
  89. //
  90. ///////////////////////////////////////////////////////////////////////////////
  91. #else
  92. template <>
  93. struct member_function_ptr_impl<BOOST_PHOENIX_ITERATION>
  94. {
  95. template <typename RT, typename FP>
  96. struct impl
  97. {
  98. typedef RT result_type;
  99. impl(FP fp)
  100. : fp(fp) {}
  101. template <typename Class, BOOST_PHOENIX_typename_A>
  102. RT operator()(Class& obj, BOOST_PHOENIX_A_ref_a) const
  103. {
  104. BOOST_PROTO_USE_GET_POINTER();
  105. typedef typename proto::detail::class_member_traits<FP>::class_type class_type;
  106. return (BOOST_PROTO_GET_POINTER(class_type, obj)->*fp)(BOOST_PHOENIX_a);
  107. }
  108. template <typename Class, BOOST_PHOENIX_typename_A>
  109. RT operator()(Class* obj, BOOST_PHOENIX_A_ref_a) const
  110. {
  111. return (obj->*fp)(BOOST_PHOENIX_a);
  112. }
  113. FP fp;
  114. };
  115. };
  116. #endif // defined(BOOST_PP_IS_ITERATING)