pass_function.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. =============================================================================*/
  6. #ifndef BOOST_SPIRIT_QI_DETAIL_PASS_FUNCTION_HPP
  7. #define BOOST_SPIRIT_QI_DETAIL_PASS_FUNCTION_HPP
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/support/unused.hpp>
  12. #include <boost/optional.hpp>
  13. namespace boost { namespace spirit { namespace qi { namespace detail
  14. {
  15. #ifdef _MSC_VER
  16. # pragma warning(push)
  17. # pragma warning(disable: 4512) // assignment operator could not be generated.
  18. #endif
  19. template <typename Iterator, typename Context, typename Skipper>
  20. struct pass_function
  21. {
  22. pass_function(
  23. Iterator& first_, Iterator const& last_
  24. , Context& context_, Skipper const& skipper_)
  25. : first(first_)
  26. , last(last_)
  27. , context(context_)
  28. , skipper(skipper_)
  29. {
  30. }
  31. template <typename Component, typename Attribute>
  32. bool operator()(Component const& component, Attribute& attr)
  33. {
  34. // return true if the parser succeeds
  35. return component.parse(first, last, context, skipper, attr);
  36. }
  37. template <typename Component, typename Attribute>
  38. bool operator()(Component const& component, boost::optional<Attribute>& attr)
  39. {
  40. // return true if the parser succeeds
  41. Attribute val;
  42. if (component.parse(first, last, context, skipper, val))
  43. {
  44. attr = val;
  45. return true;
  46. }
  47. return false;
  48. }
  49. template <typename Component>
  50. bool operator()(Component const& component)
  51. {
  52. // return true if the parser succeeds
  53. return component.parse(first, last, context, skipper, unused);
  54. }
  55. Iterator& first;
  56. Iterator const& last;
  57. Context& context;
  58. Skipper const& skipper;
  59. };
  60. #ifdef _MSC_VER
  61. # pragma warning(pop)
  62. #endif
  63. }}}}
  64. #endif