switch.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #if !defined(BOOST_PHOENIX_DONT_USE_PREPROCESSED_FILES)
  2. #ifndef BOOST_PHOENIX_STATEMENT_DETAIL_SWITCH_HPP
  3. #define BOOST_PHOENIX_STATEMENT_DETAIL_SWITCH_HPP
  4. #include <boost/phoenix/support/iterate.hpp>
  5. #include <boost/phoenix/statement/detail/preprocessed/switch.hpp>
  6. #endif
  7. #else
  8. #if !BOOST_PHOENIX_IS_ITERATING
  9. #ifndef BOOST_PHOENIX_STATEMENT_DETAIL_SWITCH_HPP
  10. #define BOOST_PHOENIX_STATEMENT_DETAIL_SWITCH_HPP
  11. #include <boost/phoenix/support/iterate.hpp>
  12. #if defined(__WAVE__) && defined(BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  13. #pragma wave option(preserve: 2, line: 0, output: "preprocessed/switch_" BOOST_PHOENIX_LIMIT_STR ".hpp")
  14. #endif
  15. /*==============================================================================
  16. Copyright (c) 2005-2010 Joel de Guzman
  17. Copyright (c) 2010 Thomas Heller
  18. Distributed under the Boost Software License, Version 1.0. (See accompanying
  19. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  20. ==============================================================================*/
  21. #if defined(__WAVE__) && defined(BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  22. #pragma wave option(preserve: 1)
  23. #endif
  24. #define BOOST_PHOENIX_SWITCH_EVAL_TYPEDEF_R(Z, N, DATA) \
  25. typedef \
  26. typename fusion::result_of::deref< \
  27. typename fusion::result_of::advance_c< \
  28. flat_view_begin \
  29. , N \
  30. >::type \
  31. >::type \
  32. BOOST_PP_CAT(case, N); \
  33. typedef \
  34. typename proto::detail::uncvref< \
  35. typename proto::result_of::value< \
  36. typename proto::result_of::child_c< \
  37. BOOST_PP_CAT(case, N) \
  38. , 0 \
  39. >::type \
  40. >::type \
  41. >::type \
  42. BOOST_PP_CAT(case_label, N); \
  43. /**/
  44. #define BOOST_PHOENIX_SWITCH_EVAL_R(Z, N, DATA) \
  45. case BOOST_PP_CAT(case_label, N)::value : \
  46. boost::phoenix::eval( \
  47. proto::child_c<1>( \
  48. fusion::deref( \
  49. fusion::advance_c<N>(fusion::begin(flat_view)) \
  50. ) \
  51. ) \
  52. , ctx \
  53. ); \
  54. break; \
  55. /**/
  56. #define BOOST_PHOENIX_ITERATION_PARAMS \
  57. (3, (2, BOOST_PHOENIX_LIMIT, \
  58. <boost/phoenix/statement/detail/switch.hpp>))
  59. #include BOOST_PHOENIX_ITERATE()
  60. #undef BOOST_PHOENIX_SWITCH_EVAL_R
  61. #undef BOOST_PHOENIX_SWITCH_EVAL_TYPEDEF
  62. #if defined(__WAVE__) && defined(BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  63. #pragma wave option(output: null)
  64. #endif
  65. #endif
  66. #else
  67. template <typename Context, typename Cond, typename Cases>
  68. result_type
  69. evaluate(
  70. Context const & ctx
  71. , Cond const & cond
  72. , Cases const & cases
  73. , mpl::int_<BOOST_PHOENIX_ITERATION>
  74. , mpl::false_
  75. ) const
  76. {
  77. typedef
  78. typename proto::result_of::flatten<Cases const&>::type
  79. flat_view_type;
  80. typedef
  81. typename fusion::result_of::begin<flat_view_type>::type
  82. flat_view_begin;
  83. flat_view_type flat_view(proto::flatten(cases));
  84. BOOST_PP_REPEAT(
  85. BOOST_PHOENIX_ITERATION
  86. , BOOST_PHOENIX_SWITCH_EVAL_TYPEDEF_R
  87. , BOOST_PHOENIX_ITERATION
  88. )
  89. switch(boost::phoenix::eval(cond, ctx))
  90. {
  91. BOOST_PP_REPEAT(BOOST_PHOENIX_ITERATION, BOOST_PHOENIX_SWITCH_EVAL_R, _)
  92. }
  93. }
  94. template <typename Context, typename Cond, typename Cases>
  95. result_type
  96. evaluate(
  97. Context const & ctx
  98. , Cond const & cond
  99. , Cases const & cases
  100. , mpl::int_<BOOST_PHOENIX_ITERATION>
  101. , mpl::true_
  102. ) const
  103. {
  104. typedef
  105. typename proto::result_of::flatten<Cases const&>::type
  106. flat_view_type;
  107. typedef
  108. typename fusion::result_of::begin<flat_view_type>::type
  109. flat_view_begin;
  110. flat_view_type flat_view(proto::flatten(cases));
  111. BOOST_PP_REPEAT(
  112. BOOST_PP_DEC(BOOST_PHOENIX_ITERATION)
  113. , BOOST_PHOENIX_SWITCH_EVAL_TYPEDEF_R
  114. , BOOST_PHOENIX_ITERATION
  115. )
  116. switch(boost::phoenix::eval(cond, ctx))
  117. {
  118. BOOST_PP_REPEAT(
  119. BOOST_PP_DEC(BOOST_PHOENIX_ITERATION)
  120. , BOOST_PHOENIX_SWITCH_EVAL_R, _
  121. )
  122. default:
  123. boost::phoenix::eval(
  124. proto::child_c<0>(
  125. fusion::deref(
  126. fusion::advance_c<
  127. BOOST_PP_DEC(BOOST_PHOENIX_ITERATION)
  128. >(fusion::begin(flat_view))
  129. )
  130. )
  131. , ctx
  132. );
  133. }
  134. }
  135. #endif
  136. #endif // BOOST_PHOENIX_DONT_USE_PREPROCESSED_FILES