assign_actor.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*=============================================================================
  2. Copyright (c) 2003 Jonathan de Halleux (dehalleux@pelikhan.com)
  3. http://spirit.sourceforge.net/
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #ifndef BOOST_SPIRIT_ACTOR_ASSIGN_ACTOR_HPP
  8. #define BOOST_SPIRIT_ACTOR_ASSIGN_ACTOR_HPP
  9. #include <boost/spirit/home/classic/namespace.hpp>
  10. #include <boost/spirit/home/classic/actor/ref_value_actor.hpp>
  11. #include <boost/spirit/home/classic/actor/ref_const_ref_actor.hpp>
  12. namespace boost { namespace spirit {
  13. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  14. ///////////////////////////////////////////////////////////////////////////
  15. // Summary:
  16. // A semantic action policy that applies the assignement operator.
  17. // (This doc uses convention available in actors.hpp)
  18. //
  19. // Actions (what it does):
  20. // ref = value;
  21. // ref = T(first,last);
  22. // ref = value_ref;
  23. //
  24. // Policy name:
  25. // assign_action
  26. //
  27. // Policy holder, corresponding helper method:
  28. // ref_value_actor, assign_a( ref );
  29. // ref_const_ref_actor, assign_a( ref, value_ref );
  30. //
  31. // () operators: both
  32. //
  33. // See also ref_value_actor and ref_const_ref_actor for more details.
  34. ///////////////////////////////////////////////////////////////////////////
  35. struct assign_action
  36. {
  37. template<
  38. typename T,
  39. typename ValueT
  40. >
  41. void act(T& ref_, ValueT const& value_) const
  42. {
  43. ref_ = value_;
  44. }
  45. template<
  46. typename T,
  47. typename IteratorT
  48. >
  49. void act(
  50. T& ref_,
  51. IteratorT const& first_,
  52. IteratorT const& last_
  53. ) const
  54. {
  55. typedef T value_type;
  56. #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
  57. value_type value(first_,last_);
  58. #else
  59. value_type value;
  60. std::copy(first_, last_, std::inserter(value, value.end()));
  61. #endif
  62. ref_ = value;
  63. }
  64. };
  65. // Deprecated. Please use assign_a
  66. template<typename T>
  67. inline ref_value_actor<T,assign_action> assign(T& ref_)
  68. {
  69. return ref_value_actor<T,assign_action>(ref_);
  70. }
  71. template<typename T>
  72. inline ref_value_actor<T,assign_action> assign_a(T& ref_)
  73. {
  74. return ref_value_actor<T,assign_action>(ref_);
  75. }
  76. template<
  77. typename T,
  78. typename ValueT
  79. >
  80. inline ref_const_ref_actor<T,ValueT,assign_action> assign_a(
  81. T& ref_,
  82. ValueT const& value_
  83. )
  84. {
  85. return ref_const_ref_actor<T,ValueT,assign_action>(ref_,value_);
  86. }
  87. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  88. }}
  89. #endif