pass_function.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #if !defined(SPIRIT_PASS_FUNCTION_FEBRUARY_05_2007_1138AM)
  7. #define SPIRIT_PASS_FUNCTION_FEBRUARY_05_2007_1138AM
  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. template <typename Iterator, typename Context, typename Skipper>
  16. struct pass_function
  17. {
  18. pass_function(
  19. Iterator& first_, Iterator const& last_
  20. , Context& context_, Skipper const& skipper_)
  21. : first(first_)
  22. , last(last_)
  23. , context(context_)
  24. , skipper(skipper_)
  25. {
  26. }
  27. template <typename Component, typename Attribute>
  28. bool operator()(Component const& component, Attribute& attr)
  29. {
  30. // return true if the parser succeeds
  31. return component.parse(first, last, context, skipper, attr);
  32. }
  33. template <typename Component, typename Attribute>
  34. bool operator()(Component const& component, boost::optional<Attribute>& attr)
  35. {
  36. // return true if the parser succeeds
  37. Attribute val;
  38. if (component.parse(first, last, context, skipper, val))
  39. {
  40. attr = val;
  41. return true;
  42. }
  43. return false;
  44. }
  45. template <typename Component>
  46. bool operator()(Component const& component)
  47. {
  48. // return true if the parser succeeds
  49. return component.parse(first, last, context, skipper, unused);
  50. }
  51. Iterator& first;
  52. Iterator const& last;
  53. Context& context;
  54. Skipper const& skipper;
  55. // silence MSVC warning C4512: assignment operator could not be generated
  56. BOOST_DELETED_FUNCTION(pass_function& operator= (pass_function const&))
  57. };
  58. }}}}
  59. #endif