insert_at_actor.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_INSERT_AT_ACTOR_HPP
  8. #define BOOST_SPIRIT_ACTOR_INSERT_AT_ACTOR_HPP
  9. #include <boost/spirit/home/classic/namespace.hpp>
  10. #include <boost/spirit/home/classic/actor/ref_const_ref_value_actor.hpp>
  11. #include <boost/spirit/home/classic/actor/ref_const_ref_const_ref_a.hpp>
  12. namespace boost { namespace spirit {
  13. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  14. ///////////////////////////////////////////////////////////////////////////
  15. // Summary:
  16. // A semantic action policy that insert data into an associative
  17. // container using a const reference to a key.
  18. // (This doc uses convention available in actors.hpp)
  19. //
  20. // Actions (what it does):
  21. // ref.insert( T::value_type(key_ref,value) );
  22. // ref.insert( T::value_type(key_ref, T::mapped_type(first,last)));;
  23. // ref.insert( T::value_type(key_ref,value_ref) );
  24. //
  25. // Policy name:
  26. // insert_at_action
  27. //
  28. // Policy holder, corresponding helper method:
  29. // ref_const_ref_value_actor, insert_at_a( ref, key_ref );
  30. // ref_const_ref_const_ref_actor, insert_a( ref, key_ref, value_ref );
  31. //
  32. // () operators: both
  33. //
  34. // See also ref_const_ref_value_actor and ref_const_ref_const_ref_actor
  35. // for more details.
  36. ///////////////////////////////////////////////////////////////////////////
  37. struct insert_at_action
  38. {
  39. template<
  40. typename T,
  41. typename ReferentT,
  42. typename ValueT
  43. >
  44. void act(
  45. T& ref_,
  46. ReferentT const& key_,
  47. ValueT const& value_
  48. ) const
  49. {
  50. typedef typename T::value_type value_type;
  51. ref_.insert( value_type(key_, value_) );
  52. }
  53. template<
  54. typename T,
  55. typename ReferentT,
  56. typename IteratorT
  57. >
  58. void act(
  59. T& ref_,
  60. ReferentT const& key_,
  61. IteratorT const& first_,
  62. IteratorT const& last_
  63. ) const
  64. {
  65. typedef typename T::mapped_type mapped_type;
  66. typedef typename T::value_type value_type;
  67. mapped_type value(first_,last_);
  68. value_type key_value(key_, value);
  69. ref_.insert( key_value );
  70. }
  71. };
  72. template<
  73. typename T,
  74. typename ReferentT
  75. >
  76. inline ref_const_ref_value_actor<T,ReferentT,insert_at_action>
  77. insert_at_a(
  78. T& ref_,
  79. ReferentT const& key_
  80. )
  81. {
  82. return ref_const_ref_value_actor<
  83. T,
  84. ReferentT,
  85. insert_at_action
  86. >(ref_,key_);
  87. }
  88. template<
  89. typename T,
  90. typename ReferentT,
  91. typename ValueT
  92. >
  93. inline ref_const_ref_const_ref_actor<T,ReferentT,ValueT,insert_at_action>
  94. insert_at_a(
  95. T& ref_,
  96. ReferentT const& key_,
  97. ValueT const& value_
  98. )
  99. {
  100. return ref_const_ref_const_ref_actor<
  101. T,
  102. ReferentT,
  103. ValueT,
  104. insert_at_action
  105. >(ref_,key_,value_);
  106. }
  107. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  108. }}
  109. #endif