ref_value_actor.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*=============================================================================
  2. Copyright (c) 2003 Jonathan de Halleux (dehalleux@pelikhan.com)
  3. Copyright (c) 2011 Bryce Lelbach
  4. http://spirit.sourceforge.net/
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #ifndef BOOST_SPIRIT_ACTOR_REF_VALUE_ACTOR_HPP
  9. #define BOOST_SPIRIT_ACTOR_REF_VALUE_ACTOR_HPP
  10. #include <boost/detail/workaround.hpp>
  11. #include <boost/spirit/home/classic/namespace.hpp>
  12. namespace boost { namespace spirit {
  13. BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
  14. #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
  15. #pragma warning(push)
  16. #pragma warning(disable:4512) //assignment operator could not be generated
  17. #endif
  18. ///////////////////////////////////////////////////////////////////////////
  19. // Summary:
  20. // A semantic action policy holder. This holder stores a reference to ref.
  21. // act methods are feed with ref and the parse result.
  22. //
  23. // (This doc uses convention available in actors.hpp)
  24. //
  25. // Constructor:
  26. // ...(T& ref_);
  27. // where ref_ is stored.
  28. //
  29. // Action calls:
  30. // act(ref, value);
  31. // act(ref, first,last);
  32. //
  33. // () operators: both
  34. //
  35. ///////////////////////////////////////////////////////////////////////////
  36. template<
  37. typename T,
  38. typename ActionT
  39. >
  40. class ref_value_actor : public ActionT
  41. {
  42. private:
  43. T& ref;
  44. public:
  45. explicit
  46. ref_value_actor(T& ref_)
  47. : ref(ref_){}
  48. template<typename T2>
  49. void operator()(T2 const& val_) const
  50. {
  51. this->act(ref,val_); // defined in ActionT
  52. }
  53. template<typename IteratorT>
  54. void operator()(
  55. IteratorT const& first_,
  56. IteratorT const& last_
  57. ) const
  58. {
  59. this->act(ref,first_,last_); // defined in ActionT
  60. }
  61. };
  62. BOOST_SPIRIT_CLASSIC_NAMESPACE_END
  63. #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
  64. #pragma warning(pop)
  65. #endif
  66. }}
  67. #endif