/Src/Dependencies/Boost/boost/spirit/home/phoenix/core/actor.hpp

http://hadesmem.googlecode.com/ · C++ Header · 194 lines · 142 code · 35 blank · 17 comment · 0 complexity · 07283f775706a2fae679604a9dd33261 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. #ifndef PHOENIX_CORE_ACTOR_HPP
  7. #define PHOENIX_CORE_ACTOR_HPP
  8. #include <boost/spirit/home/phoenix/core/limits.hpp>
  9. #if !defined(BOOST_RESULT_OF_NUM_ARGS)
  10. # define BOOST_RESULT_OF_NUM_ARGS PHOENIX_ACTOR_LIMIT
  11. #elif (BOOST_RESULT_OF_NUM_ARGS < PHOENIX_ACTOR_LIMIT)
  12. # error "BOOST_RESULT_OF_NUM_ARGS < PHOENIX_ACTOR_LIMIT"
  13. #endif
  14. #include <boost/spirit/home/phoenix/core/basic_environment.hpp>
  15. #include <boost/mpl/min.hpp>
  16. #include <boost/mpl/identity.hpp>
  17. #include <boost/type_traits/add_const.hpp>
  18. #include <boost/type_traits/remove_reference.hpp>
  19. #include <boost/utility/result_of.hpp>
  20. namespace boost { namespace phoenix
  21. {
  22. // phoenix::void_ is the same as fusion::void_
  23. typedef fusion::void_ void_;
  24. namespace detail
  25. {
  26. // Forward declarations. These will come in when we get to the
  27. // operator module, yet, the actor's assignment operator and index
  28. // operator are required to be members.
  29. template <typename T0, typename T1>
  30. struct make_assign_composite;
  31. template <typename T0, typename T1>
  32. struct make_index_composite;
  33. template <typename BaseT0, typename BaseT1>
  34. struct comma_result;
  35. // error no arguments supplied
  36. struct error_expecting_arguments
  37. {
  38. template <typename T>
  39. error_expecting_arguments(T const&) {}
  40. };
  41. }
  42. template <typename Eval, typename Env>
  43. struct eval_result
  44. {
  45. typedef typename Eval::template result<Env>::type type;
  46. };
  47. #if defined(BOOST_MSVC)
  48. # pragma warning(push)
  49. # pragma warning(disable: 4522) // multiple assignment operators specified warning
  50. #endif
  51. template <typename Eval>
  52. struct actor : Eval
  53. {
  54. typedef actor<Eval> self_type;
  55. typedef Eval eval_type;
  56. template <class Sig> struct result {};
  57. actor()
  58. : Eval() {}
  59. actor(Eval const& base)
  60. : Eval(base) {}
  61. template <typename T0>
  62. explicit actor(T0 const& _0)
  63. : Eval(_0) {}
  64. template <typename T0, typename T1>
  65. actor(T0 const& _0, T1 const& _1)
  66. : Eval(_0, _1) {}
  67. typedef typename
  68. mpl::eval_if<
  69. typename Eval::no_nullary // avoid calling eval_result when this is true
  70. , mpl::identity<detail::error_expecting_arguments>
  71. , eval_result<eval_type, basic_environment<> >
  72. >::type
  73. nullary_result;
  74. actor& operator=(actor const& rhs)
  75. {
  76. Eval::operator=(rhs);
  77. return *this;
  78. }
  79. actor& operator=(actor& rhs)
  80. {
  81. Eval::operator=(rhs);
  82. return *this;
  83. }
  84. nullary_result
  85. operator()() const
  86. {
  87. return eval_type::eval(basic_environment<>());
  88. }
  89. template <class F, class A0>
  90. struct result<F(A0)>
  91. : eval_result<
  92. eval_type
  93. , basic_environment<
  94. typename remove_reference<A0>::type
  95. >
  96. >
  97. {};
  98. template <typename T0>
  99. typename result<actor(T0&)>::type
  100. operator()(T0& _0) const
  101. {
  102. return eval_type::eval(basic_environment<T0>(_0));
  103. }
  104. template <class F, class A0, class A1>
  105. struct result<F(A0,A1)>
  106. : eval_result<
  107. eval_type
  108. , basic_environment<
  109. typename remove_reference<A0>::type
  110. , typename remove_reference<A1>::type
  111. >
  112. >
  113. {};
  114. template <typename T0, typename T1>
  115. typename result<actor(T0&,T1&)>::type
  116. operator()(T0& _0, T1& _1) const
  117. {
  118. return eval_type::eval(basic_environment<T0, T1>(_0, _1));
  119. }
  120. template <typename T1>
  121. typename detail::make_assign_composite<self_type, T1>::type
  122. operator=(T1 const& a1) const;
  123. template <typename T1>
  124. typename detail::make_index_composite<self_type, T1>::type
  125. operator[](T1 const& a1) const;
  126. // Bring in the rest of the constructors and function call operators
  127. #include <boost/spirit/home/phoenix/core/detail/actor.hpp>
  128. };
  129. #if defined(BOOST_MSVC)
  130. # pragma warning(pop)
  131. #endif
  132. // Forward declaration: The intent to overload the comma must be
  133. // stated early on to avoid the subtle problem that arises when
  134. // the header file where the comma operator overload is defined,
  135. // is not included by the client and the client attempts to use
  136. // the comma anyway.
  137. namespace detail
  138. {
  139. template <typename BaseT0, typename BaseT1>
  140. struct comma_result;
  141. }
  142. template <typename BaseT0, typename BaseT1>
  143. typename detail::comma_result<BaseT0, BaseT1>::type
  144. operator,(actor<BaseT0> const& a0, actor<BaseT1> const& a1);
  145. }}
  146. namespace boost
  147. {
  148. template <typename Eval>
  149. struct result_of<phoenix::actor<Eval>()>
  150. {
  151. typedef typename phoenix::actor<Eval>::nullary_result type;
  152. };
  153. template <typename Eval>
  154. struct result_of<phoenix::actor<Eval> const()>
  155. : result_of<phoenix::actor<Eval>()>
  156. {};
  157. }
  158. #endif