push_front_actor.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_FRONT_ACTOR_HPP
  8. #define BOOST_SPIRIT_ACTOR_PUSH_FRONT_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 front 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_front( value );
  23. // ref.push_front( T::value_type(first,last) );
  24. // ref.push_front( value_ref );
  25. //
  26. // Policy name:
  27. // push_front_action
  28. //
  29. // Policy holder, corresponding helper method:
  30. // ref_value_actor, push_front_a( ref );
  31. // ref_const_ref_actor, push_front_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_front_action
  38. {
  39. template<
  40. typename T,
  41. typename ValueT
  42. >
  43. void act(T& ref_, ValueT const& value_) const
  44. {
  45. ref_.push_front( 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_front( value );
  60. }
  61. };
  62. template<typename T>
  63. inline ref_value_actor<T,push_front_action> push_front_a(T& ref_)
  64. {
  65. return ref_value_actor<T,push_front_action>(ref_);
  66. }
  67. template<
  68. typename T,
  69. typename ValueT
  70. >
  71. inline ref_const_ref_actor<T,ValueT,push_front_action> push_front_a(
  72. T& ref_,
  73. ValueT const& value_
  74. )
  75. {
  76. return ref_const_ref_actor<T,ValueT,push_front_action>(ref_,value_);
  77. }
  78. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  79. }}
  80. #endif