phoenix_attributes.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. //
  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. #if !defined(BOOST_SPIRIT_KARMA_PHOENIX_ATTRIBUTES_OCT_01_2009_1128AM)
  6. #define BOOST_SPIRIT_KARMA_PHOENIX_ATTRIBUTES_OCT_01_2009_1128AM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/include/version.hpp>
  11. // we support Phoenix attributes only starting with V2.2
  12. #if SPIRIT_VERSION >= 0x2020
  13. #include <boost/spirit/home/karma/detail/attributes.hpp>
  14. #include <boost/spirit/home/karma/detail/indirect_iterator.hpp>
  15. #include <boost/spirit/home/support/container.hpp>
  16. #include <boost/utility/result_of.hpp>
  17. ///////////////////////////////////////////////////////////////////////////////
  18. namespace boost { namespace phoenix
  19. {
  20. template <typename Expr>
  21. struct actor;
  22. }}
  23. ///////////////////////////////////////////////////////////////////////////////
  24. namespace boost { namespace spirit { namespace traits
  25. {
  26. ///////////////////////////////////////////////////////////////////////////
  27. // Provide customization points allowing the use of phoenix expressions as
  28. // generator functions in the context of generators expecting a container
  29. // attribute (Kleene, plus, list, repeat, etc.)
  30. ///////////////////////////////////////////////////////////////////////////
  31. template <typename Eval>
  32. struct is_container<phoenix::actor<Eval> const>
  33. : is_container<typename boost::result_of<phoenix::actor<Eval>()>::type>
  34. {};
  35. template <typename Eval>
  36. struct container_iterator<phoenix::actor<Eval> const>
  37. {
  38. typedef phoenix::actor<Eval> const& type;
  39. };
  40. template <typename Eval>
  41. struct begin_container<phoenix::actor<Eval> const>
  42. {
  43. typedef phoenix::actor<Eval> const& type;
  44. static type call(phoenix::actor<Eval> const& f)
  45. {
  46. return f;
  47. }
  48. };
  49. template <typename Eval>
  50. struct end_container<phoenix::actor<Eval> const>
  51. {
  52. typedef phoenix::actor<Eval> const& type;
  53. static type call(phoenix::actor<Eval> const& f)
  54. {
  55. return f;
  56. }
  57. };
  58. template <typename Eval>
  59. struct deref_iterator<phoenix::actor<Eval> const>
  60. {
  61. typedef typename boost::result_of<phoenix::actor<Eval>()>::type type;
  62. static type call(phoenix::actor<Eval> const& f)
  63. {
  64. return f();
  65. }
  66. };
  67. template <typename Eval>
  68. struct next_iterator<phoenix::actor<Eval> const>
  69. {
  70. typedef phoenix::actor<Eval> const& type;
  71. static type call(phoenix::actor<Eval> const& f)
  72. {
  73. return f;
  74. }
  75. };
  76. template <typename Eval>
  77. struct compare_iterators<phoenix::actor<Eval> const>
  78. {
  79. static bool
  80. call(phoenix::actor<Eval> const&, phoenix::actor<Eval> const&)
  81. {
  82. return false;
  83. }
  84. };
  85. template <typename Eval>
  86. struct container_value<phoenix::actor<Eval> >
  87. {
  88. typedef phoenix::actor<Eval> const& type;
  89. };
  90. template <typename Eval>
  91. struct make_indirect_iterator<phoenix::actor<Eval> const>
  92. {
  93. typedef phoenix::actor<Eval> const& type;
  94. };
  95. ///////////////////////////////////////////////////////////////////////////
  96. // Handle Phoenix actors as attributes, just invoke the function object
  97. // and deal with the result as the attribute.
  98. ///////////////////////////////////////////////////////////////////////////
  99. template <typename Eval, typename Exposed>
  100. struct extract_from_attribute<phoenix::actor<Eval>, Exposed>
  101. {
  102. typedef typename boost::result_of<phoenix::actor<Eval>()>::type type;
  103. template <typename Context>
  104. static type call(phoenix::actor<Eval> const& f, Context& context)
  105. {
  106. return f(unused, context);
  107. }
  108. };
  109. }}}
  110. #endif
  111. #endif