/src/contrib/boost/spirit/home/phoenix/core/value.hpp

http://pythonocc.googlecode.com/ · C++ Header · 155 lines · 121 code · 25 blank · 9 comment · 1 complexity · 675084a8a146ed646c5a8eff5e8fe83e 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_VALUE_HPP
  7. #define PHOENIX_CORE_VALUE_HPP
  8. #include <boost/spirit/home/phoenix/core/actor.hpp>
  9. #include <boost/spirit/home/phoenix/core/as_actor.hpp>
  10. #include <boost/static_assert.hpp>
  11. #include <boost/type_traits/is_reference.hpp>
  12. #include <boost/type_traits/remove_reference.hpp>
  13. #include <boost/type_traits/is_pointer.hpp>
  14. #include <boost/type_traits/add_const.hpp>
  15. #include <boost/type_traits/add_reference.hpp>
  16. #include <boost/type_traits/remove_pointer.hpp>
  17. #include <boost/type_traits/is_function.hpp>
  18. #include <boost/mpl/bool.hpp>
  19. #include <boost/mpl/eval_if.hpp>
  20. #include <boost/mpl/identity.hpp>
  21. namespace boost { namespace phoenix
  22. {
  23. namespace meta
  24. {
  25. template<typename T>
  26. struct const_ref
  27. : add_reference<typename add_const<T>::type>
  28. {};
  29. template<typename T>
  30. struct argument_type
  31. : mpl::eval_if<
  32. is_function<typename remove_pointer<T>::type>,
  33. mpl::identity<T>,
  34. const_ref<T> >
  35. {
  36. typedef T type;
  37. };
  38. }
  39. template <typename T>
  40. struct value
  41. {
  42. BOOST_STATIC_ASSERT(
  43. mpl::not_<is_reference<T> >::value != 0);
  44. typedef mpl::false_ no_nullary;
  45. template <typename Env>
  46. struct result
  47. {
  48. typedef T type;
  49. };
  50. value(T const& arg)
  51. : val(arg) {}
  52. template <typename Env>
  53. T const&
  54. eval(Env const&) const
  55. {
  56. return val;
  57. }
  58. T val;
  59. };
  60. template <typename Actor>
  61. struct actor_value
  62. {
  63. typedef typename Actor::no_nullary no_nullary;
  64. template <typename Env>
  65. struct result
  66. {
  67. typedef typename
  68. remove_reference<
  69. typename eval_result<Actor, Env>::type
  70. >::type
  71. type;
  72. };
  73. actor_value(Actor const& actor)
  74. : actor(actor) {}
  75. template <typename Env>
  76. typename result<Env>::type
  77. eval(Env const& env) const
  78. {
  79. return actor.eval(env);
  80. }
  81. Actor actor;
  82. };
  83. template <typename T>
  84. inline typename as_actor<T>::type
  85. val(T const& v)
  86. {
  87. return as_actor<T>::convert(v);
  88. }
  89. template <typename Derived>
  90. inline actor<actor_value<Derived> >
  91. val(actor<Derived> const& actor)
  92. {
  93. return actor_value<Derived>(actor);
  94. }
  95. template <typename T>
  96. struct as_actor_base
  97. {
  98. typedef value<T> type;
  99. static value<T>
  100. convert(typename meta::argument_type<T>::type x)
  101. {
  102. return value<T>(x);
  103. }
  104. };
  105. // Sometimes it is necessary to auto-convert references to
  106. // a value<T>. This happens when we are re-currying. This
  107. // cannot happen through the standard public actor interfaces.
  108. template <typename T>
  109. struct as_actor_base<T&>
  110. {
  111. typedef value<T> type;
  112. static value<T>
  113. convert(T& x)
  114. {
  115. return value<T>(x);
  116. }
  117. };
  118. template <typename T, int N>
  119. struct as_actor_base<T[N]>
  120. {
  121. typedef value<T const*> type;
  122. static value<T const*>
  123. convert(T const x[N])
  124. {
  125. return value<T const*>(x);
  126. }
  127. };
  128. }}
  129. #endif