phoenix_attributes.hpp 3.7 KB

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