assign_key_actor.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_KEY_ACTOR_HPP
  8. #define BOOST_SPIRIT_ACTOR_ASSIGN_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. #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. struct assign_key_action
  15. {
  16. template<
  17. typename T,
  18. typename ValueT,
  19. typename KeyT
  20. >
  21. void act(T& ref_, ValueT const& value_, KeyT const& key_) const
  22. {
  23. ref_[ key_ ] = value_;
  24. }
  25. template<
  26. typename T,
  27. typename ValueT,
  28. typename IteratorT
  29. >
  30. void act(
  31. T& ref_,
  32. ValueT const& value_,
  33. IteratorT const& first_,
  34. IteratorT const& last_
  35. ) const
  36. {
  37. typedef typename T::key_type key_type;
  38. key_type key(first_,last_);
  39. ref_[key] = value_;
  40. }
  41. };
  42. template<
  43. typename T,
  44. typename ValueT
  45. >
  46. inline ref_const_ref_value_actor<T,ValueT,assign_key_action>
  47. assign_key_a(T& ref_, ValueT const& value_)
  48. {
  49. return ref_const_ref_value_actor<T,ValueT,assign_key_action>(
  50. ref_,
  51. value_
  52. );
  53. }
  54. template<
  55. typename T,
  56. typename ValueT,
  57. typename KeyT
  58. >
  59. inline ref_const_ref_const_ref_actor<
  60. T,
  61. ValueT,
  62. KeyT,
  63. assign_key_action
  64. >
  65. assign_key_a(
  66. T& ref_,
  67. ValueT const& value_,
  68. KeyT const& key_
  69. )
  70. {
  71. return ref_const_ref_const_ref_actor<
  72. T,
  73. ValueT,
  74. KeyT,
  75. assign_key_action
  76. >(
  77. ref_,
  78. value_,
  79. key_
  80. );
  81. }
  82. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  83. }}
  84. #endif