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