ref_actor.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_REF_ACTOR_HPP
  8. #define BOOST_SPIRIT_ACTOR_REF_ACTOR_HPP
  9. #include <boost/spirit/home/classic/namespace.hpp>
  10. namespace boost { namespace spirit {
  11. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  12. ///////////////////////////////////////////////////////////////////////////
  13. // Summary:
  14. // A semantic action policy holder. This holder stores a reference to ref,
  15. // act methods are fead with this reference. The parse result is not used
  16. // by this holder.
  17. //
  18. // (This doc uses convention available in actors.hpp)
  19. //
  20. // Constructor:
  21. // ...(T& ref_);
  22. // where ref_ is stored.
  23. //
  24. // Action calls:
  25. // act(ref);
  26. //
  27. // () operators: both
  28. //
  29. ///////////////////////////////////////////////////////////////////////////
  30. template<
  31. typename T,
  32. typename ActionT
  33. >
  34. class ref_actor : public ActionT
  35. {
  36. private:
  37. T& ref;
  38. public:
  39. explicit
  40. ref_actor(T& ref_)
  41. : ref(ref_){}
  42. template<typename T2>
  43. void operator()(T2 const& /*val*/) const
  44. {
  45. this->act(ref); // defined in ActionT
  46. }
  47. template<typename IteratorT>
  48. void operator()(
  49. IteratorT const& /*first*/,
  50. IteratorT const& /*last*/
  51. ) const
  52. {
  53. this->act(ref); // defined in ActionT
  54. }
  55. };
  56. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  57. }}
  58. #endif