erase_actor.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_ERASE_ACTOR_HPP
  8. #define BOOST_SPIRIT_ACTOR_ERASE_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. // A semantic action policy that calss the erase method.
  17. // (This doc uses convention available in actors.hpp)
  18. //
  19. // Actions (what it does):
  20. // ref.erase( value );
  21. // ref.erase( T::key_type(first,last) );
  22. // ref.erase( key_ref );
  23. //
  24. // Policy name:
  25. // erase_action
  26. //
  27. // Policy holder, corresponding helper method:
  28. // ref_value_actor, erase_a( ref );
  29. // ref_const_ref_actor, erase_a( ref, key_ref );
  30. //
  31. // () operators: both
  32. //
  33. // See also ref_value_actor and ref_const_ref_actor for more details.
  34. ///////////////////////////////////////////////////////////////////////////
  35. struct erase_action
  36. {
  37. template<
  38. typename T,
  39. typename KeyT
  40. >
  41. void act(T& ref_, KeyT const& key_) const
  42. {
  43. ref_.erase(key_);
  44. }
  45. template<
  46. typename T,
  47. typename IteratorT
  48. >
  49. void act(
  50. T& ref_,
  51. IteratorT const& first_,
  52. IteratorT const& last_
  53. ) const
  54. {
  55. typedef typename T::key_type key_type;
  56. key_type key(first_,last_);
  57. ref_.erase(key);
  58. }
  59. };
  60. template<typename T>
  61. inline ref_value_actor<T,erase_action> erase_a(T& ref_)
  62. {
  63. return ref_value_actor<T,erase_action>(ref_);
  64. }
  65. template<
  66. typename T,
  67. typename KeyT
  68. >
  69. inline ref_const_ref_actor<T,KeyT,erase_action> erase_a(
  70. T& ref_,
  71. KeyT const& key_
  72. )
  73. {
  74. return ref_const_ref_actor<T,KeyT,erase_action>(ref_,key_);
  75. }
  76. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  77. }}
  78. #endif