insert_key_actor.hpp 2.8 KB

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