push_back_actor.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_PUSH_BACK_ACTOR_HPP
  8. #define BOOST_SPIRIT_ACTOR_PUSH_BACK_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. //
  17. // A semantic action policy that appends a value to the back of a
  18. // container.
  19. // (This doc uses convention available in actors.hpp)
  20. //
  21. // Actions (what it does and what ref, value_ref must support):
  22. // ref.push_back( value );
  23. // ref.push_back( T::value_type(first,last) );
  24. // ref.push_back( value_ref );
  25. //
  26. // Policy name:
  27. // push_back_action
  28. //
  29. // Policy holder, corresponding helper method:
  30. // ref_value_actor, push_back_a( ref );
  31. // ref_const_ref_actor, push_back_a( ref, value_ref );
  32. //
  33. // () operators: both
  34. //
  35. // See also ref_value_actor and ref_const_ref_actor for more details.
  36. ///////////////////////////////////////////////////////////////////////////
  37. struct push_back_action
  38. {
  39. template<
  40. typename T,
  41. typename ValueT
  42. >
  43. void act(T& ref_, ValueT const& value_) const
  44. {
  45. ref_.push_back( value_ );
  46. }
  47. template<
  48. typename T,
  49. typename IteratorT
  50. >
  51. void act(
  52. T& ref_,
  53. IteratorT const& first_,
  54. IteratorT const& last_
  55. ) const
  56. {
  57. typedef typename T::value_type value_type;
  58. value_type value(first_,last_);
  59. ref_.push_back( value );
  60. }
  61. };
  62. // Deprecated interface. Use push_back_a
  63. template<typename T>
  64. inline ref_value_actor<T,push_back_action>
  65. append(T& ref_)
  66. {
  67. return ref_value_actor<T,push_back_action>(ref_);
  68. }
  69. template<typename T>
  70. inline ref_value_actor<T,push_back_action>
  71. push_back_a(T& ref_)
  72. {
  73. return ref_value_actor<T,push_back_action>(ref_);
  74. }
  75. template<
  76. typename T,
  77. typename ValueT
  78. >
  79. inline ref_const_ref_actor<T,ValueT,push_back_action>
  80. push_back_a(
  81. T& ref_,
  82. ValueT const& value_
  83. )
  84. {
  85. return ref_const_ref_actor<T,ValueT,push_back_action>(ref_,value_);
  86. }
  87. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  88. }}
  89. #endif